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
.
Arguments
- object
an object of class
ModelRef
as returned bylink{generate_model}
. Or a list of such objects. Ifobject
is aSimulation
, then function is applied to the referenced models in that simulation and returns the sameSimulation
object but with references added to the new draws created.- nsim
number of simulations to be conducted. If a scalar, then value repeated for each index. Otherwise can be a vector of length
length(index)
- 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
NULL
or a list containingsocket_names
and (optionally)libraries
andsave_locally
(see Details for more information)
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.
Examples
if (FALSE) {
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))
}