Bayesian Network with R
Asked Answered
D

2

11

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

Dink answered 6/7, 2015 at 17:31 Comment(0)
R
27

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.

Roundlet answered 6/7, 2015 at 19:20 Comment(1)
You may need to use the force=T argument to BiocManager::install if some of the packages have the same or higher versions, otherwise they won't be installed.Reducer
I
4

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"))
Indehiscent answered 25/3, 2020 at 7:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.