Bayesian Network with R - r

I am trying to build a Bayesian network model. However I am unable to install a suitable package. Tried gRain, bnlearn and Rgraphviz for plotting. I have tried in R 2.15 and 3.2
Following are the error messages :
library(gRain)
Loading required package: gRbase
Loading required package: graph
Error: package ‘graph’ could not be loaded
In addition: Warning message:
In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) :
there is no package called ‘graph’
> install.packages("graph")
Warning message:
package ‘graph’ is not available (for R version 2.15.3)
Same for R 3.2.1
> install.packages("graph")
(as ‘lib’ is unspecified)
Warning message:
package ‘graph’ is not available (for R version 3.2.1)
> install.packages("Rgraphviz")
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Warning messages:
1: In open.connection(con, "r") : unable to resolve 'cran.r-project.org'
2: package ‘Rgraphviz’ is not available (for R version 3.2.1)
> install.packages("Rgraphviz")
(as ‘lib’ is unspecified)
Warning message:
package ‘Rgraphviz’ is not available (for R version 2.15.3)
Other info for the model
1) No of variables - 17
2) Type of variables - discrete/continuous

The packagesgraph, RBGL and Rgraphviz are not on CRAN but on bioconductor.
To install these packages, execute
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install(c("graph", "RBGL", "Rgraphviz"))
Then install the packages from CRAN in the usual way:
install.packages("gRain", dependencies=TRUE)
See also the gRain installation instructions.

For R version 3.5 or greater, you can install Bioconductor packages using BiocManager.
Please see: https://bioconductor.org/install.
I installed them using the following code:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install(version = "3.10")
BiocManager::install(c("gRbase", "RBGL", "Rgraphviz", "gRain"))

Related

Using USABoundaries

I'm trying to use the USABoundaries package to draw maps and am having trouble downloading UsaBoundariesData. When I enter something like this
library(USAboundaries)
OH_cong <- us_congressional(states = "OH", resolution = "high")
I get this error message:
The USAboundariesData package needs to be installed.
Install the USAboundariesData package?
1: Yes
2: No
Selection: Yes
Installing the USAboundariesData package.
Installing package into ‘/home/rstudio-user/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
Error in value[[3L]](cond) :
Failed to install the USAboundariesData package.
Please try installing the package for yourself using the following command:
install.packages("USAboundariesData", repos = "http://packages.ropensci.org", type = "source")
> install.packages("USAboundariesData", repos = "http://packages.ropensci.org", type = "source")
Installing package into ‘/home/rstudio-user/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
Error in install.packages : error reading from connection
If anyone has any useful info that would be much appreciated!
Try this instead:
devtools::install_github("ropensci/USAboundariesData")

How should I solve error “there is no package called ‘rspatial’?

I'm trying to install rspatial package using:
if (!require("rspatial")) devtools::install_github('rspatial/rspatial')
but I received below error:
Error: Failed to install 'rspatial' from GitHub:
(converted from warning) installation of package ‘C:/Users/A02243~1/AppData/Local/Temp/Rtmpgx3SZq/file16441e95c6/rspatial_1.0-0.tar.gz’ had non-zero exit status
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘rspatial’
Also, I used:
install.packages("rspatial")
and I received below warning
Warning in install.packages :
package ‘rspatial’ is not available (for R version 3.5.2)
Is there any other ways that will install rspatial on R version 3.5.2?
Thanks.
3.5.2 has some issues with devtools - try updating processx package and see if that resolves the issue.

Installation of factoextra package in R studio

I am trying to install factoextra package in R Studio (v.1.2.1335 on Mac), however, I get error messages for each of the several approaches I tried.
I tried simple installation as well as installing the package source from https://cran.r-project.org/web/packages/factoextra/index.html.
install.packages("factoextra")
install.packages("~/Desktop/factoextra_1.0.5.tar.gz", repos = NULL, type = "source")
package ‘factoextra’ is available as a source package but not as a binary
Warning in install.packages :
package ‘factoextra’ is not available (for R version 3.1.2)
When installing the package source I get an error message:
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
unknown timezone 'zone/tz/2019a.1.0/zoneinfo/America/Toronto'
ERROR: dependency ‘ggpubr’ is not available for package ‘factoextra’
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/factoextra’
Warning in install.packages :
installation of package ‘/Users/lihieder/Desktop/factoextra_1.0.5.tar.gz’ had non-zero exit status
I also tried installing package ggpubr but run into similar issues even when trying to install the source package for ggpubr.
Any ideas?
only use
install.packages("factoextra")

Error in library("Hmisc"): there is no package called 'Hmisc'

I just installed R using anaconda, and I am following this tutorial:
https://www.analyticsvidhya.com/blog/2016/03/tutorial-powerful-packages-imputing-missing-values/
I learned that I need to install some package by using:
if(!require(Hmisc)) install.packages("Hmisc",repos = "http://cran.us.r-project.org")
There are some warning message i am not sure whether it means successful or not:
Loading required package: Hmisc
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called 'Hmisc'also installing the dependencies 'survival', 'ggplot2'
Warning message:
In install.packages("Hmisc", repos = "http://cran.us.r-project.org"): installation of package 'survival' had non-zero exit status
Warning message:
In install.packages("Hmisc", repos = "http://cran.us.r-project.org"): installation of package 'ggplot2' had non-zero exit status
Warning message:
In install.packages("Hmisc", repos = "http://cran.us.r-project.org"): installation of package 'Hmisc' had non-zero exit status
The downloaded source packages are in
'/tmp/Rtmpcf6rZ9/downloaded_packages'
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Then I tried to load the library with
library(Hmisc)
But I got the error,
Error in library(Hmisc): there is no package called 'Hmisc'
Does anyone know what might has happened? Thanks.
Edit:
I am suggested to try a few more ways, but they all have various error:
install.packages("Hmisc")
Error in contrib.url(repos, type): trying to use CRAN without setting a mirror
If I do:
install.packages("Hmisc",repos = "http://cran.us.r-project.org")
I got:
also installing the dependencies 'survival', 'ggplot2'
Warning message:
In install.packages("Hmisc", repos = "http://cran.us.r-project.org"): installation of package 'survival' had non-zero exit status
Warning message:
In install.packages("Hmisc", repos = "http://cran.us.r-project.org"): installation of package 'ggplot2' had non-zero exit status
Warning message:
In install.packages("Hmisc", repos = "http://cran.us.r-project.org"): installation of package 'Hmisc' had non-zero exit status
The downloaded source packages are in
'/tmp/Rtmpcf6rZ9/downloaded_packages'
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
I am suggested not to use Anaconda R, but because I mostly use rpy2 and jupiter notebook the most. I think using the Anaconda R may be the most straight forward method to get my jupiter notebook and python to work seamlessly with R.
I had a similar issue, solved it by installing "acepack" directly install.packages('acepack')
This is mysterious, regardless. I do an update of all packages in Conda. Then, I install Rstudio using anaconda. Then the error does not exist anymore...

MXNet package installation in R

I get plenty of trouble when trying to install MXNet package in R
I am using the 3.4.0 version of R and I am on windows 10 CPU intel i3, 64bits x64-based processor.
I get prompted:
install.packages("mxnet")
Warning in install.packages :
cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/src/contrib/PACKAGES.rds': HTTP status was '404 Not Found'
Installing package into ‘C:/Users/los40/OneDrive/Documentos/R/win-library/3.4’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘mxnet’ is not available (for R version 3.4.0)
Warning in install.packages :
cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.4/PACKAGES.rds': HTTP status was '404 Not Found'
I've tried downloading the .rar files provided here. I decompress one and get the folder where it says "R package" attempting to install it by using:
> install.packages('R.package.rar', lib='D:/mxnet',repos = NULL)
Error in install.packages : type == "both" cannot be used with 'repos = NULL'
> install.packages('R.package.rar', lib='D:/mxnet')
Warning in install.packages :
package ‘R.package.rar’ is not available (for R version 3.4.0)
The guide found in http://mxnet.io/get_started/windows_setup.html makes no sense to me since I cannot find the file required in the steps for installing the prebuild package on windows called setupenv.cmd
For mxnet package install in R using this command for only CPU
cran <- getOption("repos")
cran["dmlc"] <- "https://s3-us-west-2.amazonaws.com/apache-mxnet/R/CRAN/"
options(repos = cran)
install.packages("mxnet",dependencies = T)
library(mxnet)
Please try the following line:
cran <- getOption("repos")
cran["dmlc"] <- "https://s3.amazonaws.com/mxnet-r/"
options(repos = cran)
install.packages("mxnet")
For windows, if you want to install mxnet. Use the below commmand:
cran <- getOption("repos")
cran["dmlc"] <- "https://s3-us-west-2.amazonaws.com/apache-mxnet/R/CRAN/"
options(repos = cran)
install.packages("mxnet",dependencies = T)
library(mxnet)

Resources