| simulate.micsim_model | R Documentation |
Runs the simulation a micsim_model() describes and returns the result
together with the model, the seed and what happened during the run.
## S3 method for class 'micsim_model'
simulate(
object,
nsim = 1,
seed = NULL,
cores = 1L,
verbose = FALSE,
reestimate = TRUE,
...
)
object |
A |
nsim |
Number of simulations. Only |
seed |
Integer seed, or |
cores |
Number of processor cores. Splitting the population across cores is exact rather than approximate, because individuals in MicSim's model are independent of one another. The result does not depend on the number of cores. No more workers are started than there are individuals in the starting population. |
verbose |
Report progress through |
reestimate |
Estimate the transition rates from the simulated
population after the run and compare them with the supplied ones
( |
... |
Not used. |
This is a method for stats::simulate(), so it has that generic's
argument names. With the default seed = NULL, a seed is drawn from R's
current random number state (one draw), so set.seed(234) before the
call makes a run reproducible. The drawn seed is stored in the result.
Apart from that draw, the caller's random number state is left exactly
as it was, including the generator kind. Every individual in the simulation
draws from their own random-number stream, derived from the seed and
their ID (a newborn's from its mother's). A life course therefore does not
depend on who else is in the population, on the order of the population's rows
or of the transitions, or on the number of cores. Two scenarios simulated with
the same seed share their random numbers (common random numbers), i.e.
an individual whose rates are the same in both lives the same life in both.
A model can be simulated repeatedly. Nothing is shared between runs:
every subsystem's state is created fresh at the start of each run. If
the model was built by a different MicSim version, a micsim_version_warning
is given.
After the run, every transition rate is estimated from the simulated
population and compared with the supplied one (reestimate()).
Using plot() on the result shows the comparison.
Pass reestimate = FALSE to skip it.
An object of class micsim_result, a list with
popthe simulated population:
one row per transition, one row with NA transition
columns for an individual who never moved. as.data.frame()
returns it.
modelthe micsim_model that was simulated, so the result
is self-describing and as_long() needs no arguments.
seedthe seed the run used; when none was supplied, the one drawn from R's random number state.
diagnosticsn_events, n_individuals, n_starting,
n_immigrants and n_newborns; n_forced (transitions forced
by an Inf rate), n_unreliable (waiting times drawn from a
degraded numerical integration); peak_queue (largest number
of pending events; for a multi-core run the largest of any core),
cores (worker processes used) and seconds (wall time of
the simulation).
extensionsa named list with what each subsystem reports,
e.g. result$extensions$fertility$births; see fertility() and
school_enrolment().
reestimationa micsim_reestimation (reestimate()), or
NULL with reestimate = FALSE.
metaprovenance: micsim_version, r_version, platform,
rng_kind (always "L'Ecuyer-CMRG"), seed_drawn
(TRUE if the seed was drawn from R's random number state),
created (time the run finished) and reestimation_seconds.
micsim_model(), as_long(), as_wide(), MicSim-concepts
mortality <- function(age, calTime) 0.00003 * exp(0.1 * age)
model <- micsim_model(
state_space = state_space(sex = c("m", "f")),
transitions = transitions(transition(NA, "dead", mortality)),
population = data.frame(ID = 1:10, birthDate = rep("19500101", 10),
initState = rep("f", 10),
stringsAsFactors = FALSE),
horizon = c(20000101, 20401231), max_age = 120
)
result <- simulate(model, seed = 234)
result
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.