smc_simulate: Simulate data from various models.

Description Usage Arguments Details See Also Examples

View source: R/simcases-simulate.R

Description

Simulate data from various models. Results are saved to disk.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
smc_simulate(
  models = models,
  code = "",
  constants = nlist::nlist(),
  parameters = nlist::nlist(),
  monitor = ".*",
  stochastic = NA,
  latent = NA,
  nsims = 1,
  path = ".",
  exists = FALSE,
  rdists = sims_rdists(),
  ask = getOption("sims.ask", TRUE),
  silent = FALSE,
  environment = parent.frame(),
  fun = function(x) read.table(text = gsub(";|,| |:|\t|\\||&|~", "\t",
    readLines(textConnection(x))), header = TRUE),
  ...
)

Arguments

models

A data frame or an object that becomes a data frame when fun is applied. The data frame contains character strings that refer to objects defined within environment. Each row defines a model. The header may contain: code, constants, parameters, monitor, stochastic, latent and/or nsims

code

A string of the JAGS or R code to generate the data. The JAGS code must not be in a data or model block.

constants

An nlist object (or list that can be coerced to nlist) specifying the values of nodes in code. The values are included in the output dataset.

parameters

An nlist object (or list that can be coerced to nlist) specifying the values of nodes in code. The values are not included in the output dataset.

monitor

A character vector (or regular expression if a string) specifying the names of the nodes in code to include in the dataset. By default all nodes are included.

stochastic

A logical scalar specifying whether to monitor deterministic and stochastic (NA), only deterministic (FALSE) or only stochastic nodes (TRUE).

latent

A logical scalar specifying whether to monitor observed and latent (NA), only latent (TRUE) or only observed nodes (FALSE).

nsims

A whole number between 1 and 1,000,000 specifying the number of data sets to simulate. By default 100 data sets are simulated.

path

A string specifying the path to the directory to save the data sets in.

exists

A flag specifying whether the 'path' directory should already exist (if ‘exists = NA' it doesn’t matter).

rdists

A character vector specifying the R functions to recognize as stochastic. The seed should be specified using [base::set.seed()].

ask

A flag specifying whether to ask before deleting sims compatible files.

silent

A flag specifying whether to suppress warnings.

environment

The environment in which the objects described in cases were defined.

fun

A function to convert cases to a data frame.

...

Unused.

Details

The arguments code, constants, parameters, monitor, stochastic, latent and nsims will only be used if not specified within models.

See Also

[sims::simulate()]

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
normal <- "a ~ dnorm(0, 1/sigma^2)"
sigma1 <- list(sigma=1)
sigma2 <- list(sigma=2)
smc_simulate("code parameters,
                   normal sigma1
                   normal sigma2",
                   path = tempdir(), 
                   exists = NA, 
                   ask = FALSE)
smc_simulate(tibble::tribble(
                   ~code, ~parameters,
                   "normal", "sigma1",
                   "normal", "sigma2"),
                   fun = identity,
                   path = tempdir(), 
                   exists = NA, 
                   ask = FALSE)

audrey-b/simcases documentation built on July 22, 2020, 6:20 p.m.