A Function to Simulate a Model from a Generic Simulation Function, with Pre and Post Processing

simulate_model(
  model,
  sim_fn,
  inits = NULL,
  params = NULL,
  times = NULL,
  as_tibble = TRUE,
  by_row = FALSE,
  aggregate_to = NULL,
  compartments = NULL,
  strat = NULL,
  hold_out_var = NULL,
  new_var = "incidence",
  total_pop = TRUE,
  summary_var = FALSE,
  verbose = FALSE,
  ...
)

Arguments

model

A model compatible with your sim_fn.

sim_fn

A generic simulation function, with the first argument as the model object, a params argument, and a as.data.frame argument.

inits

A dataframe of initial conditions, optionally a named vector can be used.

params

A dataframe of parameters, with each parameter as a variable. Optionally a named vector can be used.

times

A vector of the times to sample the model for, from a starting time to a final time.

as_tibble

Logical (defaults to TRUE) indicating if the output should be returned as a tibble, otherwise returned as the default sim_fn output.

by_row

Logical (defaults to FALSE) indicating if inputed parameters should be inputed as a block to sim_fn or individually. If TRUE then function will always return a tibble. Does not currently work with sim_fn that produces multiple simulations for a single parameter set - for this scenario a block based approach or post processing is required.

aggregate_to

A character vector or list specifying the aggregation operations to perform on the model output. Operations are carried out in the order specified. Implemented options are; disease, demographic, and incidence.

compartments

A character vector or list specifying the unique compartments to aggregate. May either be specified once for all aggregation functions or for each function separately.

strat

The number of stratified groups in the model.

hold_out_var

A character vector or list specifying the unique compartments that will not be aggregated. May either be specified once for all aggregation functions or for each function separately. If compartments is set then this argument does not need to be used.

new_var

A character vector specifying the new variable to add when aggregating incidence.

total_pop

A logical (defaults to TRUE) indicating if the total population should be calculated when summarising the model demographics.

summary_var

A logical (defaults to FALSE), specifying whether to add an additional summary variable across all stratified levels.

verbose

Logical (defaults to FALSE) indicating if progress information should be printed to the console.

...

Additional arguments to pass to sim_fn

Value

Trajectories as a tibble, optionally returns the default sim_fn output.

See also

aggregate_model

Examples

## Intialise N = 100000 I_0 = 1 S_0 = N - I_0 R_0 = 1.1 beta = R_0 ##Time for model to run over tbegin = 0 tend = 50 times <- seq(tbegin, tend, 1) ##Vectorise input parameters <- data.frame(beta = beta) inits <- data.frame(S = S_0, I = I_0) SI_sim <- simulate_model(model = SI_ode, sim_fn = solve_ode, inits, parameters, times)