Return simulations of the trajectory of the output
variables of a dynamical model simulator. To see this functionality
in context, please see vignette("quickstart")
.
Arguments
- model
A dynamical model simulator produced by
mp_simulator
.- include_initial
Should the initial values of the simulation be included in the output? If
TRUE
this will include outputs fortime == 0
associated with the initial values. Seemp_initial
for another approach to getting the initial values.- conf.int
Should confidence intervals be produced?
- conf.level
If
conf.int
isTRUE
, what confidence level should be used? For example, the default of0.95
corresponds to 95% confidence intervals.- n
Number of random trajectories to simulate.
- probs
Numeric vector of probabilities corresponding to quantiles for summarizing the results over the random realizations.
Value
A data frame with one row for each simulated value and the following columns.
- matrix
Name of the variable in the model. All variables are matrix-valued in
macpan2
(scalars are technically 1-by-1 matrices), which explains the name of this field. In hindsight I would have called itvariable
.- time
Time index of the simulated value, with
time = 0
indicating initial values.- row
The 0-based index of the row of the matrix, or the name of the row of the matrix if row names (or names for column vectors) are supplied for the default value of the matrix.
- col
The 0-based index of the column of the matrix, or the name of the column of the matrix if column names are supplied for the default value of the matrix. It is also possible that this column is blank if everything is either a scalar or column vector (a common case).
- value
(
mp_trajectory
andmp_trajectory_sd
) Simulation values.- sd
(for
mp_trajectory_sd
only) The standard deviations of the simulated values accounting for parameter estimation uncertainty.- conf.low
(for
mp_trajectory_sd
only) The lower bounds of the confidence interval for the simulated values.- conf.high
(for
mp_trajectory_sd
only) The upper bounds of the confidence interval for the simulated values.- n%
(for
mp_trajectory_[ensemble|sim]
) The n-th quantiles of the simulation values over repeated simulations.
Functions
mp_trajectory_sd()
: Simulate a trajectory that includes uncertainty information provided by thesdreport
function inTMB
with default settings.mp_trajectory_ensemble()
: Simulate a trajectory that includes uncertainty information provided by repeatedly sampling from a normal approximation to the distribution of the fitted parameters, and generating one trajectory for each of these samples. The quantiles of the empirical distribution of these trajectories can be used to produce a confidence interval for the fitted trajectory.mp_trajectory_sim()
: Generate quantiles overn
realizations of the trajectory. Instead of avalue
column in the output data frame, there is one column for each of the quantiles defined inprobs
.mp_trajectory_replicate()
: Generate a list ofn
simulation results.
Examples
spec = mp_tmb_library("starter_models"
, "si"
, package = "macpan2"
)
simulator = mp_simulator(spec
, time_steps = 10L
, outputs = c("infection", "I")
)
trajectory = mp_trajectory(simulator)
print(trajectory)
#> matrix time row col value
#> 1 I 1 0 0 1.1980000
#> 2 infection 1 0 0 0.1980000
#> 3 I 2 0 0 1.4347296
#> 4 infection 2 0 0 0.2367296
#> 5 I 3 0 0 1.7175586
#> 6 infection 3 0 0 0.2828290
#> 7 I 4 0 0 2.0551703
#> 8 infection 4 0 0 0.3376117
#> 9 I 5 0 0 2.4577569
#> 10 infection 5 0 0 0.4025866
#> 11 I 6 0 0 2.9372272
#> 12 infection 6 0 0 0.4794702
#> 13 I 7 0 0 3.5074180
#> 14 infection 7 0 0 0.5701908
#> 15 I 8 0 0 4.1842977
#> 16 infection 8 0 0 0.6768796
#> 17 I 9 0 0 4.9861405
#> 18 infection 9 0 0 0.8018428
#> 19 I 10 0 0 5.9336454
#> 20 infection 10 0 0 0.9475049