diff --git a/compare-interventions.md b/compare-interventions.md
index 2952b0f6..855bf7ab 100644
--- a/compare-interventions.md
+++ b/compare-interventions.md
@@ -16,7 +16,7 @@ exercises: 30 # exercise time in minutes
::::::::::::::::::::::::::::::::::::: objectives
-- Understand how to compare intervention scenarios
+- Compare intervention scenarios
::::::::::::::::::::::::::::::::::::::::::::::::
@@ -25,7 +25,7 @@ exercises: 30 # exercise time in minutes
## Prerequisites
+ Complete tutorials [Simulating transmission](../episodes/simulating-transmission.md) and [Modelling interventions](../episodes/modelling-interventions.md)
-This tutorial has the following concept dependencies:
+Learners should familiarise themselves with following concept dependencies before working through this tutorial:
**Outbreak response** : [Intervention types](https://www.cdc.gov/nonpharmaceutical-interventions/).
:::::::::::::::::::::::::::::::::
@@ -50,7 +50,7 @@ In this tutorial we introduce the concept of the counter factual and how to comp
## Vacamole model
-The Vacamole model is a deterministic model based on a system of ODEs in [Ainslie et al. 2022]( https://doi.org/10.2807/1560-7917.ES.2022.27.44.2101090). The model consists of 11 compartments, individuals are classed as one of the following:
+The Vacamole model is a deterministic model based on a system of ODEs in [Ainslie et al. 2022]( https://doi.org/10.2807/1560-7917.ES.2022.27.44.2101090) to describe the effect of vaccination on COVID-19 dynamics. The model consists of 11 compartments, individuals are classed as one of the following:
+ susceptible, $S$,
+ partial vaccination ($V_1$), fully vaccination ($V_2$),
@@ -64,42 +64,174 @@ The diagram below describes the flow of individuals through the different compar
-See `?epidemics::model_vacamole_cpp` for detail on how to run the model.
-## Comparing scenarios
+::::::::::::::::::::::::::::::::::::: challenge
-*Coming soon*
+## Running a counterfactual scenario using the Vacamole model
-## Challenge
+1. Run the model with the default parameter values for the UK population assuming that :
-*Coming soon*
++ 1 in a million individual are infectious (and not vaccinated) at the start of the simulation
++ The contact matrix for the United Kingdom has age bins:
+ + age between 0 and 20 years,
+ + age between 20 and 40,
+ + 40 years and over.
++ There is no vaccination scheme in place
+
+2. Using the output, plot the number of deaths through time
+
+
+::::::::::::::::: hint
+
+### Vaccination code
+
+To run the model with no vaccination in place we can *either* create two vaccination objects (one for each dose) using `vaccination()` with the time start, time end and vaccination rate all set to 0, or we can use the `no_vaccination()` function to create a vaccination object for two doses with all values set to 0.
+
+
+```r
+no_vaccination <- no_vaccination(population = uk_population, doses = 2)
+```
+::::::::::::::::::::::
+
+::::::::::::::::: hint
+
+### HINT : Running the model with default parameter values
+
+We can run the Vacamole model with [default parameter values](https://epiverse-trace.github.io/epidemics/articles/vacamole.html#model-epidemic-using-vacamole) by just specifying the population object and number of time steps to run the model for:
+
+
+
+```r
+output <- model_vacamole_cpp(
+ population = uk_population,
+ vaccination = no_vaccination,
+ time_end = 300
+)
+```
+
+::::::::::::::::::::::
-
-
+::::::::::::::::: solution
+### SOLUTION
-
+1. Run the model
-
+```r
+polymod <- socialmixr::polymod
+contact_data <- socialmixr::contact_matrix(
+ survey = polymod,
+ countries = "United Kingdom",
+ age.limits = c(0, 20, 40),
+ symmetric = TRUE
+)
+```
-
+```{.output}
+Using POLYMOD social contact data. To cite this in a publication, use the 'get_citation()' function
+```
+```{.output}
+Removing participants that have contacts without age information. To change this behaviour, set the 'missing.contact.age' option
+```
-
+```r
+# prepare contact matrix
+contact_matrix <- t(contact_data$matrix)
-
+# extract demography vector
+demography_vector <- contact_data$demography$population
+names(demography_vector) <- rownames(contact_matrix)
+# prepare initial conditions
+initial_i <- 1e-6
+initial_conditions <- c(
+ S = 1 - initial_i,
+ V1 = 0, V2 = 0,
+ E = 0, EV = 0,
+ I = initial_i, IV = 0,
+ H = 0, HV = 0, D = 0, R = 0
+)
+initial_conditions <- rbind(
+ initial_conditions,
+ initial_conditions,
+ initial_conditions
+)
+rownames(initial_conditions) <- rownames(contact_matrix)
+# prepare population object
+uk_population <- population(
+ name = "UK",
+ contact_matrix = contact_matrix,
+ demography_vector = demography_vector,
+ initial_conditions = initial_conditions
+)
-
+no_vaccination <- no_vaccination(population = uk_population, doses = 2)
+# run model
+output <- model_vacamole_cpp(
+ population = uk_population,
+ vaccination = no_vaccination,
+ time_end = 300
+)
+```
+
+2. Plot the number of deaths through time
+
+
+```r
+ggplot(output[output$compartment == "dead", ]) +
+ geom_line(
+ aes(time, value, colour = demography_group),
+ linewidth = 1
+ ) +
+ scale_colour_brewer(
+ palette = "Dark2",
+ labels = rownames(contact_matrix),
+ name = "Age group"
+ ) +
+ scale_y_continuous(
+ labels = scales::comma
+ ) +
+ labs(
+ x = "Simulation time (days)",
+ y = "Individuals"
+ ) +
+ theme(
+ legend.position = "top"
+ ) +
+ theme_bw(
+ base_size = 15
+ )
+```
+
+
+
+
+
+:::::::::::::::::::::::::::
+
+
+::::::::::::::::::::::::::::::::::::::::::::::::
+
+
+
+## Comparing scenarios
+
+*Coming soon*
+
+
+
+## Challenge : Ebola outbreak analysis
+
+*Coming soon*
-
diff --git a/fig/compare-interventions-rendered-unnamed-chunk-5-1.png b/fig/compare-interventions-rendered-unnamed-chunk-5-1.png
new file mode 100644
index 00000000..9db2cbe5
Binary files /dev/null and b/fig/compare-interventions-rendered-unnamed-chunk-5-1.png differ
diff --git a/fig/model-choices-rendered-diagram-1.png b/fig/model-choices-rendered-diagram-1.png
index eb18a7f6..ca8324c8 100644
Binary files a/fig/model-choices-rendered-diagram-1.png and b/fig/model-choices-rendered-diagram-1.png differ
diff --git a/fig/model-choices-rendered-unnamed-chunk-1-1.png b/fig/model-choices-rendered-unnamed-chunk-1-1.png
index 5a803301..1b7aa851 100644
Binary files a/fig/model-choices-rendered-unnamed-chunk-1-1.png and b/fig/model-choices-rendered-unnamed-chunk-1-1.png differ
diff --git a/fig/model-choices-rendered-unnamed-chunk-3-1.png b/fig/model-choices-rendered-unnamed-chunk-3-1.png
new file mode 100644
index 00000000..88ae9744
Binary files /dev/null and b/fig/model-choices-rendered-unnamed-chunk-3-1.png differ
diff --git a/fig/modelling-interventions-rendered-baseline-1.png b/fig/modelling-interventions-rendered-baseline-1.png
new file mode 100644
index 00000000..8bde486a
Binary files /dev/null and b/fig/modelling-interventions-rendered-baseline-1.png differ
diff --git a/fig/modelling-interventions-rendered-plot_masks-1.png b/fig/modelling-interventions-rendered-plot_masks-1.png
new file mode 100644
index 00000000..6669bb0d
Binary files /dev/null and b/fig/modelling-interventions-rendered-plot_masks-1.png differ
diff --git a/fig/modelling-interventions-rendered-plot_vaccinate-1.png b/fig/modelling-interventions-rendered-plot_vaccinate-1.png
new file mode 100644
index 00000000..f598e879
Binary files /dev/null and b/fig/modelling-interventions-rendered-plot_vaccinate-1.png differ
diff --git a/fig/simulating-transmission-rendered-diagram-1.png b/fig/simulating-transmission-rendered-diagram-1.png
index ab75590d..ca8324c8 100644
Binary files a/fig/simulating-transmission-rendered-diagram-1.png and b/fig/simulating-transmission-rendered-diagram-1.png differ
diff --git a/fig/simulating-transmission-rendered-plot-1.png b/fig/simulating-transmission-rendered-plot-1.png
new file mode 100644
index 00000000..4c020ba9
Binary files /dev/null and b/fig/simulating-transmission-rendered-plot-1.png differ
diff --git a/fig/simulating-transmission-rendered-traj-1.png b/fig/simulating-transmission-rendered-traj-1.png
new file mode 100644
index 00000000..6de308ad
Binary files /dev/null and b/fig/simulating-transmission-rendered-traj-1.png differ
diff --git a/fig/simulating-transmission-rendered-visualise-1.png b/fig/simulating-transmission-rendered-visualise-1.png
new file mode 100644
index 00000000..6de308ad
Binary files /dev/null and b/fig/simulating-transmission-rendered-visualise-1.png differ
diff --git a/md5sum.txt b/md5sum.txt
index 660270c0..fc70d1de 100644
--- a/md5sum.txt
+++ b/md5sum.txt
@@ -1,15 +1,15 @@
"file" "checksum" "built" "date"
-"CODE_OF_CONDUCT.md" "549f00b0992a7743c2bc16ea6ce3db57" "site/built/CODE_OF_CONDUCT.md" "2023-12-20"
-"LICENSE.md" "14377518ee654005a18cf28549eb30e3" "site/built/LICENSE.md" "2023-12-20"
-"config.yaml" "46df6477e1ca41a1c87c0bd036c4de8a" "site/built/config.yaml" "2023-12-20"
-"index.md" "adfca1a79e0106ee8b3f7731d0678b59" "site/built/index.md" "2023-12-20"
-"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2023-12-20"
-"episodes/simulating-transmission.Rmd" "24073c38e72e7759cf1552223940032e" "site/built/simulating-transmission.md" "2023-12-20"
-"episodes/model-choices.Rmd" "638cbe36fb15612bc564e5cf9f3c77e5" "site/built/model-choices.md" "2023-12-20"
-"episodes/modelling-interventions.Rmd" "ef12f024f60c47a957d364fa60d8b4b3" "site/built/modelling-interventions.md" "2023-12-20"
-"episodes/compare-interventions.Rmd" "6155de0722b94f8de3318d726d27f723" "site/built/compare-interventions.md" "2023-12-20"
-"instructors/instructor-notes.md" "ca3834a1b0f9e70c4702aa7a367a6bb5" "site/built/instructor-notes.md" "2023-12-20"
-"learners/reference.md" "7980e987fc72761f30df53cb3ef246fc" "site/built/reference.md" "2023-12-20"
-"learners/setup.md" "b3c6bfa13fd687f926bb1a3e772a2516" "site/built/setup.md" "2023-12-20"
-"profiles/learner-profiles.md" "31b503c4b5bd1f0960ada730eca4a25e" "site/built/learner-profiles.md" "2023-12-20"
-"renv/profiles/lesson-requirements/renv.lock" "9a76afbb24cadc53e338a9e657e62139" "site/built/renv.lock" "2023-12-20"
+"CODE_OF_CONDUCT.md" "549f00b0992a7743c2bc16ea6ce3db57" "site/built/CODE_OF_CONDUCT.md" "2023-12-21"
+"LICENSE.md" "14377518ee654005a18cf28549eb30e3" "site/built/LICENSE.md" "2023-12-21"
+"config.yaml" "46df6477e1ca41a1c87c0bd036c4de8a" "site/built/config.yaml" "2023-12-21"
+"index.md" "adfca1a79e0106ee8b3f7731d0678b59" "site/built/index.md" "2023-12-21"
+"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2023-12-21"
+"episodes/simulating-transmission.Rmd" "957e9471afa392a97da1551ce4a3b572" "site/built/simulating-transmission.md" "2023-12-21"
+"episodes/model-choices.Rmd" "866aab771a26d00ceed93750cee4b265" "site/built/model-choices.md" "2023-12-21"
+"episodes/modelling-interventions.Rmd" "258a8c0cc1fe6fbfabc3f90ca0d41a36" "site/built/modelling-interventions.md" "2023-12-21"
+"episodes/compare-interventions.Rmd" "f5ffe39d7728f03fb8cbe5efade69501" "site/built/compare-interventions.md" "2023-12-21"
+"instructors/instructor-notes.md" "ca3834a1b0f9e70c4702aa7a367a6bb5" "site/built/instructor-notes.md" "2023-12-21"
+"learners/reference.md" "de73c95256f9030b72ac9d56ff91cfe6" "site/built/reference.md" "2023-12-21"
+"learners/setup.md" "b3c6bfa13fd687f926bb1a3e772a2516" "site/built/setup.md" "2023-12-21"
+"profiles/learner-profiles.md" "31b503c4b5bd1f0960ada730eca4a25e" "site/built/learner-profiles.md" "2023-12-21"
+"renv/profiles/lesson-requirements/renv.lock" "c62d98bb51b1182dd5d21c540241976e" "site/built/renv.lock" "2023-12-21"
diff --git a/model-choices.md b/model-choices.md
index cc4ab9ac..cc829fe2 100644
--- a/model-choices.md
+++ b/model-choices.md
@@ -10,15 +10,14 @@ exercises: 20 # exercise time in minutes
:::::::::::::::::::::::::::::::::::::: questions
-- How do I choose a model for my task?
+- How do I choose a mathematical model that's appropriate to complete my analytical task?
::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::: objectives
-- Learn how to access the model library in `epidemics`
-- Understand the model requirements for a question
+- Understand the model requirements for a specific research question
::::::::::::::::::::::::::::::::::::::::::::::::
@@ -31,7 +30,7 @@ exercises: 20 # exercise time in minutes
## Introduction
-Using mathematical models in outbreak analysis does not necessarily require developing a new model. There are existing models for different infections, interventions and transmission patterns which can be used to answer new questions. In this tutorial, we will learn how to choose an existing model to generate predictions for a given scenario.
+There are existing mathematical models for different infections, interventions and transmission patterns which can be used to answer new questions. In this tutorial, we will learn how to choose an existing model to complete a given task.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: instructor
@@ -39,49 +38,77 @@ The focus of this tutorial is understanding existing models to decide if they ar
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+::::::::::::::::::::::::::::::::::::::: discussion
+
### Choosing a model
-When deciding whether an existing model can be used, we must consider :
+When deciding which mathematical model to use, there are a number of questions we must consider :
-+ What is the infection/disease of interest?
+:::::::::::::::::::::::::::::::::::::::::::::::::::
+
+:::::::::::::::: solution
+
+### What is the infection/disease of interest?
A model may already exist for your study disease, or there may be a model for an infection that has the same transmission pathways and epidemiological features that can be used.
-+ Do we need a [deterministic](../learners/reference.md#deterministic) or [stochastic](../learners/reference.md#stochastic) model?
+:::::::::::::::::::::::::
+
+:::::::::::::::: solution
+
+### Do we need a [deterministic](../learners/reference.md#deterministic) or [stochastic](../learners/reference.md#stochastic) model?
Model structures differ for whether the disease has pandemic potential or not. When predicted numbers of infection are small, stochastic variation in output can have an effect on whether an outbreak takes off or not. Outbreaks are usually smaller in magnitude than epidemics, so its often appropriate to use a stochastic model to characterise the uncertainty in the early stages of the outbreak. Epidemics are larger in magnitude than outbreaks and so a deterministic model is suitable as we have less interest in the stochastic variation in output.
-+ What is the outcome of interest?
+:::::::::::::::::::::::::
+
+:::::::::::::::: solution
+
+## What is the outcome of interest?
The outcome of interest can be a feature of a mathematical model. It may be that you are interested in the predicted numbers of infection through time, or in a specific outcome such as hospitalisations or cases of severe disease.
-+ Will any interventions be modelled?
+:::::::::::::::::::::::::
-Finally, interventions such as vaccination may be of interest. A model may or may not have the capability to include the impact of different interventions on different time scales (continuous time or at discrete time points). We will discuss interventions in detail in the next tutorial.
+:::::::::::::::: solution
-### Available models
-
-The R package `epidemics` contains functions to run existing models.
-For details on the models that are available, see the package [vignettes](https://epiverse-trace.github.io/epidemics/articles). To learn how to run the models in R, read the documentation using `?epidemics::model_ebola_r`. Remember to use the questions in the '[Check model equation](#check-model-equations)' checklist to help your understanding of an existing model.
+## How is transmission modelled?
-::::::::::::::::::::::::::::::::::::: checklist
-### Check model equations
+For example, [direct](../learners/reference.md#direct) or [indirect](../learners/reference.md#indirect), [airborne](../learners/reference.md#airborne) or [vector-borne](../learners/reference.md#vectorborne).
+:::::::::::::::::::::::::
-- How is transmission modelled? e.g. direct or indirect, airborne or vector-borne
-- What interventions are modelled?
-- What state variables are there and how do they relate to assumptions about infection?
-::::::::::::::::::::::::::::::::::::::::::::::::
+:::::::::::::::: solution
+
+## How are the different processes (e.g. transmission) formulated in the equations?
+
+There can be subtle differences in model structures for the same infection or outbreak type which can be missed without studying the equations. For example, transmissibility parameters can be specified as rates or probabilities. If you want to use parameter values from other published models, you must check that transmission is formulated in the same way.
+:::::::::::::::::::::::::
+
+:::::::::::::::: solution
+## Will any interventions be modelled?
+Finally, interventions such as vaccination may be of interest. A model may or may not have the capability to include the impact of different interventions on different time scales (continuous time or at discrete time points). We discuss interventions in detail in the tutorial [Modelling interventions](../episodes/modelling-interventions.md).
+
+:::::::::::::::::::::::::
+
+
+
+
+
+
+## Available models in `epidemics`
+
+The R package `epidemics` contains functions to run existing models.
+For details on the models that are available, see the package [vignettes](https://epiverse-trace.github.io/epidemics/articles). To learn how to run the models in R, read the documentation using `?epidemics::model_ebola_r`.
-## Challenge
::::::::::::::::::::::::::::::::::::: challenge
## What model?
-You have been asked to explore the variation in numbers of infected individuals in the early stages of an Ebola outbreak.
+You have been asked to explore the variation in numbers of infectious individuals in the early stages of an Ebola outbreak.
Which of the following models would be an appropriate choice for this task:
@@ -130,11 +157,23 @@ The model is capable of predicting an Ebola type outbreak, but as the model is d
#### `model_ebola_r()`
-A stochastic SEIHFR (Susceptible, Exposed, Infectious, Hospitalised, Funeral, Removed) model that was developed specifically for infection with Ebola.
+A stochastic SEIHFR (Susceptible, Exposed, Infectious, Hospitalised, Funeral, Removed) model that was developed specifically for infection with Ebola. The model has stochasticity in the passage times between states, which are modelled as Erlang distributions.
+
+The key parameters affecting the transition between states are:
+
++ $R_0$, the basic reproduction number,
++ $\rho^I$, the mean infectious period,
++ $\rho^E$, the mean preinfectious period,
++ $p_{hosp}$ the probability of being transferred to the hospitalised compartment.
+
+**Note: the functional relationship between the preinfectious period ($\rho^E$) and the transition rate between exposed and infectious ($\gamma^E$) is $\rho^E = k^E/\gamma^E$ where $k^E$ is the shape of the Erlang distribution. Similarly for the infectious period $\rho^I = k^I/\gamma^I$. See [here](https://epiverse-trace.github.io/epidemics/articles/ebola_model.html#details-discrete-time-ebola-virus-disease-model) for more detail on the stochastic model formulation. **
+The model has additional parameters describing the transmission risk in hospital and funeral settings:
++ $p_{ETU}$, the proportion of hospitalised cases contributing to the infection of susceptibles (ETU = Ebola virus treatment units),
++ $p_{funeral}$, the proportion of funerals at which the risk of transmission is the same as of infectious individuals in the community.
As this model is stochastic, it is the most appropriate choice to explore how variation in numbers of infected individuals in the early stages of an Ebola outbreak.
@@ -145,9 +184,177 @@ As this model is stochastic, it is the most appropriate choice to explore how va
::::::::::::::::::::::::::::::::::::::::::::::::
+## Challenge : Ebola outbreak analysis
+
+
+
+::::::::::::::::::::::::::::::::::::: challenge
+
+## Running the model
+
+You have been tasked to generate initial trajectories of an Ebola outbreak in Guinea. Using `model_ebola_r()` and the the information detailed below, complete the following tasks:
+
+1. Run the model once and plot the number of infectious individuals through time
+2. Run model 100 times and plot the mean, upper and lower 95% quantiles of the number of infectious individuals through time
+
++ Population size : 14 million
++ Initial number of exposed individuals : 10
++ Initial number of infectious individuals : 5
++ Time of simulation : 120 days
++ Parameter values :
+ + $R_0$ (`r0`) = 1.1,
+ + $p^I$ (`infectious_period`) = 12,
+ + $p^E$ (`preinfectious_period`) = 5,
+ + $k^E=k^I = 2$,
+ + $1-p_{hosp}$ (`prop_community`) = 0.9,
+ + $p_{ETU}$ (`etu_risk`) = 0.7,
+ + $p_{funeral}$ (`funeral_risk`) = 0.5
+
+::::::::::::::::: hint
+
+### Code for initial conidtions
+
+
+```r
+# set population size
+population_size <- 14e6
+
+E0 <- 10
+I0 <- 5
+# prepare initial conditions as proportions
+initial_conditions <- c(
+ S = population_size - (E0 + I0), E = E0, I = I0, H = 0, F = 0, R = 0
+) / population_size
+
+guinea_population <- population(
+ name = "Guinea",
+ contact_matrix = matrix(1), # note dummy value
+ demography_vector = population_size, # 14 million, no age groups
+ initial_conditions = matrix(
+ initial_conditions,
+ nrow = 1
+ )
+)
+```
+
+
+::::::::::::::::::::::
+
+
+::::::::::::::::: hint
+
+### HINT : Multiple model simulations
+
+Adapt the code from the [accounting for uncertainty](../episodes/simulating-transmission.md#accounting-for-uncertainty) section
+
+::::::::::::::::::::::
+
+::::::::::::::::: solution
+
+### SOLUTION
+
+1. Run the model once and plot the number of infectious individuals through time
+
+
+
+```r
+output <- model_ebola_r(
+ population = guinea_population,
+ transmissibility = 1.1 / 12,
+ infectiousness_rate = 2.0 / 5,
+ removal_rate = 2.0 / 12,
+ prop_community = 0.9,
+ etu_risk = 0.7,
+ funeral_risk = 0.5,
+ time_end = 100
+)
+
+ggplot(output[output$compartment == "infectious", ]) +
+ geom_line(
+ aes(time, value),
+ linewidth = 1.2
+ ) +
+ scale_y_continuous(
+ labels = scales::comma
+ ) +
+ labs(
+ x = "Simulation time (days)",
+ y = "Individuals"
+ ) +
+ theme_bw(
+ base_size = 15
+ )
+```
+
+
+
+2. Run model 100 times and plot the mean, upper and lower 95% quantiles of the number of infectious individuals through time
+
+We run the model 100 times with the *same* parameter values.
+
+
+```r
+output_samples <- Map(
+ x = seq(100),
+ f = function(x) {
+ output <- model_ebola_r(
+ population = guinea_population,
+ transmissibility = 1.1 / 12,
+ infectiousness_rate = 2.0 / 5,
+ removal_rate = 2.0 / 12,
+ prop_community = 0.9,
+ etu_risk = 0.7,
+ funeral_risk = 0.5,
+ time_end = 100
+ )
+ # add replicate number and return data
+ output$replicate <- x
+ output
+ }
+)
+
+output_samples <- bind_rows(output_samples) # requires the tidyverse package
+```
+
+```{.error}
+Error in bind_rows(output_samples): could not find function "bind_rows"
+```
+
+```r
+ggplot(output_samples[output_samples$compartment == "infectious", ], aes(time, value)) +
+ stat_summary(geom = "line", fun = mean) +
+ stat_summary(
+ geom = "ribbon",
+ fun.min = function(z) {
+ quantile(z, 0.025)
+ },
+ fun.max = function(z) {
+ quantile(z, 0.975)
+ },
+ alpha = 0.3
+ ) +
+ labs(
+ x = "Simulation time (days)",
+ y = "Individuals"
+ ) +
+ theme_bw(
+ base_size = 15
+ )
+```
+
+```{.error}
+Error in output_samples[output_samples$compartment == "infectious", ]: incorrect number of dimensions
+```
+
+:::::::::::::::::::::::::::
+
+
+::::::::::::::::::::::::::::::::::::::::::::::::
+
+
::::::::::::::::::::::::::::::::::::: keypoints
-- Existing models can be used for new questions
-- Check that a model has appropriate assumptions about transmission, outbreak potential, outcomes and interventions
+- Existing mathematical models should be selected according to the research question
+- It is important to check that a model has appropriate assumptions about transmission, outbreak potential, outcomes and interventions
::::::::::::::::::::::::::::::::::::::::::::::::
diff --git a/modelling-interventions.md b/modelling-interventions.md
index e53f0f36..e155d934 100644
--- a/modelling-interventions.md
+++ b/modelling-interventions.md
@@ -16,7 +16,7 @@ exercises: 30 # exercise time in minutes
::::::::::::::::::::::::::::::::::::: objectives
-- Learn how to implement pharmaceutical and non-pharmaceutical interventions
+- Add pharmaceutical and non-pharmaceutical interventions to an {epidemics} model
::::::::::::::::::::::::::::::::::::::::::::::::
@@ -25,7 +25,7 @@ exercises: 30 # exercise time in minutes
## Prerequisites
+ Complete tutorial [Simulating transmission](../episodes/simulating-transmission.md)
-This tutorial has the following concept dependencies:
+Learners should familiarise themselves with following concept dependencies before working through this tutorial:
**Outbreak response** : [Intervention types](https://www.cdc.gov/nonpharmaceutical-interventions/).
:::::::::::::::::::::::::::::::::
@@ -33,7 +33,9 @@ This tutorial has the following concept dependencies:
## Introduction
-Mathematical models can be used to generate predictions for the implementation of non-pharmaceutical and pharmaceutical interventions at different stages of an outbreak. In this tutorial, we will introduce how to include different interventions in models.
+Mathematical models can be used to generate trajectories of disease spread under the implementation of interventions at different stages of an outbreak. These predictions can be used to make decisions on what interventions could be implemented to slow down the spread of diseases.
+
+We can assume interventions in mathematical models reduce the values of relevant parameters e.g. reduce transmissibility while in place. Or it may be appropriate to assume individuals are classified into a new disease state, e.g. once vaccinated we assume individuals are no longer susceptible to infection and therefore move to a vaccinated state. In this tutorial, we will introduce how to include three different interventions in model of COVID-19 transmission.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: instructor
@@ -43,45 +45,52 @@ In this tutorial different types of intervention and how they can be modelled ar
## Non-pharmaceutical interventions
-Non-pharmaceutical interventions (NPIs) are measures put in place to reduce transmission that do not include taking medicine or vaccines. NPIs aim reduce contact between infectious and susceptible individuals. For example, washing hands, wearing masks and closures of school and workplaces.
-
-In mathematical modelling, we must make assumptions about how NPIs will affect transmission. This may include adding additional disease states or reducing the value of relevant parameters.
-
-#### Effect of school closures on COVID-19 spread
-
-
+[Non-pharmaceutical interventions](../learners/reference.md#NPIs) (NPIs) are measures put in place to reduce transmission that do not include the administration of drugs or vaccinations. NPIs aim reduce contact between infectious and susceptible individuals. For example, washing hands, wearing masks and closures of school and workplaces.
+We will investigate the effect of interventions on a COVID-19 outbreak using an SEIR model (`model_default_cpp()` in the R package `{epidemics}`). We will set $R_0 = 2.7$, latent period or preinfectious period $= 4$ and the infectious_period $= 5.5$ (parameters adapted from [Davies et al. (2020)](https://doi.org/10.1016/S2468-2667(20)30133-X)). We load a contact matrix with age bins 0-18, 18-65, 65 years and older using `{socialmixr}` and assume that one in every 1 million in each age group is infectious at the start of the epidemic.
-We want to investigate the effect of school closures on reducing the number of individuals infectious with COVID-19 through time. We assume that a school closure will reduce the frequency of contacts within and between different age groups.
-
-Using an SEIR model (`model_default_cpp()` in the R package `{epidemics}`) we set $R_0 = 2.7$, preinfectious period $= 4$ and the infectious_period $= 5.5$ (parameters adapted from [Davies et al. (2020)](https://doi.org/10.1016/S2468-2667(20)30133-X)). We load a contact matrix with age bins 0-18, 18-65, 65 years and older using `{socialmixr}` and assume that one in every 1 million in each age group is infectious at the start of the epidemic.
-
-We will assume that school closures will reduce the contacts between school aged children (aged 0-15) by 0.5, and will cause a small reduction (0.01) in the contacts between adults (aged 15 and over).
-
-::::::::::::::::::::::::::::::::::::: callout
-### Effect of interventions on contacts
-
-The contact matrix is scaled down by proportions for the period in which the intervention is in place. To explain the reduction, consider a contact matrix for two age groups with equal number of contacts:
+```r
+polymod <- socialmixr::polymod
+contact_data <- socialmixr::contact_matrix(
+ polymod,
+ countries = "United Kingdom",
+ age.limits = c(0, 15, 65),
+ symmetric = TRUE
+)
-```{.output}
- [,1] [,2]
-[1,] 1 1
-[2,] 1 1
-```
+# prepare contact matrix
+contact_matrix <- t(contact_data$matrix)
-If the reduction is 50% in group 1 and 10% in group 2, the contact matrix during the intervention will be:
+# prepare the demography vector
+demography_vector <- contact_data$demography$population
+names(demography_vector) <- rownames(contact_matrix)
+# initial conditions: one in every 1 million is infected
+initial_i <- 1e-6
+initial_conditions <- c(
+ S = 1 - initial_i, E = 0, I = initial_i, R = 0, V = 0
+)
-```{.output}
- [,1] [,2]
-[1,] 0.25 0.45
-[2,] 0.45 0.81
+# build for all age groups
+initial_conditions <- matrix(
+ rep(initial_conditions, dim(contact_matrix)[1]),
+ ncol = 5, byrow = T,
+)
+rownames(initial_conditions) <- rownames(contact_matrix)
+
+# prepare the population to model as affected by the epidemic
+uk_population <- population(
+ name = "UK",
+ contact_matrix = contact_matrix,
+ demography_vector = demography_vector,
+ initial_conditions = initial_conditions
+)
```
-The contacts within group 1 are reduced by 50% twice to accommodate for a 50% reduction in outgoing and incoming contacts ($1\times 0.5 \times 0.5 = 0.25$). Similarly, the contacts within group 2 are reduced by 10% twice. The contacts between group 1 and group 2 are reduced by 50% and then by 10% ($1 \times 0.5 \times 0.9= 0.45$).
+#### Effect of school closures on COVID-19 spread
-::::::::::::::::::::::::::::::::::::::::::::::::
+The first NPI we will consider is the effect of school closures on reducing the number of individuals infectious with COVID-19 through time. We assume that a school closure will reduce the frequency of contacts within and between different age groups. We assume that school closures will reduce the contacts between school aged children (aged 0-15) by 0.5, and will cause a small reduction (0.01) in the contacts between adults (aged 15 and over).
To include an intervention in our model we must create an `intervention` object. The inputs are the name of the intervention (`name`), the type of intervention (`contacts` or `rate`), the start time (`time_begin`), the end time (`time_end`) and the reduction (`reduction`). The values of the reduction matrix are specified in the same order as the age groups in the contact matrix.
@@ -107,41 +116,114 @@ close_schools <- intervention(
)
```
+::::::::::::::::::::::::::::::::::::: callout
+### Effect of interventions on contacts
+
+In `epidemics`, the contact matrix is scaled down by proportions for the period in which the intervention is in place. To understand how the reduction is calculated within the model functions, consider a contact matrix for two age groups with equal number of contacts:
+
+
+```{.output}
+ [,1] [,2]
+[1,] 1 1
+[2,] 1 1
+```
+
+If the reduction is 50% in group 1 and 10% in group 2, the contact matrix during the intervention will be:
+
-```{.error}
-Error in model_default_cpp(population = uk_population, infection = covid, : could not find function "model_default_cpp"
+```{.output}
+ [,1] [,2]
+[1,] 0.25 0.45
+[2,] 0.45 0.81
```
+The contacts within group 1 are reduced by 50% twice to accommodate for a 50% reduction in outgoing and incoming contacts ($1\times 0.5 \times 0.5 = 0.25$). Similarly, the contacts within group 2 are reduced by 10% twice. The contacts between group 1 and group 2 are reduced by 50% and then by 10% ($1 \times 0.5 \times 0.9= 0.45$).
+
+::::::::::::::::::::::::::::::::::::::::::::::::
-To run the model with an intervention we set ` intervention = list(contacts = close_schools)` as follows:
+Using transmissibility $= 2.7/5.5$ (remember that [transmissibility = $R_0$/ infectious period](../episodes/simulating-transmission.md#the-basic-reproduction-number-r_0)), infectiousness rate $1/= 4$ and the recovery rate $= 1/5.5$ we run the model with` intervention = list(contacts = close_schools)` as follows :
```r
output_school <- model_default_cpp(
population = uk_population,
- infection = covid,
+ transmissibility = 2.7 / 5.5,
+ infectiousness_rate = 1.0 / 4.0,
+ recovery_rate = 1.0 / 5.5,
intervention = list(contacts = close_schools),
time_end = 300, increment = 1.0
)
```
-```{.error}
-Error in model_default_cpp(population = uk_population, infection = covid, : could not find function "model_default_cpp"
-```
+To be able to see the effect of our intervention, we also run the model where there is no intervention, combine the two outputs into one data frame and then plot the output. Here we plot the total number of infectious individuals in all age groups using `ggplot2::stat_summary()`:
-We see that with the intervention (solid line) in place, the infection still spreads through the population, though the epidemic peak is smaller than the baseline with no intervention in place (dashed line).
+```r
+# run baseline simulation with no intervention
+output_baseline <- model_default_cpp(
+ population = uk_population,
+ transmissibility = 2.7 / 5.5,
+ infectiousness_rate = 1.0 / 4.0,
+ recovery_rate = 1.0 / 5.5,
+ time_end = 300, increment = 1.0
+)
-```{.error}
-Error in eval(expr, envir, enclos): object 'output_school' not found
+# create intervention_type column for plotting
+output_school$intervention_type <- "school closure"
+output_baseline$intervention_type <- "baseline"
+output <- rbind(output_school, output_baseline)
+
+ggplot(data = output[output$compartment == "infectious", ]) +
+ aes(
+ x = time,
+ y = value,
+ color = intervention_type,
+ linetype = intervention_type
+ ) +
+ stat_summary(
+ fun = "sum",
+ geom = "line",
+ linewidth = 1
+ ) +
+ scale_y_continuous(
+ labels = scales::comma
+ ) +
+ labs(
+ x = "Simulation time (days)",
+ y = "Individuals"
+ ) +
+ theme_bw(
+ base_size = 15
+ ) +
+ geom_vline(
+ xintercept = c(close_schools$time_begin, close_schools$time_end),
+ colour = "black",
+ linetype = "dashed",
+ linewidth = 0.2
+ ) +
+ annotate(
+ geom = "text",
+ label = "Schools closed",
+ colour = "black",
+ x = (close_schools$time_end - close_schools$time_begin) / 2 +
+ close_schools$time_begin,
+ y = 10,
+ angle = 0,
+ vjust = "outward"
+ )
```
+
+We see that with the intervention in place, the infection still spreads through the population, though the peak number of infectious individuals is smaller than the baseline with no intervention in place (solid line).
+
+
+
#### Effect of mask wearing on COVID-19 spread
We can model the effect of other NPIs as reducing the value of relevant parameters. For example, we want to investigate the effect of mask wearing on the number of individuals infectious with COVID-19 through time.
-We expect that mask wearing will reduce an individual's infectiousness. As we are using a population based model, we cannot make changes to individual behaviour and so assume that the transmission rate $\beta$ is reduced by a proportion due to mask wearing in the population. We specify this proportion, $\theta$ as product of the proportion wearing masks multiplied by the proportion reduction in transmissibility (adapted from [Li et al. 2020](https://doi.org/10.1371/journal.pone.0237691))
+We expect that mask wearing will reduce an individual's infectiousness. As we are using a population based model, we cannot make changes to individual behaviour and so assume that the transmissibility $\beta$ is reduced by a proportion due to mask wearing in the population. We specify this proportion, $\theta$ as product of the proportion wearing masks multiplied by the proportion reduction in transmissibility (adapted from [Li et al. 2020](https://doi.org/10.1371/journal.pone.0237691))
We create an intervention object with `type = rate` and `reduction = 0.161`. Using parameters adapted from [Li et al. 2020](https://doi.org/10.1371/journal.pone.0237691) we have proportion wearing masks = coverage $\times$ availability = $0.54 \times 0.525 = 0.2835$, proportion reduction in transmissibility = $0.575$. Therefore, $\theta = 0.2835 \times 0.575 = 0.163$. We assume that the mask wearing mandate starts at day 40 and is in place for 200 days.
@@ -162,30 +244,84 @@ To implement this intervention on the parameter $\beta$, we specify `interventio
```r
output_masks <- model_default_cpp(
population = uk_population,
- infection = covid,
- intervention = list(beta = mask_mandate),
+ transmissibility = 2.7 / 5.5,
+ infectiousness_rate = 1.0 / 4.0,
+ recovery_rate = 1.0 / 5.5,
+ intervention = list(transmissibility = mask_mandate),
time_end = 300, increment = 1.0
)
```
-```{.error}
-Error in model_default_cpp(population = uk_population, infection = covid, : could not find function "model_default_cpp"
+
+
+```r
+# create intervention_type column for plotting
+output_masks$intervention_type <- "mask mandate"
+output_baseline$intervention_type <- "baseline"
+output <- rbind(output_masks, output_baseline)
+
+ggplot(data = output[output$compartment == "infectious", ]) +
+ aes(
+ x = time,
+ y = value,
+ color = intervention_type,
+ linetype = intervention_type
+ ) +
+ stat_summary(
+ fun = "sum",
+ geom = "line",
+ linewidth = 1
+ ) +
+ scale_y_continuous(
+ labels = scales::comma
+ ) +
+ labs(
+ x = "Simulation time (days)",
+ y = "Individuals"
+ ) +
+ theme_bw(
+ base_size = 15
+ ) +
+ geom_vline(
+ xintercept = c(mask_mandate$time_begin, mask_mandate$time_end),
+ colour = "black",
+ linetype = "dashed",
+ linewidth = 0.2
+ ) +
+ annotate(
+ geom = "text",
+ label = "Mask mandate",
+ colour = "black",
+ x = (mask_mandate$time_end - mask_mandate$time_begin) / 2 +
+ mask_mandate$time_begin,
+ y = 10,
+ angle = 0,
+ vjust = "outward"
+ )
```
+
+::::::::::::::::::::::::::::::::::::: callout
+### Intervention types
+There are two intervention types for `model_default_cpp()`. Rate interventions on model parameters (`transmissibillity` $\beta$, `infectiousness_rate` $\sigma$ and `recovery_rate` $\gamma$) and contact matrix reductions `contacts`.
-```{.error}
-Error in eval(expr, envir, enclos): object 'output_masks' not found
-```
+To implement both contact and rate interventions in the same simulation they must be passed as a list e.g. `intervention = list(transmissibility = mask_mandate, contacts = close_schools)`. But if there are multiple interventions that target contact rates, these must be passed as one `contacts` input. See the [vignette on modelling overlapping interventions](https://epiverse-trace.github.io/epidemics/articles/multiple_interventions.html) for more detail.
+
+::::::::::::::::::::::::::::::::::::::::::::::::
## Pharmaceutical interventions
-Models can be used to investigate the effect of pharmaceutical interventions, such as vaccination. In this case, it is useful to add another disease state to track the number of vaccinated individuals through time. The diagram below shows an SEIRV model where susceptible individuals are vaccinated and then move to the $V$ class.
+Pharmaceutical interventions (PIs) are measures such as vaccination and mass treatment programs. In the previous section, we assumed that interventions reduced the value of parameter values while the intervention was in place. In the case of vaccination, we assume that after the intervention individuals are no longer susceptible and should be classified into a different disease state. Therefore, we specify the rate at which individuals are vaccinated and track the number of vaccinated individuals through time.
+
+The diagram below shows the SEIRV model implemented using `model_default_cpp()` where susceptible individuals are vaccinated and then move to the $V$ class.
+
+
The equations describing this model are as follows:
$$
@@ -197,10 +333,11 @@ $$
\frac{dV_i}{dt} & =\nu_{i,t} S_i\\
\end{aligned}
$$
-Individuals are vaccinated at an age group ($i$) specific time dependent ($t$) vaccination rate ($\nu$). The SEIR components of these equations are described in the tutorial Simulating transmission.
+Individuals are vaccinated at an age group ($i$) specific time dependent ($t$) vaccination rate ($\nu_{i,t}$). The SEIR components of these equations are described in the tutorial [simulating transmission](../episodes/simulating-transmission.md#simulating-disease-spread).
-To explore the effect of vaccination we need to create a vaccination object. As vaccination is age group specific, we must pass an age groups specific vaccination rate $\nu$ and age group specific start and end times of the vaccination program. Here we will assume all age groups are vaccinated at the same rate and that the vaccination program starts on day 40 and is in place for 150 days.
+To explore the effect of vaccination we need to create a vaccination object to pass as an input into `model_default_cpp()` that includes an age groups specific vaccination rate `nu` and age group specific start and end times of the vaccination program (`time_begin` and `time_end`).
+Here we will assume all age groups are vaccinated at the same rate 0.01 and that the vaccination program starts on day 40 and is in place for 150 days.
```r
@@ -219,31 +356,75 @@ We pass our vaccination object using `vaccination = vaccinate`:
```r
output_vaccinate <- model_default_cpp(
population = uk_population,
- infection = covid,
+ transmissibility = 2.7 / 5.5,
+ infectiousness_rate = 1.0 / 4.0,
+ recovery_rate = 1.0 / 5.5,
vaccination = vaccinate,
time_end = 300, increment = 1.0
)
```
-```{.error}
-Error in model_default_cpp(population = uk_population, infection = covid, : could not find function "model_default_cpp"
-```
-Here we see that the total number of infectious individuals when vaccination is in place is much lower compared to school closures and mask wearing interventions.
+::::::::::::::::::::::::::::::::::::: challenge
+
+## Compare interventions
+
+Plot the three interventions vaccination, school closure and mask mandate and the baseline simulation on one plot. Which intervention reduces the peak number of infectious individuals the most?
+
+:::::::::::::::::::::::: solution
-```{.error}
-Error in eval(expr, envir, enclos): object 'output_vaccinate' not found
+## Output
+
+
+```r
+# create intervention_type column for plotting
+output_vaccinate$intervention_type <- "vaccination"
+output <- rbind(output_school, output_masks, output_vaccinate, output_baseline)
+
+ggplot(data = output[output$compartment == "infectious", ]) +
+ aes(
+ x = time,
+ y = value,
+ color = intervention_type,
+ linetype = intervention_type
+ ) +
+ stat_summary(
+ fun = "sum",
+ geom = "line",
+ linewidth = 1
+ ) +
+ scale_y_continuous(
+ labels = scales::comma
+ ) +
+ labs(
+ x = "Simulation time (days)",
+ y = "Individuals"
+ ) +
+ theme_bw(
+ base_size = 15
+ )
```
+
+
+From the plot we see that the peak number of total number of infectious individuals when vaccination is in place is much lower compared to school closures and mask wearing interventions.
+
+:::::::::::::::::::::::::::::::::
+::::::::::::::::::::::::::::::::::::::::::::::::
+
+
+
## Summary
-Modelling interventions requires assumptions of how interventions affect model parameters such as contact matrices or parameter values. Next we want quantify the effect of an interventions. In the next tutorial, we will learn how to compare intervention scenarios against each other.
+Different types of intervention can be implemented using mathematical modelling. Modelling interventions requires assumptions of which model parameters are affected (e.g. contact matrices, transmissibility), by what magnitude and and what times in the simulation of an outbreak.
+The next step is to quantify the effect of an interventions. If you are interested in learning how to compare interventions, please complete the tutorial [Comparing public health outcomes of interventions](../episodes/compare-interventions.md).
::::::::::::::::::::::::::::::::::::: keypoints
-- Different types of intervention can be implemented using mathematical modelling
+- The effect of NPIs can be modelled as reducing contact rates between age groups or reducing the transmissibility of infection
+- Vaccination can be modelled by assuming individuals move to a different disease state $V$
::::::::::::::::::::::::::::::::::::::::::::::::
diff --git a/reference.md b/reference.md
index 5cec1299..14c8148d 100644
--- a/reference.md
+++ b/reference.md
@@ -9,7 +9,13 @@ title: 'Glossary of Terms: Epiverse-TRACE'
-
+## C
+
+[Contact matrix]{#contact}
+: The contact matrix is a square matrix consisting of rows/columns equal to the number age groups. Each element represents the frequency of contacts between age groups. If we believe that transmission of an infection is driven by contact, and that contact rates are very different for different age groups, then specifying a contact matrix allows us to account for age specific rates of transmission.
+
+[C++]{#cplusplus}
+: C++ is a high-level programming language that can be used within R to speed up sections of code. To learn more about C++ check out these [tutorials](https://cplusplus.com/doc/tutorial/) and learn more about the integration of C++ and R [here](https://www.rcpp.org/).
## D
@@ -30,11 +36,15 @@ title: 'Glossary of Terms: Epiverse-TRACE'
## I
[Incubation period]{#incubation}
-: The time between becoming infected and the onset of infectiousness, same as [latent period](#latent).
+: The time between becoming infected and the onset of symptoms. [More information on the incubation period](https://en.wikipedia.org/wiki/Latent_period_(epidemiology)#Incubation_period).
[Indirect transmission]{#indirect}
: Indirectly transmitted infections are passed on to humans via contact with vectors, animals or contaminated environment. Vector-borne infections, zoonoses and water-borne infections are modelled as indirectly transmitted.
+[Initial conditions]{#initial}
+: In [ODEs](#ordinary), the initial conditions are the values of the state variables at the start of the model simulation (at time 0). For example, if there is one infectious individual in a population of 1000 in an Susceptible-Infectious-Recovered model, the initial conditions would be $S(0) = 999$, $I(0) = 1$, $R(0) = 0$.
+
+
@@ -42,14 +52,21 @@ title: 'Glossary of Terms: Epiverse-TRACE'
## L
[Latent period]{#latent}
-: The time between becoming infected and the onset of infectiousness, same as [incubation period](#incubation).
+: The time between becoming infected and the onset of infectiousness. [More information on the latent period](https://en.wikipedia.org/wiki/Latent_period_(epidemiology)).
-
+## M
+[Model parameters (ODEs)]{#parsode}
+: The model parameters are used in [ordinary differential equation](#ordinary) models to describe the flow between disease states. For example, a transmission rate $\beta$ is a model parameter that can be used to describe the flow between susceptible and infectious states.
-
-
+## N
+[Non-pharmaceutical interventions]{#NPIs}
+: Non-pharmaceutical interventions (NPIs) are measures put in place to reduce transmission that do not include the administration of drugs or vaccinations. [More information on NPIs](https://www.gov.uk/government/publications/technical-report-on-the-covid-19-pandemic-in-the-uk/chapter-8-non-pharmaceutical-interventions).
+
+## O
+[Ordinary differential equations]{#ordinary}
+: Ordinary differential equations (ODEs) can be used to represent the rate of change of one variable (e.g. number of infected individuals) with respect to another (e.g. time). Check out this introduction to [ODEs](https://mathinsight.org/ordinary_differential_equation_introduction). ODEs are widely used in infectious disease modelling to model the flow of individuals between different disease states.
@@ -59,6 +76,9 @@ title: 'Glossary of Terms: Epiverse-TRACE'
## S
+[State variables]{#state}
+: The state variables in a model represented by [ordinary differential equations](#ordinary) are the disease states that individuals can be in e.g. if individuals can be susceptible, infectious or recovered the state variables are $S$, $I$ and $R$. There is an ordinary differential equation for each state variable.
+
[Stochastic model]{#stochastic}
: A model that includes some stochastic process resulting in variation in model simulations for the same initial conditions and parameter values. Examples include stochastic differential equations and branching process models. For more detail see [Allen (2017)](https://doi.org/10.1016/j.idm.2017.03.001).
@@ -73,6 +93,7 @@ title: 'Glossary of Terms: Epiverse-TRACE'
: Vector-borne transmission means an infection can be passed from a vector (e.g. mosquitoes) to humans. Examples of vector-borne diseases include malaria and dengue. The World Health Organization have a [Fact sheet about Vector-borne diseases](https://www.who.int/news-room/fact-sheets/detail/vector-borne-diseases) with key information and a list of them according to their vector.
+
diff --git a/simulating-transmission.md b/simulating-transmission.md
index 93a15e21..b077cb8b 100644
--- a/simulating-transmission.md
+++ b/simulating-transmission.md
@@ -9,18 +9,18 @@ exercises: 30 # exercise time in minutes
:::::::::::::::::::::::::::::::::::::: questions
-- How do I generate predictions of disease trajectories?
+- How do I simulate disease spread using a mathematical model?
- What inputs are needed for a model simulation?
+- How do I account for uncertainty?
::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::: objectives
-Using the R package `epidemics`, learn how to:
-
-- load an existing model structure,
-- load an existing social contact matrix,
-- run a model simulation.
+- Load an existing model structure from `{epidemics}` R package
+- Load an existing social contact matrix with `{socialmixr}`
+- Generate a disease spread model simulation with `{epidemics}`
+- Generate multiple model simulations and visualise uncertainty
::::::::::::::::::::::::::::::::::::::::::::::::
@@ -28,9 +28,9 @@ Using the R package `epidemics`, learn how to:
## Prerequisites
-This tutorial has the following concept dependencies:
+Learners should familiarise themselves with following concept dependencies before working through this tutorial:
-**Modelling** : [Components of infectious disease models](https://doi.org/10.1038/s41592-020-0856-2) e.g. state variables, parameters, initial conditions, and ordinary differential equations.
+**Mathematical Modelling** : [Introduction to infectious disease models](https://doi.org/10.1038/s41592-020-0856-2), [state variables](../learners/reference.md#state), [model parameters](../learners/reference.md#parsode), [initial conditions](../learners/reference.md#initial), [ordinary differential equations](../learners/reference.md#ordinary).
**Epidemic theory** : [Transmission](https://doi.org/10.1155/2011/267049), [Reproduction number](https://doi.org/10.3201/eid2501.171901).
:::::::::::::::::::::::::::::::::
@@ -39,18 +39,9 @@ This tutorial has the following concept dependencies:
## Introduction
-Mathematical models are useful tools for generating future trajectories of disease spread. Models can be used to evaluate the implementation of non-pharmaceutical and pharmaceutical interventions while accounting for factors such as age.
-
-In this tutorial, we will use the R package `{epidemics}` to generate trajectories of influenza spread. By the end of this tutorial, you will be able to generate the trajectory below showing the number of infectious individuals in different age categories over time.
-
-
-```{.error}
-Error in model_default_cpp(population = uk_population, infection = influenza, : could not find function "model_default_cpp"
-```
+Mathematical models are useful tools for generating future trajectories of disease spread. In this tutorial, we will use the R package `{epidemics}` to generate disease trajectories of an influenza strain with pandemic potential. By the end of this tutorial, you will be able to generate the trajectory below showing the number of infectious individuals in different age categories over time.
-```{.error}
-Error in eval(expr, envir, enclos): object 'output' not found
-```
+
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: instructor
@@ -59,49 +50,29 @@ By the end of this tutorial, learners should be able to replicate the above imag
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-The first step is to install the R packages `epidemics`.
-
-*Note : this tutorial is based on a development version of {epidemics}. This version of the package can be installed using `{pak}`:*
-
-
-```r
-if (!require("pak")) install.packages("pak")
-pak::pak("epiverse-trace/epidemics@96a7b1457")
-```
+## Simulating disease spread
-## Model structures
To generate predictions of infectious disease trajectories, we must first select a mathematical model to use.
-There is a library of models to choose from in `epidemics`. Models in `epidemics` are prefixed with `model` and suffixed by the name of infection (e.g. ebola) or a different identifier (e.g. default), and whether the model has a R or C++ code base. In this tutorial, we will use the default epidemic model, `model_default_cpp()` which is described in the next section.
+There is a library of models to choose from in `epidemics`. Models in `epidemics` are prefixed with `model` and suffixed by the name of infection (e.g. Ebola) or a different identifier (e.g. default), and whether the model has a R or [C++](../learners/reference.md#cplusplus) code base.
+In this tutorial, we will use the default model in `epidemics`, `model_default_cpp()` which is an age-structured SEIR model described by a system of [ordinary differential equations](../learners/reference.md#ordinary). For each age group $i$, individuals are classed as either susceptible $S$, infected but not yet infectious $E$, infectious $I$ or recovered $R$. The schematic below shows the processes which describe the flow of individuals between the disease states $S$, $E$, $I$ and $R$ and the key parameters for each process.
-::::::::::::::::::::::::::::::::::::: callout
-### Check model equations
-When using existing model structures always check the model assumptions. Ask questions such as:
-
-- How is transmission modelled? e.g. [direct](../learners/reference.md#direct) or [indirect](../learners/reference.md#indirect), [airborne](../learners/reference.md#airborne) or [vector-borne](../learners/reference.md#vectorborne)?
-- What interventions are modelled?
-- What state variables are there and how do they relate to assumptions about infection?
-
-There can be subtle differences in model structures for the same infection or outbreak type which can be missed without studying the equations.
-::::::::::::::::::::::::::::::::::::::::::::::::
-
+
-### An epidemic model for pandemic influenza
-We want to generate disease trajectories of an influenza strain with pandemic potential. We will use the default epidemic model in `epidemics`, an age-structured SEIR model described by a system of ordinary differential equations. For each age group $i$, individuals are classed as either susceptible $S$, infected but not yet infectious $E$, infectious $I$ or recovered $R$.
+::::::::::::::::::::::::::::::::::::: callout
+### Model parameters : rates
-
+In ODE models, model parameters are often (but not always) specified as rates. The rate at which an event occurs is the inverse of the average time until that event. For example, in the SEIR model, the recovery rate $\gamma$ is the inverse of the average infectious period.
+We can use knowledge of the natural history of the disease to inform our values of rates. If the average infectious period of an infection is 8 days, then the daily recovery rate is $\gamma = 1/8 = 0.125$.
-The model parameters and equations are as follows :
+::::::::::::::::::::::::::::::::::::::::::::::::
-- transmission rate $\beta$,
-- contact matrix $C$ containing the frequency of contacts between age groups (a square $i \times j$ matrix),
-- rate of transition from exposed to infectious $\alpha$ (preinfectious period=$1/\alpha$),
-- recovery rate $\gamma$ (infectious period = $1/\gamma$).
+For each disease state ($S$, $E$, $I$ and $R$) and age group ($i$), we have an ordinary differential equation describing the rate of change with respect to time.
$$
\begin{aligned}
@@ -111,15 +82,15 @@ $$
\frac{dR_i}{dt} &=\gamma I_i \\
\end{aligned}
$$
+Individuals in age group ($i$) move from the susceptible state ($S_i$) to the exposed state ($E_i$) via age group specific contact with the infectious individuals in their own and other age groups $\beta S_i \sum_j C_{i,j} I_j$. The contact matrix $C$ allows for heterogeneity in contacts between age groups. They then move to the infectious state at a rate $\alpha$ and recover at a rate $\gamma$. There is no loss of immunity (there are no flows out of the recovered state).
-The *contact matrix* is a square matrix consisting of rows/columns equal to the number age groups. Each element represents the frequency of contacts between age groups. If we believe that transmission of an infection is driven by contact, and that contact rates are very different for different age groups, then specifying a contact matrix allows us to account for age specific rates of transmission.
+The model parameters definitions are :
-From the model structure we see that :
-
-- the contact matrix $C$ allows for heterogeneity in contacts between age groups,
-- there is no loss of immunity (there are no flows out of the recovered state).
+- transmission rate or transmissibility $\beta$,
+- [contact matrix](../learners/reference.md#contact) $C$ containing the frequency of contacts between age groups (a square $i \times j$ matrix),
+- infectiousness rate $\alpha$ (preinfectious period ([latent period](../learners/reference.md#latent)) =$1/\alpha$),
+- recovery rate $\gamma$ (infectious period = $1/\gamma$).
-This model also has the functionality to include vaccination and tracks the number of vaccinated individuals through time. We will cover the use of interventions in future tutorials.
::::::::::::::::::::::::::::::::::::: callout
### Exposed, infected, infectious
@@ -133,55 +104,14 @@ We will use the following definitions for our state variables:
::::::::::::::::::::::::::::::::::::::::::::::::
-To generate trajectories using our model, we need the following :
-
-1. parameter values,
-2. contact matrix,
-3. demographic structure,
-4. initial conditions.
-
-## Model parameters
-
-To run our model we need to specify the model parameters:
-
-- transmission rate $\beta$,
-- rate of transition from exposed to infectious $\alpha$ (preinfectious period=$1/\alpha$),
-- recovery rate $\gamma$ (infectious period=$1/\gamma$).
-
-We will learn how to specify the contact matrix $C$ in the next section.
+To generate trajectories using our model, we must prepare the following inputs :
-We will simulate a strain of influenza with pandemic potential with $R_0=1.5$, a preinfectious period of 3 days and infectious period of 7 days.
+1. Contact matrix
+2. Initial conditions
+3. Population structure
+4. Model parameters
-In `epidemics`, we use the function `infection()` to create an infection object containing the values of, $R_0$, the preinfectious period ($1/\alpha$) and the infectious period ($1/\gamma$) as follows.
-
-
-```r
-influenza <- infection(
- name = "influenza",
- r0 = 1.5,
- preinfectious_period = 3,
- infectious_period = 7
-)
-```
-
-::::::::::::::::::::::::::::::::::::: callout
-### The basic reproduction number $R_0$
-The basic reproduction number, $R_0$, for the SEIR model is:
-
-$$ R_0 = \frac{\beta}{\gamma}.$$
-
-Therefore, we can rewrite the transmission rate, $\beta$, as:
-
-$$ \beta = R_0 \gamma.$$
-
-
-::::::::::::::::::::::::::::::::::::::::::::::::
-
-
-
-
-
-### Contact matrix
+### 1. Contact matrix
Contact matrices can be estimated from surveys or contact data, or synthetic ones can be used. We will use the R package `{socialmixr}` to load in a contact matrix estimated from POLYMOD survey data [(Mossong et al. 2008)](https://doi.org/10.1371/journal.pmed.0050074).
@@ -226,7 +156,7 @@ contact.age.group [,1] [,2] [,3]
:::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::
-The result is a square matrix with rows and columns for each age group. Contact matrices can be loaded from other sources, but they must be in the correct format to be used in `epidemics`.
+The result is a square matrix with rows and columns for each age group. Contact matrices can be loaded from other sources, but they must be formatted as a matrix to be used in `epidemics`.
::::::::::::::::::::::::::::::::::::: callout
### Why would a contact matrix be non-symmetric?
@@ -235,11 +165,7 @@ One of the arguments of the function `contact_matrix()` is `symmetric=TRUE`. Thi
::::::::::::::::::::::::::::::::::::::::::::::::
-## Generating trajectories
-
-We have prepared our parameter values, contact matrix and demography vector. Now we must set the initial conditions, prepare the population and run the model.
-
-### Initial conditions
+### 2. Initial conditions
The initial conditions are the proportion of individuals in each disease state $S$, $E$, $I$ and $R$ for each age group at time 0. In this example, we have three age groups age between 0 and 20 years, age between 20 and 40 years and over. Let's assume that in the youngest age category, one in a million individuals are infectious, and the remaining age categories are infection free.
@@ -266,12 +192,14 @@ We combine the three initial conditions vectors into one matrix,
```r
-# build for all age groups
+# combine the initial conditions
initial_conditions <- rbind(
- initial_conditions_inf,
- initial_conditions_free,
- initial_conditions_free
+ initial_conditions_inf, # age group 1
+ initial_conditions_free, # age group 2
+ initial_conditions_free # age group 3
)
+
+# use contact matrix to assign age group names
rownames(initial_conditions) <- rownames(contact_matrix)
initial_conditions
```
@@ -283,15 +211,11 @@ initial_conditions
40+ 1.000000 0 0e+00 0 0
```
-### Running the model
-To run the model we need the following inputs:
-- an infection object,
-- a population object,
-- an optional number of time steps.
-We have already created our infection object `influenza`. The population object requires a vector containing the demographic structure of the population. The demographic vector must be a named vector containing the number of individuals in each age group of our given population. In this example, we can extract the demographic information from the `contact_data` object that we obtained using the `socialmixr` package.
+### 3. Population structure
+The population object requires a vector containing the demographic structure of the population. The demographic vector must be a named vector containing the number of individuals in each age group of our given population. In this example, we can extract the demographic information from the `contact_data` object that we obtained using the `socialmixr` package.
```r
@@ -317,73 +241,142 @@ uk_population <- population(
)
```
-No we are ready to run our model. We will specify `time_end=600` to run the model for 600 days.
+
+### 4. Model parameters
+
+To run our model we need to specify the model parameters:
+
+- transmissibility $\beta$,
+- infectiousness rate $\alpha$ (preinfectious period=$1/\alpha$),
+- recovery rate $\gamma$ (infectious period=$1/\gamma$).
+
+In `epidemics`, we specify the model inputs as :
+
+- `transmissibility` = $R_0 \gamma$,
+- `infectiousness_rate` = $\alpha$,
+- `recovery_rate` = $\gamma$,
+
+We will simulate a strain of influenza with pandemic potential with $R_0=1.46$, a preinfectious period of 3 days and infectious period of 7 days. Therefore our inputs will be:
+
+- `transmissibility = 1.46 / 7.0`,
+- `infectiousness_rate = 1.0 / 3.0`,
+- `recovery_rate = 1.0 / 7.0`.
+
+::::::::::::::::::::::::::::::::::::: callout
+### The basic reproduction number $R_0$
+The basic reproduction number, $R_0$, for the SEIR model is:
+
+$$ R_0 = \frac{\beta}{\gamma}.$$
+
+Therefore, we can rewrite transmissibility $\beta$, as:
+
+$$ \beta = R_0 \gamma.$$
+
+
+::::::::::::::::::::::::::::::::::::::::::::::::
+
+
+
+
+
+## Running the model
+
+::::::::::::::::::::::::::::::::::::: callout
+### Running (solving) the model
+
+For models that are described by ODEs, running the model actually means to solve the system of ODEs. ODEs describe the rate of change in the disease states with respect to time, to find the number of individuals in each of these states, we use numerical integration methods to solve the equations.
+
+In `epidemics`, the [ODE solver](https://www.boost.org/doc/libs/1_82_0/libs/numeric/odeint/doc/html/index.htm) uses the [Runge-Kutta method](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods).
+::::::::::::::::::::::::::::::::::::::::::::::::
+
+Now we are ready to run our model. To install the `epidemics` package :
```r
-output <- model_default_cpp(
- population = uk_population,
- infection = influenza,
- time_end = 600
-)
+if (!require("pak")) install.packages("pak")
+pak::pak("epiverse-trace/epidemics")
```
-```{.error}
-Error in model_default_cpp(population = uk_population, infection = influenza, : could not find function "model_default_cpp"
-```
+Then we specify `time_end=600` to run the model for 600 days.
```r
+output <- model_default_cpp(
+ population = uk_population,
+ transmissibility = 1.46 / 7.0,
+ infectiousness_rate = 1.0 / 3.0,
+ recovery_rate = 1.0 / 7.0,
+ time_end = 600, increment = 1.0
+)
head(output)
```
-```{.error}
-Error in eval(expr, envir, enclos): object 'output' not found
+```{.output}
+ time demography_group compartment value
+1 0 [0,20) susceptible 14799275
+2 0 [20,40) susceptible 16526302
+3 0 40+ susceptible 28961159
+4 0 [0,20) exposed 0
+5 0 [20,40) exposed 0
+6 0 40+ exposed 0
```
+
+*Note : This model also has the functionality to include vaccination and tracks the number of vaccinated individuals through time. Even though we have not specified any vaccination, there is still a vaccinated compartment in the output (containing no individuals). We will cover the use of vaccination in future tutorials.*
+
Our model output consists of the number of individuals in each compartment in each age group through time. We can visualise the infectious individuals only (those in the $I$ class) through time.
```r
-ggplot(output[compartment == "infectious", ]) +
+filter(output_plot, compartment %in% c("exposed", "infectious")) %>%
+ ggplot(
+ aes(
+ x = time,
+ y = value,
+ col = demography_group,
+ linetype = compartment
+ )
+ ) +
geom_line(
- aes(time, value, colour = demography_group),
- linewidth = 1
+ linewidth = 1.2
+ ) +
+ scale_y_continuous(
+ labels = scales::comma
) +
scale_colour_brewer(
palette = "Dark2",
- labels = rownames(contact_matrix),
name = "Age group"
) +
- scale_y_continuous(
- labels = scales::comma,
- name = "Infectious indivduals"
+ expand_limits(
+ y = c(0, 500e3)
) +
- labs(
- x = "Model time (days)"
+ coord_cartesian(
+ expand = FALSE
+ ) +
+ theme_bw(
+ base_size = 15
) +
- theme_classic() +
theme(
legend.position = "top"
) +
- theme_grey(
- base_size = 15
+ labs(
+ x = "Simulation time (days)",
+ linetype = "Compartment",
+ y = "Individuals"
)
```
-```{.error}
-Error in eval(expr, envir, enclos): object 'output' not found
-```
+
::::::::::::::::::::::::::::::::::::: callout
### Time increments
-Note that there is a default argument of `increment = 1`. This relates to the time step of the ODE solver. When the parameters and maximum number of time steps is days, the default increment is one day.
+Note that there is a default argument of `increment = 1`. This relates to the time step of the ODE solver. When the parameters are specified on a daily time-scale and maximum number of time steps (`time_end`) is days, the default time step of the ODE solver one day.
The choice of increment will depend on the time scale of the parameters, and the rate at which events can occur. In general, the increment should smaller than the fastest event. For example, if parameters are on a monthly time scale, but some events will occur within a month, then the increment should be less than one month.
::::::::::::::::::::::::::::::::::::::::::::::::
-### Accounting for uncertainty
+## Accounting for uncertainty
As the epidemic model is [deterministic](../learners/reference.md#deterministic), we have one trajectory for our given parameter values. In practice, we have uncertainty in the value of our parameters. To account for this, we must run our model for different parameter combinations.
@@ -401,82 +394,69 @@ R0_vec <- rnorm(100, 1.5, 0.05)
```r
output_samples <- Map(
- R0_vec,
+ R0_vec,
seq_along(R0_vec),
f = function(x, i) {
- # create infection object for R0 value
- influenza <- infection(
- name = "influenza",
- r0 = x,
- preinfectious_period = 3,
- infectious_period = 7
- )
-
# run an epidemic model using `epidemic()`
output <- model_default_cpp(
population = uk_population,
- infection = influenza,
+ transmissibility = x / 7.0,
+ infectiousness_rate = 1.0 / 3.0,
+ recovery_rate = 1.0 / 7.0,
time_end = 600, increment = 1.0
)
- # extract infectious individuals
- output <- output[compartment == "infectious"]
-
- # assign scenario number
- output[, c("scenario", "R") := list(i, x)]
-
+ # add replicate number and return data
+ output$replicate <- x
output
}
)
-```
-
-```{.error}
-Error in model_default_cpp(population = uk_population, infection = influenza, : could not find function "model_default_cpp"
-```
-```r
# combine to prepare for plotting
output_samples <- bind_rows(output_samples)
```
-```{.error}
-Error in eval(expr, envir, enclos): object 'output_samples' not found
-```
-
3. Calculate the mean and 95% quantiles of number of infectious individuals across each model simulation and visualise output
```r
-ggplot(output_samples ,aes(time, value)) +
+ggplot(output_samples[output_samples$compartment == "infectious", ], aes(time, value)) +
stat_summary(geom = "line", fun = mean) +
- stat_summary(geom = "ribbon",
- fun.min = function(z) { quantile(z, 0.025) },
- fun.max = function(z) { quantile(z, 0.975) },
- alpha = 0.3) +
+ stat_summary(
+ geom = "ribbon",
+ fun.min = function(z) {
+ quantile(z, 0.025)
+ },
+ fun.max = function(z) {
+ quantile(z, 0.975)
+ },
+ alpha = 0.3
+ ) +
facet_grid(
cols = vars(demography_group)
) +
- theme_grey(
+ labs(
+ x = "Simulation time (days)",
+ y = "Individuals"
+ ) +
+ theme_bw(
base_size = 15
)
```
-```{.error}
-Error in eval(expr, envir, enclos): object 'output_samples' not found
-```
+
-Deciding which parameters to include uncertainty in depends on a few factors: how well informed a parameter value is e.g. consistency of estimates from the literature; how sensitive model outputs are to parameter value changes; and the purpose of the modelling task.
+Deciding which parameters to include uncertainty in depends on a few factors: how well informed a parameter value is e.g. consistency of estimates from the literature; how sensitive model outputs are to parameter value changes; and the purpose of the modelling task. See [McCabe et al. 2021](https://doi.org/10.1016%2Fj.epidem.2021.100520) to learn about different types of uncertainty in infectious disease modelling.
## Summary
-In this tutorial, we have learnt how to generate disease trajectories using a mathematical model. Once a model has been chosen, the parameters and other inputs must be specified in the correct way to perform model simulations. In the next tutorial, we will consider how to choose the right model for different tasks.
+In this tutorial, we have learnt how to simulate disease spread using a mathematical model. Once a model has been chosen, the parameters and other inputs must be specified in the correct way to perform model simulations. In the next tutorial, we will consider how to choose the right model for different tasks.
::::::::::::::::::::::::::::::::::::: keypoints
- Disease trajectories can be generated using the R package `epidemics`
-- Contact matrices can be estimated from different sources
-- Include uncertainty in model trajectories
+- Uncertainty should be included in model trajectories using a range of model parameter values
::::::::::::::::::::::::::::::::::::::::::::::::