R/simulate_model.R
simulate_model.Rd
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, ... )
model | A model compatible with your |
---|---|
sim_fn | A generic simulation function, with the first argument as the model object,
a |
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 |
by_row | Logical (defaults to |
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 |
summary_var | A logical (defaults to |
verbose | Logical (defaults to |
... | Additional arguments to pass to |
Trajectories as a tibble, optionally returns the default sim_fn
output.
aggregate_model
## 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)