Learn R Programming

abn (version 1.3)

simulateabn: Simulate from an ABN network

Description

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

Usage

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,
                       bug.file=NULL,
                       verbose=TRUE,
                       simulate=TRUE,
                       seed=42)

Arguments

data.dists

named list giving the distribution for each node in the network, see details.

data.param

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.

data.param.var

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.

data.param.mult

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

n.chains

number of parallel chains for the model.

n.thin

number of parallel chains for the model.

n.iter

number of iteration to monitor.

n.adapt

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

bug.file

path/name of the user specific bug file.

verbose

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

simulate

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

seed

by default set to 42.

Value

A data frame containing simulated data

Details

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" distributions use log and "binomial" and "multinomial" distributions 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.

References

Further information about abn can be found at: http://www.r-bayesian-networks.org

Examples

Run this code
# NOT RUN {
#define set of distribution
dist<-list(a="gaussian",
b="gaussian",
c="gaussian",
d="gaussian", 
e="binomial", 
f="binomial")

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

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

#plot the dag
plotabn(dag.m = ~a|b:c:e+b|c:d:f+e|f,data.dists = dist ,plot = FALSE)

#simulate the data
simulateabn(data.dists = dist,
n.chains = 1,
n.thin = 1,
n.iter = 1000,
data.param = data.param,
data.param.var = data.param.var,
seed = 132)
# }

Run the code above in your browser using DataLab