diff --git a/episodes/contact-matrices.Rmd b/episodes/contact-matrices.Rmd index f0e11878..f957078a 100644 --- a/episodes/contact-matrices.Rmd +++ b/episodes/contact-matrices.Rmd @@ -64,6 +64,7 @@ $$ 1 & 3 \end{bmatrix} $$ + In this example, we would use this to represent that children meet, on average, 2 other children and 2 adult per day (first row), and adults meet, on average, 1 child and 3 other adults per day (second row). We can use this kind of information to account for the role heterogeneity in contact plays in infectious disease transmission. ::::::::::::::::::::::::::::::::::::: callout @@ -267,6 +268,7 @@ $$ \frac{dR}{dt} &=\gamma I \\ \end{aligned} $$ + To add age structure to our model, we need to add additional equations for the infection states $S$, $I$ and $R$ for each age group $i$. If we want to assume that there is heterogeneity in contacts between age groups then we must adapt the transmission term $\beta SI$ to include the contact matrix $C$ as follows : $$ \beta S_i \sum_j C_{i,j} I_j/N_j. $$ diff --git a/episodes/modelling-interventions.Rmd b/episodes/modelling-interventions.Rmd index fb1e9007..a51fd37a 100644 --- a/episodes/modelling-interventions.Rmd +++ b/episodes/modelling-interventions.Rmd @@ -28,8 +28,24 @@ library(epidemics) Learners should also familiarise themselves with following concept dependencies before working through this tutorial: **Outbreak response** : [Intervention types](https://www.cdc.gov/nonpharmaceutical-interventions/). + +**R packages installed**: `{epidemics}`, `{socialmixr}`, `{scales}`, `{tidyverse}`. + ::::::::::::::::::::::::::::::::: +:::::::::: spoiler + +Install packages if their are not already installed + +```r +if (!base::require("pak")) install.packages("pak") +pak::pak(c("epiverse-trace/epidemics", "socialmixr", "scales", "tidyverse")) +``` + +If you have any error message, +go to the [main setup page](../learners/setup.md#software-setup). + +:::::::::: ## Introduction @@ -52,7 +68,17 @@ In this tutorial different types of intervention and how they can be modelled ar :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -## A baseline model +:::::::::::::::::::::: instructor + +Share with learners the code for the baseline model. + +It has **different** disease parameters than previous episode. + +Then start with the livecoding directly with interventions. + +:::::::::::::::::::::: + +## Baseline model We will investigate the effect of interventions on a COVID-19 outbreak using an SEIR model (`model_default()` in the R package `{epidemics}`). To be able to see the effect of our intervention, we will run a baseline variant of the model, i.e, without intervention. @@ -127,6 +153,18 @@ output_baseline <- epidemics::model_default( ) ``` +:::::::::::::::::::::: instructor + +Make a pause. + +Use slides to introduce the topics of: + +- Non pharmaceutical interventions. + +Then continue with the livecoding. + +:::::::::::::::::::::: + ## Non-pharmaceutical interventions [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 at reducing contacts between infectious and susceptible individuals by closure of schools and workplaces, and other measures to prevent the spread of the disease, for example, washing hands and wearing masks. @@ -141,7 +179,7 @@ To include an intervention in our model we must create an `intervention` object. rownames(cm_matrix) ``` -Therefore, we specify ` reduction = matrix(c(0.5, 0.01, 0.01))`. We assume that the school closures start on day 50 and continue to be in place for a further 100 days. Therefore our intervention object is: +Therefore, we specify `reduction = matrix(c(0.5, 0.01, 0.01))`. We assume that the school closures start on day 50 and continue to be in place for a further 100 days. Therefore our intervention object is: ```{r intervention} close_schools <- epidemics::intervention( @@ -160,18 +198,18 @@ In `{epidemics}`, the contact matrix is scaled down by proportions for the perio ```{r echo = FALSE} reduction <- matrix(c(0.5, 0.1)) -cm_matrix_example <- matrix(c(1, 1, 1, 1), nrow = 2) -cm_matrix_example +contact_matrix_example <- matrix(c(1, 1, 1, 1), nrow = 2) +contact_matrix_example ``` If the reduction is 50% in group 1 and 10% in group 2, the contact matrix during the intervention will be: ```{r echo = FALSE} -cm_matrix_example[1, ] <- cm_matrix_example[1, ] * (1 - reduction[1]) -cm_matrix_example[, 1] <- cm_matrix_example[, 1] * (1 - reduction[1]) -cm_matrix_example[2, ] <- cm_matrix_example[2, ] * (1 - reduction[2]) -cm_matrix_example[, 2] <- cm_matrix_example[, 2] * (1 - reduction[2]) -cm_matrix_example +contact_matrix_example[1, ] <- contact_matrix_example[1, ] * (1 - reduction[1]) +contact_matrix_example[, 1] <- contact_matrix_example[, 1] * (1 - reduction[1]) +contact_matrix_example[2, ] <- contact_matrix_example[2, ] * (1 - reduction[2]) +contact_matrix_example[, 2] <- contact_matrix_example[, 2] * (1 - reduction[2]) +contact_matrix_example ``` 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$). @@ -245,7 +283,7 @@ We can also model the effect of other NPIs by reducing the value of the relevant We expect that mask wearing will reduce an individual's infectiousness, based on multiple studies showing the effectiveness of masks in reducing transmission. As we are using a population-based model, we cannot make changes to individual behavior 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 transmission rate (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$ and proportion reduction in transmission rate = $0.575$. Therefore, $\theta = 0.2835 \times 0.575 = 0.163$. We assume that the mask wearing mandate starts at day 40 and continue to be in place for 200 days. +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$ and proportion reduction in transmission rate = $0.575$. Therefore, $\theta = 0.2835 \times 0.575 = 0.163$. We assume that the mask wearing mandate starts at day 40 and continue to be in place for 200 days. ```{r masks} mask_mandate <- epidemics::intervention( @@ -321,6 +359,17 @@ To implement both contact and rate interventions in the same simulation they mus :::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::: instructor + +Make a pause. + +Use slides to introduce the topics of: + +- Pharmaceutical interventions. + +Then continue with the livecoding. + +:::::::::::::::::::::: ## Pharmaceutical interventions @@ -373,6 +422,7 @@ $$ \frac{dV_i}{dt} & =\nu_{i,t} S_i\\ \end{aligned} $$ + Individuals in age group ($i$) at specific time dependent ($t$) are vaccinated at rate ($\nu_{i,t}$). The other 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 to pass as an input into `model_default()` that includes age groups specific vaccination rate `nu` and age groups specific start and end times of the vaccination program (`time_begin` and `time_end`). @@ -501,6 +551,15 @@ To get an age-stratified plot, keep the default `by_group = TRUE` and then add ` ::::::::::::::::::::: +:::::::::::::::::::::: instructor + +Stop the livecoding. + +Suggest learners to read the next episode. + +Return to slides. + +:::::::::::::::::::::: ## Summary diff --git a/episodes/simulating-transmission.Rmd b/episodes/simulating-transmission.Rmd index 2f65a5cb..34be95b4 100644 --- a/episodes/simulating-transmission.Rmd +++ b/episodes/simulating-transmission.Rmd @@ -37,7 +37,7 @@ Learners should familiarise themselves with following concept dependencies befor **Epidemic theory** : [Transmission](https://doi.org/10.1155/2011/267049), [Reproduction number](https://doi.org/10.3201/eid2501.171901). -**R packages installed**: `{epidemics}`, `{socialmixr}`, `{tidyverse}`. +**R packages installed**: `{epidemics}`, `{socialmixr}`, `{scales}`, `{tidyverse}`. ::::::::::::::::::::::::::::::::: diff --git a/learners/setup.md b/learners/setup.md index 57389bf6..3af54bfe 100644 --- a/learners/setup.md +++ b/learners/setup.md @@ -96,7 +96,71 @@ While this may sound scary, it is **far more common** to run into issues due to ::::::::::::::::::::::::::::: -### 2. Install the required R packages +### 2. Check and Install Build Tools + +Some packages require a complementary set of tools to build them. +Open RStudio and **copy and paste** the following code chunk into the +[console window](https://docs.posit.co/ide/user/ide/guide/code/console.html), +then press the Enter (Windows and Linux) or Return (MacOS) to execute the command: + +```r +if(!require("pkgbuild")) install.packages("pkgbuild") +pkgbuild::check_build_tools(debug = TRUE) +``` + +We expect a message like the one below: + +```output +Your system is ready to build packages! +``` + +If the build tools are not available, this will trigger an automated install. + +1. Run the command in the console. +2. Don’t interrupt it—wait until R prints the confirmation message. +3. Once that’s done, restart your R session (or just restart RStudio) to ensure the changes take effect. + +If the automatic installation **does not** work, you can manually install them according to your operating system. + +::::::::::::::::::::::::::::: tab + +### Windows + +Windows users will need a working installation of `Rtools` in order to build the package from source. +`Rtools` is not an R package, but a software you need to download and install. +We suggest you to follow: + +- **Install `Rtools`**. Download the `Rtools` installer from . Install with default selections. +- Close and reopen RStudio so it can recognize the new installation. + +### Mac + +Mac users require two additional steps as detailed in this [guide to Configuring C Toolchain for Mac](https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Mac): + +- Install and use [`macrtools`](https://mac.thecoatlessprofessor.com/macrtools/) to setup the C++ toolchain +- Enable some compiler optimizations. + +### Linux + +Linux users require specific details per distribution. Find them in this [guide to Configuring C Toolchain for Linux](https://github.com/stan-dev/rstan/wiki/Configuring-C-Toolchain-for-Linux). + +::::::::::::::::::::::::::::: + +::::::::::::: callout + +### Environment Check + +This step requires administrator privileges to install software. + +If you do not have admin rights in your current environment: + +- Try running the tutorial on your **personal machine** where you have full access. +- Use a **preconfigured development environment** (e.g. [Posit Cloud](https://posit.cloud/)). +- Ask your **system administrator** to install the required software for you. + +::::::::::::: + +### 3. Install the required R packages