Packages for graphical modelling with R

This page describes some of the R packages for graphical modelling that I have been involved with. There are many more packages for grapical modelling, and the CRAN Task View gRaphical Models in R lists many of these.

1  Packages


2  Books

3  Installation

  1. The packages listed above use the graph, RBGL and Rgraphviz packages. These packages are NOT on CRAN but on bioconductor. Hence you MUST install these packages BEFORE installing the graphical modelling packages. To do so, execute these commands:
    source(""); biocLite(c("graph","RBGL","Rgraphviz"))
  2. Then install the graphical modelling packages from CRAN with:
    install.packages("gRbase", dependencies=TRUE); install.packages("gRain", dependencies=TRUE); install.packages("gRim", dependencies=TRUE)

4  Development versions of the packages

Development versions of the packages reside on github. If you decide to use these versions, PLEASE install the CRAN versions FIRST (to get dependencies right) and then AFTERWARDS install the development versions using:
Notice that for this to succeed you will need tools for building R packages from sources on your computer. For windows users this translates to that you will have to install Rtools which can be obtained from Just follow the suggestions of the installer.
Notice that the packages are interdependent: For example, gRain depends on gRbase. Therefore, to use the development version of e.g. gRain you must also install the development version of gRbase.

5  Examples

6  Scripts and notes

7  Tutorial and short courses

8  Reporting unexpected behaviours (bugs)

When reporting unexpected behaviours, bugs etc. in the packages, PLEASE supply:
  1. A reproducible example in terms of a short code fragment.
  2. The data. The preferred way of sending the data "mydata" is to copy and paste the result from running dput(mydata).
  3. The result of running the sessionInfo() function.

9  FAQ (frequently asked questions)

Is it possible to specify likelihood evidence (also called virtual evidence) in gRain?
Yes, as of version 1.1-2 this has been implemented. The function to use is setEvidence(). A vignette on the topic has also been added. Please report unexpected behaviour.
I want to build a Bayesian network with 80.000 nodes. Can I do so with gRain?
Work has been done on supporting large networks. Please report sucesses and failures.
Does gRain have support for Bayesian networks for variables that are (multivariate) normal? Or for mixtures of discrete and normal variables?
No. Implementation for the multivariate normal distribution is straight forward (if you work with the canoncical rather than the moment parameters). Any contribution would be most welcome. For mixed variables, the only algorithm I know of is numerically unstable.
Does gRain have support for Bayesian networks for variables that are not discrete (and with a finite state space)?
Not in full generality. However, using the likelihood evidence facilities, one can work with some types of non-discrete variables.
Søren Højsgaard sorenh [at] math [dot] aau [dot] dk

File translated from TEX by TTH, version 4.08.