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)
1) No of variables - 17 2) Type of variables - discrete/continuous
Additive Bayesian Network Modelling in R. Bayesian network analysis is a form of probabilistic graphical models which derives from empirical data a directed acyclic graph (DAG)
A Bayesian Network (BN) is a probabilistic model based on directed a cyclic graphs that describe a set of variables and their conditional dependencies to each other. It is a graphical model, and we can easily check the conditional dependencies of the variables and their directions in a graph.
While Bayesian network modelling is computationally intensive, comparing across potentially large numbers of different models, it should not be treated as a black box approach as each individual data set has its own quirks and difficulties.
Bayes Nets can get complex quite quickly (for example check out a few from the bnlearn doco, however the graphical representation makes it easy to visualise the relationships and the package makes it easy to query the graph. Fitting the network and querying the model is only the first part of the practice.
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"))
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With