| run_multiple {epiworldR} | R Documentation |
Run multiple simulations at once
Description
The run_multiple function allows running multiple simulations at once.
When available, users can take advantage of parallel computing to speed up
the process.
Usage
run_multiple(
m,
ndays,
nsims,
seed = sample.int(10000, 1),
saver = make_saver(),
reset = TRUE,
verbose = TRUE,
nthreads = 1L
)
run_multiple_get_results(m)
make_saver(..., fn = "")
Arguments
m, ndays, seed |
See run. |
nsims |
Integer. Number of replicats |
saver |
An object of class epiworld_saver. |
reset |
When |
verbose |
When |
nthreads |
Integer. Number of threads (parallel computing.) |
... |
List of strings (characters) specifying what to save (see details). |
fn |
A file name pattern. |
Details
Currently, the following elements can be saved:
-
total_histHistory of the model (total numbers per time). -
virus_infoInformation aboutviruses. -
virus_histChanges inviruses. -
tool_infoInformation abouttools. -
tool_histChanges intools. -
transmissionTransmission events. -
transitionTransition matrices. -
reproductiveReproductive number. -
generationEstimation of generation time.
Value
In the case of
make_saver, an list of classepiworld_saver.
The
run_multiplefunction runs a specified number of simulations and returns a model object of class epiworld_model.
The
run_multiple_get_resultsfunction returns a named list with the data specified bymake_saver.
Examples
model_sir <- ModelSIRCONN(
name = "COVID-19",
prevalence = 0.01,
n = 1000,
contact_rate = 2,
transmission_rate = 0.9, recovery_rate = 0.1
)
# Generating a saver
saver <- make_saver("total_hist", "reproductive")
# Running and printing
run_multiple(model_sir, ndays = 100, nsims = 50, saver = saver, nthreads = 2)
# Retrieving the results
ans <- run_multiple_get_results(model_sir)
head(ans$total_hist)
head(ans$reproductive)
# Plotting
multi_sir <- run_multiple_get_results(model_sir)$total_hist
multi_sir <- multi_sir[multi_sir$date <= 20,]
plot(multi_sir)