simulate_from_model: Simulate from a model.

Description Usage Arguments Details See Also Examples

View source: R/draws.R


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.


simulate_from_model(object, nsim, index = 1, parallel = NULL)



an object of class ModelRef as returned by link{generate_model}. Or a list of such objects. If object is a Simulation, then function is applied to the referenced models in that simulation and returns the same Simulation object but with references added to the new draws created.


number of simulations to be conducted. If a scalar, then value repeated for each index. Otherwise can be a vector of length 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.


either NULL or a list containing socket_names and (optionally) libraries and save_locally (see Details for more information)


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


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

simulator documentation built on May 19, 2017, 8:28 a.m.

Search within the simulator package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.