Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions episodes/contact-matrices.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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. $$
Expand Down
79 changes: 69 additions & 10 deletions episodes/modelling-interventions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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$).
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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`).
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion episodes/simulating-transmission.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}`.

:::::::::::::::::::::::::::::::::

Expand Down
87 changes: 77 additions & 10 deletions learners/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Our tutorials are built around an outbreak analysis pipeline split into three stages: **Early tasks**, **Middle tasks** and **Late tasks**. The outputs of tasks completed in earlier stages commonly feed into the tasks required for later ones.


![An overview of the tutorial topics](https://epiverse-trace.github.io/task_pipeline-minimal.svg)

Check warning on line 16 in learners/setup.md

View workflow job for this annotation

GitHub Actions / Build markdown source files if valid

[image missing alt-text]: https://epiverse-trace.github.io/task_pipeline-minimal.svg

Each task has its tutorial website and each tutorial website consists of a set of episodes covering different topics.

Expand All @@ -36,7 +36,7 @@

Our strategy is to gradually incorporate specialised **R packages** into a traditional analysis pipeline. These packages should fill the gaps in these epidemiology-specific tasks in response to outbreaks.

![In **R**, the fundamental unit of shareable code is the **package**. A package bundles together code, data, documentation, and tests and is easy to share with others ([Wickham and Bryan, 2023](https://r-pkgs.org/introduction.html))](episodes/fig/pkgs-hexlogos-2.png)

Check warning on line 39 in learners/setup.md

View workflow job for this annotation

GitHub Actions / Build markdown source files if valid

[image missing alt-text]: episodes/fig/pkgs-hexlogos-2.png

:::::::::::::::::::::::::::: prereq

Expand Down Expand Up @@ -96,7 +96,71 @@

:::::::::::::::::::::::::::::

### 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 <kbd>Enter</kbd> (Windows and Linux) or <kbd>Return</kbd> (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 <https://cran.r-project.org/bin/windows/Rtools/>. 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

<!--
During the tutorial, we will need a number of R packages. Packages contain useful R code written by other people. We will use packages from the [Epiverse-TRACE](https://epiverse-trace.github.io/).
Expand Down Expand Up @@ -128,12 +192,14 @@
If you get an error message when installing {epidemics}, try this alternative code:

```r
if(!require("devtools")) install.packages("devtools")

devtools::install_github("epiverse-trace/epidemics")
install.packages("epidemics", repos = c("https://epiverse-trace.r-universe.dev", "https://cloud.r-project.org"))
```

**What to do if an Error persist?**
:::::::::::::::::::::::::::::

::::::::::::::::::::::::::: spoiler

### Do you need a GitHub Personal access token (PAT)?

If the error message keyword include an string like `Personal access token (PAT)`, you may need to [set up your GitHub token](https://epiverse-trace.github.io/git-rstudio-basics/02-setup.html#set-up-your-github-token).

Expand Down Expand Up @@ -162,20 +228,21 @@
usethis::git_sitrep()
```

Try again installing {epidemics}:
Try again installing {epiparameter}:

```r
if(!require("devtools")) install.packages("devtools")

devtools::install_github("epiverse-trace/epidemics")
if(!require("remotes")) install.packages("remotes")
remotes::install_github("epiverse-trace/epiparameter")
```

If the error persist, [contact us](#your-questions)!

:::::::::::::::::::::::::::::
:::::::::::::::::::::::::::

You should update **all of the packages** required for the tutorial, even if you installed them relatively recently. New versions bring improvements and important bug fixes.

### 4. Verify the installation

When the installation has finished, you can try to load the packages by pasting the following code into the console:

```r
Expand Down
Loading