Skip to contents

Simulate data from a fitted additive Bayesian network.

Usage

simulateAbn(
  object = NULL,
  run.simulation = TRUE,
  bugsfile = NULL,
  n.chains = 10L,
  n.adapt = 1000L,
  n.thin = 100L,
  n.iter = 10000L,
  seed = 42L,
  verbose = FALSE,
  debug = FALSE
)

Arguments

object

of type abnFit.

run.simulation

call JAGS to simulate data (default is TRUE).

bugsfile

A path to a valid file or NULL (default) to delete the bugs file after simulation.

n.chains

number of parallel chains for the model.

n.adapt

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

n.thin

thinning interval for monitors.

n.iter

number of iteration to monitor.

seed

by default set to 42.

verbose

if TRUE prints additional output

debug

if TRUE prints bug file content to stdout and does not run simulations.

Value

data.frame

See also

Examples

df <- FCV[, c(12:15)]
mydists <- list(Outdoor="binomial",
                Sex="multinomial",
                GroupSize="poisson",
                Age="gaussian")

## buildScoreCache -> mostProbable() -> fitAbn()
suppressWarnings({
  mycache.mle <- buildScoreCache(data.df = df, data.dists = mydists, method = "mle",
                                 adj.vars = NULL, cor.vars = NULL,
                                 dag.banned = NULL, dag.retained = NULL,
                                 max.parents = 1,
                                 which.nodes = NULL, defn.res = NULL)
}) # ignore non-convergence warnings
mp.dag.mle <- mostProbable(score.cache = mycache.mle, verbose = FALSE)
myres.mle <- fitAbn(object = mp.dag.mle, method = "mle")

myres.sim <- simulateAbn(object = myres.mle,
                             run.simulation = TRUE,
                             bugsfile = NULL,
                             verbose = FALSE)
str(myres.sim)
#> 'data.frame':	1000 obs. of  4 variables:
#>  $ Age      : num  -0.796 -0.6201 0.0929 -0.1999 -0.9388 ...
#>  $ GroupSize: num  4 4 2 5 3 3 3 2 3 4 ...
#>  $ Outdoor  : Factor w/ 2 levels "0","1": 1 1 1 1 1 2 1 1 2 2 ...
#>  $ Sex      : Factor w/ 4 levels "1","2","3","4": 3 1 4 1 3 1 4 2 3 1 ...
prop.table(table(myres.sim$Outdoor))
#> 
#>   0   1 
#> 0.4 0.6 
prop.table(table(df$Outdoor))
#> 
#>         0         1 
#> 0.4233333 0.5766667