Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

simulate-abn

Simulate from an ABN Network


Description

Simulate one or more responses from an ABN network corresponding to a fitted object using a 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,
                       keep.file=FALSE,
                       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.

keep.file

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

seed

by default set to 42.

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 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.

Value

A data frame containing simulated data.

Author(s)

Gilles Kratzer

References

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

Examples

## 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,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)

## 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

Modelling Multivariate Data with Additive Bayesian Networks

v2.5-0
GPL (>= 2)
Authors
Gilles Kratzer [aut, cre] (<https://orcid.org/0000-0002-5929-8935>), Fraser Iain Lewis [aut] (<https://orcid.org/0000-0003-4580-2712>), Reinhard Furrer [ctb] (<https://orcid.org/0000-0002-6319-2332>), Marta Pittavino [ctb] (<https://orcid.org/0000-0002-1232-1034>)
Initial release
2021-04-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.