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. A generic simulation function, with the first argument as the model object, a params argument, and a as.data.frame argument. A dataframe of initial conditions, optionally a named vector can be used. A dataframe of parameters, with each parameter as a variable. Optionally a named vector can be used. A vector of the times to sample the model for, from a starting time to a final time. Logical (defaults to TRUE) indicating if the output should be returned as a tibble, otherwise returned as the default sim_fn output. 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. 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. 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. The number of stratified groups in the model. 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. A character vector specifying the new variable to add when aggregating incidence. A logical (defaults to TRUE) indicating if the total population should be calculated when summarising the model demographics. A logical (defaults to FALSE), specifying whether to add an additional summary variable across all stratified levels. 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.

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)