| simulate_from_model {simulator} | R Documentation |
Simulate from a model.
Description
Given a reference to a Model object, this function calls the
model's simulate function on its params. It repeats this
nsim times. For example, when simulating regression with a fixed
design, this function would generate nsim response vectors y.
Usage
simulate_from_model(object, nsim, index = 1, parallel = NULL)
Arguments
object |
an object of class |
nsim |
number of simulations to be conducted. If a scalar, then
value repeated for each index. Otherwise can be a vector of length
|
index |
a vector of positive integer indices. Allows simulations to be carried out in chunks. Each chunk gets a separate RNG stream, meaning that the results will be identical whether we run these in parallel or sequentially. |
parallel |
either |
Details
This function creates objects of class Draws and saves each to
file (at dir/files/model_name/r<index>.Rdata). Note: while "files" is the
default, the name of this directory is from getOption("simulator.files"),
which is the value of getOption("simulator.files") when the model was
created.
If parallel is not NULL, then it must be a list containing
socket_names, which can either be a positive integer specifying the
number of copies to run on localhost or else a character vector of machine
names (e.g., "mycluster-0-0"). The list parallel can also contain
libraries, a character vector of R packages that will be needed on the
slaves and save_locally, a logical that indicates whether the files
generated should be saved on the slaves (i.e., locally) or on the master.
See Also
load_draws generate_model run_method
Examples
## Not run:
sim <- new_simulation(name = "normal-example",
label = "Normal Mean Estimation",
dir = tempdir()) %>%
generate_model(make_my_example_model, n = 20) %>%
simulate_from_model(nsim = 50, index = 1:3,
parallel = list(socket_names = 3))
## End(Not run)