Title: | Infectious Disease Model Library and Utilities |
---|---|
Description: | Explore a range of infectious disease models in a consistent framework. The primary aim of 'idmodelr' is to provide a library of infectious disease models for researchers, students, and other interested individuals. These models can be used to understand the underlying dynamics and as a reference point when developing models for research. 'idmodelr' also provides a range of utilities. These include: plotting functionality; a simulation wrapper; scenario analysis tooling; an interactive dashboard; tools for handling mult-dimensional models; and both model and parameter look up tables. Unlike other modelling packages such as 'pomp' (<https://kingaa.github.io/pomp/>), 'libbi' (<http://libbi.org>) and 'EpiModel' (<http://www.epimodel.org>), 'idmodelr' serves primarily as an educational resource. It is most comparable to epirecipes (<http://epirecip.es/epicookbook/chapters/simple>) but provides a more consistent framework, an R based workflow, and additional utility tooling. After users have explored model dynamics with 'idmodelr' they may then implement their model using one of these packages in order to utilise the model fitting tools they provide. For newer modellers, this package reduces the barrier to entry by containing multiple infectious disease models, providing a consistent framework for simulation and visualisation, and signposting towards other, more research focussed, resources. |
Authors: | Sam Abbott [aut, cre] , Akira Endo [aut] |
Maintainer: | Sam Abbott <[email protected]> |
License: | GPL-3 |
Version: | 0.4.0 |
Built: | 2024-11-20 04:05:39 UTC |
Source: | https://github.com/seabbs/idmodelr |
Adds Pointer Structure to R objects
add_pointer_struct(char, length)
add_pointer_struct(char, length)
char |
A character vector. |
length |
The length of the returned object. |
A character vector of the concatenated character string with sequential numbering
## For a single variable add_pointer_struct("S", 3) ## For multiple variables add_pointer_struct(c("S", "I"), length = 3)
## For a single variable add_pointer_struct("S", 3) ## For multiple variables add_pointer_struct(c("S", "I"), length = 3)
A Function to Apply Multiple Aggregations to Model Output
aggregate_model( df, aggregate_to = NULL, compartments = NULL, strat = NULL, hold_out_var = NULL, id_col = NULL, groups = NULL, new_var = "incidence", total_pop = TRUE, summary_var = FALSE, test = FALSE )
aggregate_model( df, aggregate_to = NULL, compartments = NULL, strat = NULL, hold_out_var = NULL, id_col = NULL, groups = NULL, new_var = "incidence", total_pop = TRUE, summary_var = FALSE, test = FALSE )
df |
A dataframe of Model Output. |
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. |
id_col |
A character string containing the name of the new id column. |
groups |
A character vector with length equal to the level of stratification. Used to name the stratified levels. |
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 |
test |
Logical defaults to |
An aggregated dataframe.
aggregate_model aggregate_model_internal combine_to_age_model combine_strat_model_output summarise_var_by_strat
df <- data.frame(A1 = 1, B1 = 1, A2 = 1, B2 = 1, A3 = 1, B3 = 1) aggregate_model(df, aggregate_to = "incidence", compartments = c("A", "B"), strat = 3, summary_var = TRUE)
df <- data.frame(A1 = 1, B1 = 1, A2 = 1, B2 = 1, A3 = 1, B3 = 1) aggregate_model(df, aggregate_to = "incidence", compartments = c("A", "B"), strat = 3, summary_var = TRUE)
An Internal Function to Aggregate Model Output Using other Idmodelr functions.
aggregate_model_internal( df, aggregate_to = NULL, compartments = NULL, strat = NULL, hold_out_var = NULL, new_var = "incidence", id_col = NULL, groups = NULL, total_pop = TRUE, summary_var = FALSE )
aggregate_model_internal( df, aggregate_to = NULL, compartments = NULL, strat = NULL, hold_out_var = NULL, new_var = "incidence", id_col = NULL, groups = NULL, total_pop = TRUE, summary_var = FALSE )
df |
A dataframe of Model Output. |
aggregate_to |
A character vector specifying the aggregation function to apply possible values are; disease, demographic, or incidence. |
compartments |
A character vector specifying the unique compartments to aggregate. |
strat |
The number of stratified groups in the model. |
hold_out_var |
A character vector specifying the unique compartments not to aggregate. |
new_var |
A character vector specifying the new variable to add when aggregating incidence. |
id_col |
A character string containing the name of the new id column. |
groups |
A character vector with length equal to the level of stratification. Used to name the stratified levels. |
total_pop |
A logical (defaults to |
summary_var |
A logical (defaults to |
An aggregated dataframe.
aggregate_model aggregate_model_internal combine_to_age_model combine_strat_model_output summarise_var_by_strat
df <- data.frame(time = 1, A1 = 1, B1 = 1, A2 = 1, B2 = 1, A3 = 1, B3 = 1) ## Incidence aggregate_model_internal(df, aggregate_to = "incidence", compartments = c("A", "B"), strat = 3, summary_var = TRUE) ## Demographic aggregate_model_internal(df, aggregate_to = "demographic", compartments = c("A", "B"), strat = 3, summary_var = TRUE) ## Disease aggregate_model_internal(df, aggregate_to = "disease", compartments = c("A", "B"), strat = 3, summary_var = TRUE) ## Tidy (long) aggregate_model_internal(df, aggregate_to = "tidy", compartments = c("A", "B"), hold_out_var = "time", strat = 3, summary_var = TRUE, id_col = "Age", groups = c("Children", "Young adults", "Adults"))
df <- data.frame(time = 1, A1 = 1, B1 = 1, A2 = 1, B2 = 1, A3 = 1, B3 = 1) ## Incidence aggregate_model_internal(df, aggregate_to = "incidence", compartments = c("A", "B"), strat = 3, summary_var = TRUE) ## Demographic aggregate_model_internal(df, aggregate_to = "demographic", compartments = c("A", "B"), strat = 3, summary_var = TRUE) ## Disease aggregate_model_internal(df, aggregate_to = "disease", compartments = c("A", "B"), strat = 3, summary_var = TRUE) ## Tidy (long) aggregate_model_internal(df, aggregate_to = "tidy", compartments = c("A", "B"), hold_out_var = "time", strat = 3, summary_var = TRUE, id_col = "Age", groups = c("Children", "Young adults", "Adults"))
Reduces the dimensions of stratified model output. Default behaviour is to remove stratification for all variables. However, variables to reduce the dimensions of can be selected, as can variables to preserve with there structure intact.
combine_strat_model_output( df, strat = NULL, compartments = NULL, hold_out_var = NULL )
combine_strat_model_output( df, strat = NULL, compartments = NULL, hold_out_var = NULL )
df |
A data frame with variables stratified using numeric labels. |
strat |
An integer specifying the number of stratifications to reduce. |
compartments |
A character vector specifying the unique population compartments. |
hold_out_var |
A character vector specifying the variables to keep unchanged. Defaults to NULL |
A dataframe of model output that has its dimensionality reduced
combine_to_age_model
df <- data.frame(S1 = NA, S2 = NA, S3 = NA, time = NA) combine_strat_model_output(df, 3, compartments = "S", hold_out_var = "time")
df <- data.frame(S1 = NA, S2 = NA, S3 = NA, time = NA) combine_strat_model_output(df, 3, compartments = "S", hold_out_var = "time")
Similarly to combine_strat_model_output
this functions
reduces the dimension of model output into just the demographic components.
combine_to_age_model( df, age_com = NULL, compartments = NULL, hold_out_var = NULL, total_pop = TRUE )
combine_to_age_model( df, age_com = NULL, compartments = NULL, hold_out_var = NULL, total_pop = TRUE )
df |
A dataframe of model output. |
age_com |
Integer indicating the number of age compartments. |
compartments |
A character vector of the disease model compartments to combine. |
hold_out_var |
A character vector specifying the variables to keep unchanged. Defaults to NULL |
total_pop |
A logical indicating whether to calculate the total population. Defaults to true. |
A dataframe which summarises the demographic process of a model.
combine_strat_model_output
df <- data.frame(S1 = c(1,2), S2 = c(1, 3), E1 = c(4, 1), E2 = c(3, 4), time = c(1, 2)) combine_to_age_model(df, age_com = 2, hold_out_var = "time")
df <- data.frame(S1 = c(1,2), S2 = c(1, 3), E1 = c(4, 1), E2 = c(3, 4), time = c(1, 2)) combine_to_age_model(df, age_com = 2, hold_out_var = "time")
A Function to Estimate a Normal Distribution from Credible or Confidence Intervals
estimate_norm_dist_from_ci( lower_interval = NULL, upper_interval = NULL, interval = "95%" )
estimate_norm_dist_from_ci( lower_interval = NULL, upper_interval = NULL, interval = "95%" )
lower_interval |
Numeric, the lower CI. |
upper_interval |
Numeric, the upper CI |
interval |
A character string indicating the percentage interval the CI represents. |
A dataframe containing the mean and standard deviation of the normal distribution summarised by the provided CI's.
## Run function to estimate normal distribution for a 95% CI of 1, to 2 df <- estimate_norm_dist_from_ci(1,2) ## Check x <- rnorm(10000, df$mean, df$sd) quantile(x, c(0.025, 0.975))
## Run function to estimate normal distribution for a 95% CI of 1, to 2 df <- estimate_norm_dist_from_ci(1,2) ## Check x <- rnorm(10000, df$mean, df$sd) quantile(x, c(0.025, 0.975))
A Function to Gather Multiple Stratified Variables into a Tidy Format
gather_strat_multi_variable( df, id_col, compartments = NULL, hold_out_var = NULL, strat = NULL, groups = NULL )
gather_strat_multi_variable( df, id_col, compartments = NULL, hold_out_var = NULL, strat = NULL, groups = NULL )
df |
A data frame with variables stratified using numeric labels. |
id_col |
A character string containing the name of the new id column. |
compartments |
A character vector specifying the unique population compartments. |
hold_out_var |
A character vector specifying the variables to keep unchanged. Defaults to NULL |
strat |
An integer specifying the number of stratifications to reduce. |
groups |
A character vector with length equal to the level of stratification. Used to name the stratified levels. |
A dataframe of stratified model output with multiple Tidy variables.
df <- data.frame(time = 0, A1 = 1, A2 = 2, A3 = 3, B1 = 2, B2 = 3, B3 = 0) gather_strat_multi_variable(df, id_col = "Age", compartment = c("A", "B"), hold_out_var = "time", strat = 3, groups = c("Children", "Young adults", "Adults"))
df <- data.frame(time = 0, A1 = 1, A2 = 2, A3 = 3, B1 = 2, B2 = 3, B3 = 0) gather_strat_multi_variable(df, id_col = "Age", compartment = c("A", "B"), hold_out_var = "time", strat = 3, groups = c("Children", "Young adults", "Adults"))
A Function to Gather a Stratified Variable into a Tidy Format
gather_strat_variable( df, id_col, compartment, hold_out_var = NULL, strat, groups = NULL )
gather_strat_variable( df, id_col, compartment, hold_out_var = NULL, strat, groups = NULL )
df |
A data frame with variables stratified using numeric labels. |
id_col |
A character string containing the name of the new id column. |
compartment |
The compartment to reduce the dimension of. |
hold_out_var |
A character vector specifying the variables to keep unchanged. Defaults to NULL |
strat |
An integer specifying the number of stratifications to reduce. |
groups |
A character vector with length equal to the level of stratification. Used to name the stratified levels. |
A dataframe of stratified model output with a single Tidy variable.
df <- data.frame(time = 0, A1 = 1, A2 = 2, A3 = 3) gather_strat_variable(df, id_col = "Age", compartment = "A", strat = 3, groups = c("Children", "Young adults", "Adults"))
df <- data.frame(time = 0, A1 = 1, A2 = 2, A3 = 3) gather_strat_variable(df, id_col = "Age", compartment = "A", strat = 3, groups = c("Children", "Young adults", "Adults"))
A function to generate parameter permutations from a generic sampling function (or if not given from the input parameters). This function can be used to rapidly generate new parameter combinations given parameters to be varied, and scenarios to be investigated.
generate_parameter_permutations( variable_params = NULL, fixed_params = NULL, sample_params = NULL, excluded_params = NULL, scenarios = NULL, sampling_function = NULL, parameter_samples = 1, repeat_sample = TRUE, rerun = FALSE, ... )
generate_parameter_permutations( variable_params = NULL, fixed_params = NULL, sample_params = NULL, excluded_params = NULL, scenarios = NULL, sampling_function = NULL, parameter_samples = 1, repeat_sample = TRUE, rerun = FALSE, ... )
variable_params |
A dataframe containing any parameter variations to be investigated. If these parameters would normally be sampled then they should be added to the excluded_params argument. |
fixed_params |
A named vector of parameters that are not sampled by the sampling function. If these parameters would usually be sampled then they should be added to the excluded_params argument. |
sample_params |
A named vector of parameters to be sampled. If a sampling function is not supplied these parameters will be used in the final permutation dataframe. |
excluded_params |
A character vector indicating which parameters should have there sampled values kept. |
scenarios |
A dataframe of possible scenarios to investigate. It must contain a scenario variable to identify each separate scenarios. If parameters are included here that would normally be sampled then they should be added to the excluded_params argument |
sampling_function |
A sampling function, this should be designed such that it's input is a matrix with each parameter having a named row. It should return it's output in the same format. If not supplied defaults to passing through parameters, this may not be the required behaviour. |
parameter_samples |
The number of parameter samples to take, defaults to one. |
repeat_sample |
A logical (defaults to |
rerun |
A logical indicating if the function should be rerun or saved results should be loaded.
Defaults to |
... |
Additional arguments to be passed to the sampling_function. |
A dataframe containing sampled parameter permutations
scenarios <- data.frame(scenario = c("test_1", "test_2"), scenario_param = c(0, 1)) variable_params <- data.frame(variable = c(0, 0.5, 1)) fixed_params <- c(fixed_1 = 2, fixed_2 = c(1, 3, 4)) sample_params <- c(sample_1 = 2, sample_2 = c(2, 1)) generate_parameter_permutations(variable_params, fixed_params, sample_params, excluded_params = c("variable"), scenarios, parameter_samples = 1)
scenarios <- data.frame(scenario = c("test_1", "test_2"), scenario_param = c(0, 1)) variable_params <- data.frame(variable = c(0, 0.5, 1)) fixed_params <- c(fixed_1 = 2, fixed_2 = c(1, 3, 4)) sample_params <- c(sample_1 = 2, sample_2 = c(2, 1)) generate_parameter_permutations(variable_params, fixed_params, sample_params, excluded_params = c("variable"), scenarios, parameter_samples = 1)
Details on models implemented in idmodelr
.
model_details
model_details
A data frame with 22 rows and 14 variables.
Name of the model function.
Name of the model family (i.e. SIR)
Discrete or continuous time
Deterministic or stochastic
Does this model included a recovered population (yes/no).
Does this model included an exposed population (yes/no).
Does this model included a treated population (yes/no).
Does this model included a post infection susceptible population (yes/no).
Is this model risk stratified (yes/no).
Does this model contain non-exponential rates (yes/no).
Does this model contain simple (i.e. births = deaths) demographics (yes/no).
Does this model include vaccination (yes/no).
Which diseases (if any) can this model be used for.
What language is this model written in (i.e. R, C etc.).
A list of parameters required by the model
.
Extracts a Single Column, Summarises if from Simulation
model_df_to_vector(df, com_var, id_var = NULL, sum_fn = NULL)
model_df_to_vector(df, com_var, id_var = NULL, sum_fn = NULL)
df |
A data frame of dynamic system output. |
com_var |
The vector to be compared; use unquoted name (NSE). |
id_var |
A character string indicating the id variable to summarise over if required. |
sum_fn |
The summary function to be used, defaults to median. |
Returns a numeric vector, summarised if required.
library(dplyr) ## Extract a vector with no repeats model_df_to_vector(iris, Petal.Length) ## Extract a vector and summarise df <- bind_rows(iris %>% mutate(sim = 1, id = 1:length(sim)), iris %>% mutate(sim = 2 , id = 1:length(sim))) model_df_to_vector(df, Petal.Length, "id", sum_fn = mean)
library(dplyr) ## Extract a vector with no repeats model_df_to_vector(iris, Petal.Length) ## Extract a vector and summarise df <- bind_rows(iris %>% mutate(sim = 1, id = 1:length(sim)), iris %>% mutate(sim = 2 , id = 1:length(sim))) model_df_to_vector(df, Petal.Length, "id", sum_fn = mean)
Details on the parameters used in models implemented in idmodelr
.
parameter_details
parameter_details
A data frame with 14 rows and 6 variables.
Name of the parameter.
Descriptive parameter family (i.e. transmission).
What is this parameter.
What type of parameter is this (i.e rate, proportion, probability etc.).
Is this parameter used in risk stratified models (yes/no).
Is this parameter a non-exponential rate (yes/no).
Make separate plots for each model compartment. Assumes model output is structured
as that produced from solve_ode
.
plot_model(sim, prev_sim = NULL, model_labels = NULL, facet = TRUE)
plot_model(sim, prev_sim = NULL, model_labels = NULL, facet = TRUE)
sim |
A tibble of model output as formatted by |
prev_sim |
A second tibble of model output formatted as for |
model_labels |
A character vector of model names. Defaults to |
facet |
Logical, defaults to |
A Plot of each model compartments population over time.
## 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 <- as.matrix(c(beta = beta)) inits <- as.matrix(c(S = S_0, I = I_0)) sim <- solve_ode(model = SI_ode, inits, parameters, times, as.data.frame = TRUE) plot_model(sim, facet = FALSE) plot_model(sim, facet = TRUE) ## Compare with an updated model run #'## Intialise R_0 = 1.3 beta = R_0 parameters <- as.matrix(c(beta = beta)) new_sim <- solve_ode(model = SI_ode, inits, parameters, times, as.data.frame = TRUE) plot_model(new_sim,sim, facet = FALSE) plot_model(new_sim, sim, facet = TRUE) ## Passing in the simulations as a list plot_model(list("Current" = new_sim, "Previous" = sim), facet = TRUE)
## 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 <- as.matrix(c(beta = beta)) inits <- as.matrix(c(S = S_0, I = I_0)) sim <- solve_ode(model = SI_ode, inits, parameters, times, as.data.frame = TRUE) plot_model(sim, facet = FALSE) plot_model(sim, facet = TRUE) ## Compare with an updated model run #'## Intialise R_0 = 1.3 beta = R_0 parameters <- as.matrix(c(beta = beta)) new_sim <- solve_ode(model = SI_ode, inits, parameters, times, as.data.frame = TRUE) plot_model(new_sim,sim, facet = FALSE) plot_model(new_sim, sim, facet = TRUE) ## Passing in the simulations as a list plot_model(list("Current" = new_sim, "Previous" = sim), facet = TRUE)
This function simplifies the process of checking which parameters a given idmodelr
model depends on.
It is effectively an interface to parameter_details
via model_details
. As
fuzzy matching has been used it can also given information of the parameter requirements of a subset of the available models.
required_parameters(model = NULL)
required_parameters(model = NULL)
model |
A character string containing the name of the model of interest. Defaults to |
A dataframe extracted from parameter_details
containing the details of the parameters
required by the model of interest.
## Check the parameters required by the "SIR_ode" model required_parameters("SIR_ode") ## Use fizzy matching to look at parameters for all SIR models required_parameters("SIR")
## Check the parameters required by the "SIR_ode" model required_parameters("SIR_ode") ## Use fizzy matching to look at parameters for all SIR models required_parameters("SIR")
This function uses parameter permutations produced by
generate_parameter_permutations
to simulate from a supplied model function.
It can be used to examine multiple scenarios, with any number of parameter variations, for multiple samples.
scenario_analysis( parameter_df, variable_params = NULL, model = NULL, sim_fn = NULL, summary_fn = NULL, cores = 1, rerun = FALSE, verbose = FALSE, by_row = FALSE, test = FALSE, ... )
scenario_analysis( parameter_df, variable_params = NULL, model = NULL, sim_fn = NULL, summary_fn = NULL, cores = 1, rerun = FALSE, verbose = FALSE, by_row = FALSE, test = FALSE, ... )
parameter_df |
A dataframe of parameter permutations as produced by |
variable_params |
A character vector containing the names of the parameters that are varied in |
model |
A model compatible with your |
sim_fn |
A generic simulation function, with the first argument as the model object,
a |
summary_fn |
A function which accepts a single dataframe argument customised to fit with the standard
output of |
cores |
The number of cores to use for the scenario analysis, defaults to 1. |
rerun |
A logical indicating if the function should be rerun or saved results should be loaded.
Defaults to |
verbose |
Logical (defaults to |
by_row |
Logical (defaults to |
test |
A logical (defaults to |
... |
Pass additional arguments to sim_fn. Only implemented when a single core is used. |
A tidy dataframe containing simulated model trajectories for each scenario varied parameter combination. Use 'tidyr::unnest“ to examine all simulation results.
scenarios <- data.frame(scenario = c("test_1", "test_2"), scenario_param = c(0, 1)) variable_params <- data.frame(variable = c(0, 0.5, 1)) fixed_params <- c(fixed_1 = 2, fixed_2 = c(1, 3, 4)) sample_params <- c(sample_1 = 2, sample_2 = c(2, 1)) parameter_df <- generate_parameter_permutations(variable_params, fixed_params, sample_params, excluded_params = c("variable"), scenarios, parameter_samples = 10) ## set up dummy simulation function (returning an empty dataframe) dummy_sim_fn <- function(object, inits, params, times, as.data.frame) { x <- tibble::tibble() return(x) } ## Set up dummy summary function dummy_sum_fn <- function(df){ df <- dplyr::mutate(df, summarised_simulations = simulations) return(df) } dummy_model <- function(){} ## Run scenario analysis scenario_analysis(parameter_df, variable_params = "variable", model = dummy_model, sim_fn = dummy_sim_fn, cores = 1, summary_fn = dummy_sum_fn)
scenarios <- data.frame(scenario = c("test_1", "test_2"), scenario_param = c(0, 1)) variable_params <- data.frame(variable = c(0, 0.5, 1)) fixed_params <- c(fixed_1 = 2, fixed_2 = c(1, 3, 4)) sample_params <- c(sample_1 = 2, sample_2 = c(2, 1)) parameter_df <- generate_parameter_permutations(variable_params, fixed_params, sample_params, excluded_params = c("variable"), scenarios, parameter_samples = 10) ## set up dummy simulation function (returning an empty dataframe) dummy_sim_fn <- function(object, inits, params, times, as.data.frame) { x <- tibble::tibble() return(x) } ## Set up dummy summary function dummy_sum_fn <- function(df){ df <- dplyr::mutate(df, summarised_simulations = simulations) return(df) } dummy_model <- function(){} ## Run scenario analysis scenario_analysis(parameter_df, variable_params = "variable", model = dummy_model, sim_fn = dummy_sim_fn, cores = 1, summary_fn = dummy_sum_fn)
Susceptible-Exposed-Infected Model with Simple Demographics
SEI_demographics_ode(t, x, params)
SEI_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 beta <- 3 gamma <- 1/2 mu <- 1/81 parameters <- c(beta = beta, gamma = gamma, mu = mu) inits <- c(S = S_0, E = E_0, I = I_0) SEI_demographics_ode(1, inits, parameters)
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 beta <- 3 gamma <- 1/2 mu <- 1/81 parameters <- c(beta = beta, gamma = gamma, mu = mu) inits <- c(S = S_0, E = E_0, I = I_0) SEI_demographics_ode(1, inits, parameters)
Susceptible-Exposed-Infected Model
SEI_ode(t, x, params)
SEI_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 beta <- 3 gamma = 1/2 parameters <- c(beta = beta, gamma = gamma) inits <- c(S = S_0, E = E_0, I = I_0) SEI_ode(1, inits, parameters)
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 beta <- 3 gamma = 1/2 parameters <- c(beta = beta, gamma = gamma) inits <- c(S = S_0, E = E_0, I = I_0) SEI_ode(1, inits, parameters)
Susceptible-Exposed-Infected-Recovered Model with Simple Demographics
SEIR_demographics_ode(t, x, params)
SEIR_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 R_0 <- 0 beta <- 3 gamma <- 1/2 tau <- 2 mu <- 1/81 parameters <- c(beta = beta, gamma = gamma, tau = tau, mu = mu) inits <- c(S = S_0, E = E_0, I = I_0, R_0 = R_0) SEIR_demographics_ode(1, inits, parameters)
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 R_0 <- 0 beta <- 3 gamma <- 1/2 tau <- 2 mu <- 1/81 parameters <- c(beta = beta, gamma = gamma, tau = tau, mu = mu) inits <- c(S = S_0, E = E_0, I = I_0, R_0 = R_0) SEIR_demographics_ode(1, inits, parameters)
Susceptible-Exposed-Infected-Recovered Model
SEIR_ode(t, x, params)
SEIR_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 R_0 <- 0 beta <- 3 gamma <- 1/2 tau <- 2 parameters <- c(beta = beta, gamma = gamma, tau = tau) inits <- c(S = S_0, E = E_0, I = I_0, R_0 = R_0) SEIR_ode(1, inits, parameters)
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 R_0 <- 0 beta <- 3 gamma <- 1/2 tau <- 2 parameters <- c(beta = beta, gamma = gamma, tau = tau) inits <- c(S = S_0, E = E_0, I = I_0, R_0 = R_0) SEIR_ode(1, inits, parameters)
Susceptible-Exposed-Infected-Recovered-Susceptible Model with Simple Demographics
SEIRS_demographics_ode(t, x, params)
SEIRS_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 R_0 <- 0 beta <- 3 gamma <- 1/2 tau <- 2 chi <- 0.5 mu <- 1/81 parameters <- c(beta = beta, gamma = gamma, chi = chi, tau = tau, mu = mu) inits <- c(S = S_0, E = E_0, I = I_0, R_0 = R_0) SEIRS_demographics_ode(1, inits, parameters)
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 R_0 <- 0 beta <- 3 gamma <- 1/2 tau <- 2 chi <- 0.5 mu <- 1/81 parameters <- c(beta = beta, gamma = gamma, chi = chi, tau = tau, mu = mu) inits <- c(S = S_0, E = E_0, I = I_0, R_0 = R_0) SEIRS_demographics_ode(1, inits, parameters)
Susceptible-Exposed-Infected-Recovered-Susceptible Model
SEIRS_ode(t, x, params)
SEIRS_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 R_0 <- 0 beta <- 3 gamma <- 1/2 tau <- 2 chi <- 0.5 parameters <- c(beta = beta, gamma = gamma, chi = chi, tau = tau) inits <- c(S = S_0, E = E_0, I = I_0, R_0 = R_0) SEIRS_ode(1, inits, parameters)
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 R_0 <- 0 beta <- 3 gamma <- 1/2 tau <- 2 chi <- 0.5 parameters <- c(beta = beta, gamma = gamma, chi = chi, tau = tau) inits <- c(S = S_0, E = E_0, I = I_0, R_0 = R_0) SEIRS_ode(1, inits, parameters)
Susceptible-Exposed-Infected-Susceptible Model with Simple Demographics
SEIS_demographics_ode(t, x, params)
SEIS_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 beta <- 3 chi <- 0.5 gamma <- 1/2 mu <- 1/81 parameters <- c(beta = beta, gamma = gamma, chi = chi, mu = mu) inits <- c(S = S_0, E = E_0, I = I_0) SEIS_demographics_ode(1, inits, parameters)
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 beta <- 3 chi <- 0.5 gamma <- 1/2 mu <- 1/81 parameters <- c(beta = beta, gamma = gamma, chi = chi, mu = mu) inits <- c(S = S_0, E = E_0, I = I_0) SEIS_demographics_ode(1, inits, parameters)
Susceptible-Exposed-Infected-Susceptible Model
SEIS_ode(t, x, params)
SEIS_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 beta <- 3 chi <- 0.5 gamma = 1/2 parameters <- c(beta = beta, gamma = gamma, chi = chi) inits <- c(S = S_0, E = E_0, I = I_0) SEIS_ode(1, inits, parameters)
##Model Input S_0 <- 989 E_0 <- 10 I_0 <- 1 beta <- 3 chi <- 0.5 gamma = 1/2 parameters <- c(beta = beta, gamma = gamma, chi = chi) inits <- c(S = S_0, E = E_0, I = I_0) SEIS_ode(1, inits, parameters)
Susceptible-High-risk-latent-Low-risk-latent-Infected-Recovered Model with Simple Demographics
SHLIR_demographics_ode(t, x, params)
SHLIR_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 H_0 <- 10 L_0 <- 0 I_0 <- 1 R_0 <- 0 beta = 3 # Rate of transmission gamma_H = 1/5 # Rate of progression to active symptoms from high risk latent nu = 1/2 #Rate of progression from high to low risk latent gamma_L = 1/100 # Rate of progression to active symptoms for low risk latent tau = 1/2 # Rate of recovery mu = 1/81 # Rate of natural mortality parameters <- c(beta = beta, gamma_H = gamma_H, gamma_L = gamma_L, nu = nu, tau = tau, mu = mu) inits <- c(S = S_0, H = H_0, L = L_0, I = I_0, R_0 = R_0) SHLIR_demographics_ode(1, inits, parameters)
##Model Input S_0 <- 989 H_0 <- 10 L_0 <- 0 I_0 <- 1 R_0 <- 0 beta = 3 # Rate of transmission gamma_H = 1/5 # Rate of progression to active symptoms from high risk latent nu = 1/2 #Rate of progression from high to low risk latent gamma_L = 1/100 # Rate of progression to active symptoms for low risk latent tau = 1/2 # Rate of recovery mu = 1/81 # Rate of natural mortality parameters <- c(beta = beta, gamma_H = gamma_H, gamma_L = gamma_L, nu = nu, tau = tau, mu = mu) inits <- c(S = S_0, H = H_0, L = L_0, I = I_0, R_0 = R_0) SHLIR_demographics_ode(1, inits, parameters)
Susceptible-High-risk-latent-Low-risk-latent-Infected-Recovered Model
SHLIR_ode(t, x, params)
SHLIR_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 H_0 <- 10 L_0 <- 0 I_0 <- 1 R_0 <- 0 beta = 3 # Rate of transmission gamma_H = 1/5 # Rate of progression to active symptoms from high risk latent nu = 1/2 #Rate of progression from high to low risk latent gamma_L = 1/100 # Rate of progression to active symptoms for low risk latent tau = 1/2 # Rate of recovery parameters <- c(beta = beta, gamma_H = gamma_H, gamma_L = gamma_L, nu = nu, tau = tau) inits <- c(S = S_0, H = H_0, L = L_0, I = I_0, R_0 = R_0) SHLIR_ode(1, inits, parameters)
##Model Input S_0 <- 989 H_0 <- 10 L_0 <- 0 I_0 <- 1 R_0 <- 0 beta = 3 # Rate of transmission gamma_H = 1/5 # Rate of progression to active symptoms from high risk latent nu = 1/2 #Rate of progression from high to low risk latent gamma_L = 1/100 # Rate of progression to active symptoms for low risk latent tau = 1/2 # Rate of recovery parameters <- c(beta = beta, gamma_H = gamma_H, gamma_L = gamma_L, nu = nu, tau = tau) inits <- c(S = S_0, H = H_0, L = L_0, I = I_0, R_0 = R_0) SHLIR_ode(1, inits, parameters)
A more complex SHLIR model flow diagram, treatment,reinfection, and simple demographics for those who have recovered from active disease.
SHLITR_demographics_ode(t, x, params)
SHLITR_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
## initialise inits <- c( # General population S = 800, H = 0, L = 0, I = 0, Tr = 0, R = 0 ) parameters <- c( beta = 3, # Rate of transmission gamma_H = 1/5, # Rate of progression to active symptoms from high risk latent nu = 1/2, #Rate of progression from high to low risk latent gamma_L = 1/100, # Rate of progression to active symptoms for low risk latent epsilon = 1/3, # Rate of treatment tau = 1/2, # Rate of recovery mu = 1/81 # Rate of natural mortality ) SHLITR_demographics_ode(1, inits, parameters)
## initialise inits <- c( # General population S = 800, H = 0, L = 0, I = 0, Tr = 0, R = 0 ) parameters <- c( beta = 3, # Rate of transmission gamma_H = 1/5, # Rate of progression to active symptoms from high risk latent nu = 1/2, #Rate of progression from high to low risk latent gamma_L = 1/100, # Rate of progression to active symptoms for low risk latent epsilon = 1/3, # Rate of treatment tau = 1/2, # Rate of recovery mu = 1/81 # Rate of natural mortality ) SHLITR_demographics_ode(1, inits, parameters)
A more complex SHLIR model flow diagram, treatment, and reinfection for those who have recovered from active disease.
SHLITR_ode(t, x, params)
SHLITR_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
## initialise inits <- c( # General population S = 800, H = 0, L = 0, I = 0, Tr = 0, R = 0 ) parameters <- c( beta = 3, # Rate of transmission gamma_H = 1/5, # Rate of progression to active symptoms from high risk latent nu = 1/2, #Rate of progression from high to low risk latent gamma_L = 1/100, # Rate of progression to active symptoms for low risk latent epsilon = 1/3, # Rate of treatment tau = 1/2 # Rate of recovery ) SHLITR_ode(1, inits, parameters)
## initialise inits <- c( # General population S = 800, H = 0, L = 0, I = 0, Tr = 0, R = 0 ) parameters <- c( beta = 3, # Rate of transmission gamma_H = 1/5, # Rate of progression to active symptoms from high risk latent nu = 1/2, #Rate of progression from high to low risk latent gamma_L = 1/100, # Rate of progression to active symptoms for low risk latent epsilon = 1/3, # Rate of treatment tau = 1/2 # Rate of recovery ) SHLITR_ode(1, inits, parameters)
A more complex SHLIR model flow diagram, with risk groups, treatment, and reinfection for those who have recovered from active disease
SHLITR_risk_demographics_ode(t, x, params)
SHLITR_risk_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
## initialise inits <- c( # General population S = 800, H = 0, L = 0, I = 0, Tr = 0, R = 0, ## High risk population S_H = 199, H_H = 0, L_H = 0, I_H = 1, Tr_H = 0, R_H = 0 ) parameters <- c( beta = 3, # Rate of transmission beta_H = 6, # High risk rate of transmission gamma_H = 1/5, # Rate of progression to active symptoms from high risk latent nu = 1/2, #Rate of progression from high to low risk latent gamma_L = 1/100, # Rate of progression to active symptoms for low risk latent epsilon = 1/3, # Rate of treatment tau = 1/2, # Rate of recovery mu = 1/81, # Rate of natural mortality p = 0.2, # proportion of new births that are high risk M = 0.2 # Between group mixing ) SHLITR_risk_demographics_ode(1, inits, parameters)
## initialise inits <- c( # General population S = 800, H = 0, L = 0, I = 0, Tr = 0, R = 0, ## High risk population S_H = 199, H_H = 0, L_H = 0, I_H = 1, Tr_H = 0, R_H = 0 ) parameters <- c( beta = 3, # Rate of transmission beta_H = 6, # High risk rate of transmission gamma_H = 1/5, # Rate of progression to active symptoms from high risk latent nu = 1/2, #Rate of progression from high to low risk latent gamma_L = 1/100, # Rate of progression to active symptoms for low risk latent epsilon = 1/3, # Rate of treatment tau = 1/2, # Rate of recovery mu = 1/81, # Rate of natural mortality p = 0.2, # proportion of new births that are high risk M = 0.2 # Between group mixing ) SHLITR_risk_demographics_ode(1, inits, parameters)
A more complex SHLIR model flow diagram, with risk groups, treatment, and reinfection for those who have recovered from active disease
SHLITR_risk_ode(t, x, params)
SHLITR_risk_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
## initialise inits <- c( # General population S = 800, H = 0, L = 0, I = 0, Tr = 0, R = 0, ## High risk population S_H = 199, H_H = 0, L_H = 0, I_H = 1, Tr_H = 0, R_H = 0 ) parameters <- c( beta = 3, # Rate of transmission beta_H = 6, # High risk rate of transmission gamma_H = 1/5, # Rate of progression to active symptoms from high risk latent nu = 1/2, #Rate of progression from high to low risk latent gamma_L = 1/100, # Rate of progression to active symptoms for low risk latent epsilon = 1/3, # Rate of treatment tau = 1/2, # Rate of recovery M = 0.2 # Between group mixing ) SHLITR_risk_ode(1, inits, parameters)
## initialise inits <- c( # General population S = 800, H = 0, L = 0, I = 0, Tr = 0, R = 0, ## High risk population S_H = 199, H_H = 0, L_H = 0, I_H = 1, Tr_H = 0, R_H = 0 ) parameters <- c( beta = 3, # Rate of transmission beta_H = 6, # High risk rate of transmission gamma_H = 1/5, # Rate of progression to active symptoms from high risk latent nu = 1/2, #Rate of progression from high to low risk latent gamma_L = 1/100, # Rate of progression to active symptoms for low risk latent epsilon = 1/3, # Rate of treatment tau = 1/2, # Rate of recovery M = 0.2 # Between group mixing ) SHLITR_risk_ode(1, inits, parameters)
Susceptible-Infected Model with Simple Demographics
SI_demographics_ode(t, x, params)
SI_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 999 I_0 <- 1 beta <- 3 mu <- 1/81 parameters <- c(beta = beta, mu = mu) inits <- c(S = S_0, I = I_0) SI_demographics_ode(1, inits, parameters)
##Model Input S_0 <- 999 I_0 <- 1 beta <- 3 mu <- 1/81 parameters <- c(beta = beta, mu = mu) inits <- c(S = S_0, I = I_0) SI_demographics_ode(1, inits, parameters)
Susceptible-Infected Model
SI_ode(t, x, params)
SI_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 999 I_0 <- 1 beta <- 3 parameters <- c(beta = beta) inits <- c(S = S_0, I = I_0) SI_ode(1, inits, parameters)
##Model Input S_0 <- 999 I_0 <- 1 beta <- 3 parameters <- c(beta = beta) inits <- c(S = S_0, I = I_0) SI_ode(1, inits, parameters)
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, ... )
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)
## 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)
Susceptible-Infected-Recovered Model with Simple Demographics
SIR_demographics_ode(t, x, params)
SIR_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 I_0 <- 1 R_0 <- 0 beta <- 3 tau <- 2 mu <- 1/81 parameters <- c(beta = beta, tau = tau, mu = mu) inits <- c(S = S_0, I = I_0, R_0 = R_0) SIR_demographics_ode(1, inits, parameters)
##Model Input S_0 <- 989 I_0 <- 1 R_0 <- 0 beta <- 3 tau <- 2 mu <- 1/81 parameters <- c(beta = beta, tau = tau, mu = mu) inits <- c(S = S_0, I = I_0, R_0 = R_0) SIR_demographics_ode(1, inits, parameters)
Susceptible-Infected-Recovered Model
SIR_ode(t, x, params)
SIR_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 I_0 <- 1 R_0 <- 0 beta <- 3 tau <- 2 parameters <- c(beta = beta, tau = tau) inits <- c(S = S_0, I = I_0, R_0 = R_0) SIR_ode(1, inits, parameters)
##Model Input S_0 <- 989 I_0 <- 1 R_0 <- 0 beta <- 3 tau <- 2 parameters <- c(beta = beta, tau = tau) inits <- c(S = S_0, I = I_0, R_0 = R_0) SIR_ode(1, inits, parameters)
Susceptible-Infected-Recovered Model with Simple Demographics and Vaccination
SIR_vaccination_demographics_ode(t, x, params)
SIR_vaccination_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_u_0 <- 989 I_u_0 <- 1 R_u_0 <- 0 S_v_0 <- 0 I_v_0 <- 0 R_v_0 <- 0 beta <- 3 tau <- 2 mu <- 1/81 alpha <- 0.8 lambda <- 0.7 parameters <- c(beta = beta, tau = tau, mu = mu, alpha = 0.8, lambda = 0.7) inits <- c(S_u = S_u_0, I_u = I_u_0, R_u_0 = R_u_0, S_v = S_v_0, I_v = I_v_0, R_v_0 = R_v_0) SIR_vaccination_demographics_ode(1, inits, parameters)
##Model Input S_u_0 <- 989 I_u_0 <- 1 R_u_0 <- 0 S_v_0 <- 0 I_v_0 <- 0 R_v_0 <- 0 beta <- 3 tau <- 2 mu <- 1/81 alpha <- 0.8 lambda <- 0.7 parameters <- c(beta = beta, tau = tau, mu = mu, alpha = 0.8, lambda = 0.7) inits <- c(S_u = S_u_0, I_u = I_u_0, R_u_0 = R_u_0, S_v = S_v_0, I_v = I_v_0, R_v_0 = R_v_0) SIR_vaccination_demographics_ode(1, inits, parameters)
Susceptible-Infected-Recovered Model with Vaccination
SIR_vaccination_ode(t, x, params)
SIR_vaccination_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_u_0 <- 989 I_u_0 <- 1 R_u_0 <- 0 S_v_0 <- 0 I_v_0 <- 0 R_v_0 <- 0 beta <- 3 tau <- 2 lambda <- 0.7 parameters <- c(beta = beta, tau = tau, lambda = 0.7) inits <- c(S_u = S_u_0, I_u = I_u_0, R_u_0 = R_u_0, S_v = S_v_0, I_v = I_v_0, R_v_0 = R_v_0) SIR_vaccination_ode(1, inits, parameters)
##Model Input S_u_0 <- 989 I_u_0 <- 1 R_u_0 <- 0 S_v_0 <- 0 I_v_0 <- 0 R_v_0 <- 0 beta <- 3 tau <- 2 lambda <- 0.7 parameters <- c(beta = beta, tau = tau, lambda = 0.7) inits <- c(S_u = S_u_0, I_u = I_u_0, R_u_0 = R_u_0, S_v = S_v_0, I_v = I_v_0, R_v_0 = R_v_0) SIR_vaccination_ode(1, inits, parameters)
Susceptible-Infected-Recovered-Susceptible Model with Simple Demographics
SIRS_demographics_ode(t, x, params)
SIRS_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 I_0 <- 1 R_0 <- 0 beta <- 3 chi <- 0.5 tau <- 2 mu <- 1/81 dt <- 1 parameters <- c(beta = beta, tau = tau, mu = mu) inits <- c(S = S_0, I = I_0, R_0 = R_0) SIRS_demographics_ode(1, inits, parameters)
##Model Input S_0 <- 989 I_0 <- 1 R_0 <- 0 beta <- 3 chi <- 0.5 tau <- 2 mu <- 1/81 dt <- 1 parameters <- c(beta = beta, tau = tau, mu = mu) inits <- c(S = S_0, I = I_0, R_0 = R_0) SIRS_demographics_ode(1, inits, parameters)
Susceptible-Infected-Recovered-Susceptible Model
SIRS_ode(t, x, params)
SIRS_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 989 I_0 <- 1 R_0 <- 0 beta <- 3 chi <- 0.5 tau <- 2 dt <- 1 parameters <- c(beta = beta, tau = tau, chi = chi) inits <- c(S = S_0, I = I_0, R_0 = R_0) SIRS_ode(1, inits, parameters)
##Model Input S_0 <- 989 I_0 <- 1 R_0 <- 0 beta <- 3 chi <- 0.5 tau <- 2 dt <- 1 parameters <- c(beta = beta, tau = tau, chi = chi) inits <- c(S = S_0, I = I_0, R_0 = R_0) SIRS_ode(1, inits, parameters)
Susceptible-Infected-Recovered-Susceptible Model with Simple Demographics and Vaccination
SIRS_vaccination_demographics_ode(t, x, params)
SIRS_vaccination_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_u_0 <- 989 I_u_0 <- 1 R_u_0 <- 0 S_v_0 <- 0 I_v_0 <- 0 R_v_0 <- 0 beta <- 3 tau <- 2 chi <- 0.5 mu <- 1/81 alpha <- 0.8 lambda <- 0.7 dt <- 1 parameters <- c(beta = beta, tau = tau, mu = mu, alpha = 0.8, lambda = 0.7) inits <- c(S_u = S_u_0, I_u = I_u_0, R_u_0 = R_u_0, S_v = S_v_0, I_v = I_v_0, R_v_0 = R_v_0) SIRS_vaccination_demographics_ode(1, inits, parameters)
##Model Input S_u_0 <- 989 I_u_0 <- 1 R_u_0 <- 0 S_v_0 <- 0 I_v_0 <- 0 R_v_0 <- 0 beta <- 3 tau <- 2 chi <- 0.5 mu <- 1/81 alpha <- 0.8 lambda <- 0.7 dt <- 1 parameters <- c(beta = beta, tau = tau, mu = mu, alpha = 0.8, lambda = 0.7) inits <- c(S_u = S_u_0, I_u = I_u_0, R_u_0 = R_u_0, S_v = S_v_0, I_v = I_v_0, R_v_0 = R_v_0) SIRS_vaccination_demographics_ode(1, inits, parameters)
Susceptible-Infected-Recovered-Susceptible Model with Vaccination
SIRS_vaccination_ode(t, x, params)
SIRS_vaccination_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_u_0 <- 989 I_u_0 <- 1 R_u_0 <- 0 S_v_0 <- 0 I_v_0 <- 0 R_v_0 <- 0 beta <- 3 chi <- 0.5 tau <- 2 lambda <- 0.7 dt <- 1 parameters <- c(beta = beta, tau = tau, chi = chi, lambda = 0.7) inits <- c(S_u = S_u_0, I_u = I_u_0, R_u_0 = R_u_0, S_v = S_v_0, I_v = I_v_0, R_v_0 = R_v_0) SIRS_vaccination_ode(1, inits, parameters)
##Model Input S_u_0 <- 989 I_u_0 <- 1 R_u_0 <- 0 S_v_0 <- 0 I_v_0 <- 0 R_v_0 <- 0 beta <- 3 chi <- 0.5 tau <- 2 lambda <- 0.7 dt <- 1 parameters <- c(beta = beta, tau = tau, chi = chi, lambda = 0.7) inits <- c(S_u = S_u_0, I_u = I_u_0, R_u_0 = R_u_0, S_v = S_v_0, I_v = I_v_0, R_v_0 = R_v_0) SIRS_vaccination_ode(1, inits, parameters)
Susceptible-Infected-Susceptible Model with Simple Demographics
SIS_demographics_ode(t, x, params)
SIS_demographics_ode(t, x, params)
t |
The timestep over which to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 999 I_0 <- 1 beta <- 3 chi <- 2 mu <- 1/81 dt <- 1 parameters <- c(beta = beta, mu = mu) inits <- c(S = S_0, I = I_0) SIS_demographics_ode(1, inits, parameters)
##Model Input S_0 <- 999 I_0 <- 1 beta <- 3 chi <- 2 mu <- 1/81 dt <- 1 parameters <- c(beta = beta, mu = mu) inits <- c(S = S_0, I = I_0) SIS_demographics_ode(1, inits, parameters)
Susceptible-Infected-Susceptible Model
SIS_ode(t, x, params)
SIS_ode(t, x, params)
t |
The timestep overwhich to calculate derivatives |
x |
A numeric vector of compartment populations. |
params |
A named vector of parameter values. |
A vector of derivatives
##Model Input S_0 <- 999 I_0 <- 1 beta <- 3 chi <- 2 parameters <- c(beta = beta, chi = chi) inits <- c(S = S_0, I = I_0) SIS_ode(1, inits, parameters)
##Model Input S_0 <- 999 I_0 <- 1 beta <- 3 chi <- 2 parameters <- c(beta = beta, chi = chi) inits <- c(S = S_0, I = I_0) SIS_ode(1, inits, parameters)
This function acts as a simple wrapper for lsoda, allowing for multiple parameter sets and
initial conditions. It also allows lsoda
to be used within the idmodelr framework.
solve_ode( model = NULL, inits = NULL, params = NULL, times = NULL, as.data.frame = TRUE, ... )
solve_ode( model = NULL, inits = NULL, params = NULL, times = NULL, as.data.frame = TRUE, ... )
model |
A model formatted as required by |
inits |
The initial state (states) of the model. Can either be supplied as a named vector or as a matrix with each row representing a parameter. |
params |
A named vector or matrix of parameters. The matrix must have a row for each parameter and if |
times |
A numeric vector of the times for which explicit model estimates are required, this does not effect the timestep used by the solver |
as.data.frame |
A logical (defaults to |
... |
Additional arguments to pass to |
A dataframe or lsoda object containing a single or multiple model trajectories
## 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 <- as.matrix(c(beta = beta)) inits <- as.matrix(c(S = S_0, I = I_0)) solve_ode(model = SI_ode, inits, parameters, times, as.data.frame = TRUE)
## 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 <- as.matrix(c(beta = beta)) inits <- as.matrix(c(S = S_0, I = I_0)) solve_ode(model = SI_ode, inits, parameters, times, as.data.frame = TRUE)
Provides simple summary statistics for a model produced using
solve_ode
. These include the final population
sizes, the time and size of the maximum epidemic peak, and the duration of
the epidemic.
summarise_model(sim)
summarise_model(sim)
sim |
A tibble of model output as produced by
|
A tibble of summary information for a model simulation.
## 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 <- as.matrix(c(beta = beta)) inits <- as.matrix(c(S = S_0, I = I_0)) sim <- solve_ode(model = SI_ode, inits, parameters, times, as.data.frame = TRUE) summarise_model(sim)
## 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 <- as.matrix(c(beta = beta)) inits <- as.matrix(c(S = S_0, I = I_0)) sim <- solve_ode(model = SI_ode, inits, parameters, times, as.data.frame = TRUE) summarise_model(sim)
Sum a Stratified Variable
summarise_strat_var(df, vars, strat = NULL, new_var = "sum")
summarise_strat_var(df, vars, strat = NULL, new_var = "sum")
df |
A dataframe of model output. |
vars |
A character vector containing the unstratified variables to summarise |
strat |
The number of stratifications present in the data set |
new_var |
The name of the summarised variable |
Returns the original dataframe with an additional summarised variable
summarise_var_by_strat
df <- dplyr::mutate(iris, Petal.Length1 = Petal.Length, Petal.Length2 = Petal.Length) df <- tibble::as_tibble(df) summarise_strat_var(df, vars = c("Petal.Length"), strat = 2, new_var = "sum")
df <- dplyr::mutate(iris, Petal.Length1 = Petal.Length, Petal.Length2 = Petal.Length) df <- tibble::as_tibble(df) summarise_strat_var(df, vars = c("Petal.Length"), strat = 2, new_var = "sum")
Sum a Stratified Variable by Stratification Level
summarise_var_by_strat(df, vars, strat = NULL, new_var, summary_var = FALSE)
summarise_var_by_strat(df, vars, strat = NULL, new_var, summary_var = FALSE)
df |
A dataframe of model output. |
vars |
A character vector containing the unstratified variables to summarise |
strat |
The number of stratifications present in the data set |
new_var |
The name of the summarised variable |
summary_var |
A logical (defaults to |
Takes compartmental infectious disease output and adds summary statistics for each stratified population, optionally adding a final summary statistic for the whole population.
An updated data frame containing the summarised variable for each stratified level and for the whole population.
summarise_var_by_strat
df <- data.frame(A = 1, B = 2) summarise_var_by_strat(df, vars = c("A", "B"), new_var = "C") df <- data.frame(A1 = 1, B1 = 1, A2 = 1, B2 = 1, A3 = 1, B3 = 1) summarise_var_by_strat(df, vars = c("A", "B"), strat = 3, new_var = "C") summarise_var_by_strat(df, vars = c("A", "B"), strat = 3, new_var = "C", summary_var = TRUE)
df <- data.frame(A = 1, B = 2) summarise_var_by_strat(df, vars = c("A", "B"), new_var = "C") df <- data.frame(A1 = 1, B1 = 1, A2 = 1, B2 = 1, A3 = 1, B3 = 1) summarise_var_by_strat(df, vars = c("A", "B"), strat = 3, new_var = "C") summarise_var_by_strat(df, vars = c("A", "B"), strat = 3, new_var = "C", summary_var = TRUE)