simulate-abn: Simulate from an ABN Network

simulateAbnR Documentation

Simulate from an ABN Network


Simulate one or more responses from an ABN network corresponding to a fitted object using a formula statement or an adjacency matrix.


simulateAbn(data.dists = NULL,
                       data.param = NULL,
                       data.param.var = NULL,
                       data.param.mult = NULL,
                       n.chains =10,
                       n.adapt = 1000,
                       n.thin = 100,
                       n.iter = 10000,



named list giving the distribution for each node in the network, see ‘Details’.


named matrix, which have to be square with as many entries as the number of variables, each element is the coefficient (for specifications see ‘Details’) used in the glm to simulate responses.


optional matrix, which should be square and having as many entries as number of variables, which contains the precision values for gaussian nodes. Default is set to 1.


optional matrix, which should be square and having as many entries as number of variables, which contains the multinomial coefficient.


number of parallel chains for the model.


number of parallel chains for the model.


number of iteration to monitor.


number of iteration for adaptation. If n.adapt is set to zero, then no adaptation takes place.


name of the user specific bug file. If missing "model.bug" will be used. See ‘Details’.


logical. Default TRUE. Should R report extra information on progress?


logical. Default TRUE. If set to FALSE, no simulation will be run only creation of the bug file.


logical. Default FALSE. If set to TRUE, the bug file generated will be kept afterwards.


by default set to 42.


This function use rjags to simulate data from a DAG. It first creates a bug file, in the actual repository, then use it to simulate the data. This function output a data frame. The bug file can be run using rjags separately.

The coefficients given in the data.param are: the logit of the probabilities for binomial nodes, the means of the gaussian nodes, and the log of the Poison parameter. Additionally, a matrix data.param.var could give precision values for gaussian nodes (default is set to 1).

Binary and multinomial variables must be declared as factors, and the argument data.dists must be a list with named arguments, one for each of the variables in data.df (except a grouping variable - if present), where each entry is either "poisson", "binomial", "multinomial" or "gaussian", see examples below. The Poisson distributed variables use log and Binomial and multinomial distributed ones the logit link functions. Note that "binomial" here actually means only binary, one Bernoulli trial per row in data.df.

The number of simulated data (rows of the outputted data frame) is given by n.iter divided by n.thin.

The bug file contains a description of the model in the JAGS dialect of the BUGS language. It is possible to only generate this file and to reuse this for later or other purposes. If a bug file name is specified and the file exists, it will be used. If the file does not exist or bug.file is missing, the bug file is created. Default name is "model.bug".

The verbose argument is passed appropriately to the JAGS functions.


A data frame containing simulated data.


Gilles Kratzer


Further information about abn can be found at:


## Define set of distributions:
dist<-list(a="gaussian", b="gaussian", c="gaussian", d="gaussian",
           e="binomial", f="binomial")

## Define parameter matrix:
data.param <- matrix(c(1,2,0.5,0,20,0,
                       0,1,3,10,0, 0.8,
                       0,0,0,0,0,0), nrow = 6L, ncol = 6L, byrow = TRUE)

## Define precision matrix:
data.param.var <- matrix(0, nrow = 6L, ncol = 6L)
diag(data.param.var) <- c(10,20,30,40,0,0)

## Plot the dag
plotAbn(dag = ~a|b:c:e+b|c:d:f+e|f, data.dists = dist)

## Simulate the data
out <- simulateAbn(data.dists=dist, n.chains=1, n.thin=1, n.iter=1000,
            data.param=data.param, data.param.var=data.param.var)

abn documentation built on April 25, 2022, 9:06 a.m.