simulateAbn | R Documentation |

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

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

`bug.file` |
name of the user specific bug file. If missing |

`verbose` |
logical. Default |

`simulate` |
logical. Default |

`keep.file` |
logical. Default |

`seed` |
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:

http://r-bayesian-networks.org

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

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.