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.

## Packages

### gRim

• Graphical interaction models (graphical log-linear models for discrete data, Gaussian graphical models for continuous data and Mixed interaction models for mixed data).
• See Højsgaard, Edwards, Lauritzen (2012) Graphical Modelling with R. Springers UseR! series.

### gRbase

• Efficient graph algorithms, functions for easy creation of graphs, functions for manipulation of highdimensional tables, data relevant to graphical models.
• Many graph modelling packages depend on gRbase, but gRbase itself provides only limited modelling facilities.
• The reference to gRbase is: Dethlefsen, C., Højsgaard, S. (2005) A Common Platform for Graphical Models in R: The gRbase Package. Journal of Statistical Software Vol. 14, No. 17.

## Installation

1. The packages listed above use the graph, RBGL and Rgraphviz packages. These packages are on bioconductor. To enable that these are installed when installing the packates above run

setRepositories()

and make sure that BioC software is checked.

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)

## Development versions

Development versions of the packages reside on github. To use these versions, PLEASE install the CRAN versions FIRST (see section on installation) to get dependencies right and then AFTERWARDS install the development versions using:

devtools::install_github("hojsgaard/gRbase")
• 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 https://cran.r-project.org/bin/windows/Rtools/. 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 (most likely) also install the development version of gRbase.

## Books

• Højsgaard, Edwards, Lauritzen (2012) Graphical Modelling with R. Springers UseR! series. The book contains several illustrations of the use of the gRbase, gRain and gRim packages.

• Errata list for Graphical Modelling with R.

## Examples, scripts and notes

• Q: Is it possible to specify likelihood evidence (also called virtual evidence) in gRain?

• A: 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.

• Q: I want to build a Bayesian network with 80.000 nodes. Can I do so with gRain?

• A: Work has been done on supporting large networks. Please report sucesses and failures.

• Q: Does gRain have support for Bayesian networks for variables that are (multivariate) normal? Or for mixtures of discrete and normal variables?

• A: No. Implementation for the multivariate normal distribution is - at least in principle - straight forward although there can non-trivial numerical issues.

• Q: Does gRain have support for Bayesian networks for variables that are not discrete (and with a finite state space)?

• A: Not in full generality. However, using the likelihood evidence facilities, one can work with some types of non-discrete variables.

## Reporting bugs etc.

When reporting unexpected behaviours, bugs etc. PLEASE supply:

• A small reproducible example in terms of a short code fragment.

• The data. The preferred way of sending the data “mydata” is to copy and paste the result from running dput(mydata).

• The result of running the sessionInfo() function.