Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bayesian Network with 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

like image 392
Learner Avatar asked Jul 06 '15 17:07

Learner


People also ask

What is additive Bayesian network modelling in R?

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)

What is a Bayesian network?

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.

Is Bayesian network modelling a black box approach?

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.

How easy is Bayes net to use?

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.


2 Answers

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"))
like image 182
Binh T Nguyen Avatar answered Oct 26 '22 11:10

Binh T Nguyen


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.

like image 36
rcs Avatar answered Oct 26 '22 13:10

rcs