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
4 changes: 2 additions & 2 deletions episodes/compare-interventions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contacts_byage <- socialmixr::contact_matrix(
)

# prepare contact matrix
contacts_byage_matrix <- t(contacts_byage$matrix)
contacts_byage_matrix <- contacts_byage$matrix

# prepare the demography vector
demography_vector <- contacts_byage$demography$population
Expand Down Expand Up @@ -368,7 +368,7 @@ contacts_byage_uk <- socialmixr::contact_matrix(
survey_pop = uk_pop
)
# prepare contact matrix
contacts_byage_matrix_uk <- t(contacts_byage_uk$matrix)
contacts_byage_matrix_uk <- contacts_byage_uk$matrix

# extract demography vector
demography_vector <- contacts_byage_uk$demography$population
Expand Down
8 changes: 5 additions & 3 deletions episodes/contact-matrices.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,15 @@ Recall from **A Note on Notation** above that entry $C[i,j]$ of the matrix from

To convert this into a contact *rate*, we read the matrix the other way round: "susceptibles in group $i$ ($S_i$), *contacted by* group $j$". That's the same contact seen from the susceptible side rather than the reporting side — group $j$ is doing the contacting, group $i$ is being exposed. In other words, the entry we need at position $(i,j)$ is the reported contact at `socialmixr`'s position $(j,i)$: the two conventions are transposes of each other.

To go from one convention to the other, we transpose the matrix:
Going from one convention to the other means transposing the matrix. Some packages expect you to do this yourself; `{epidemics}` does it for you.

From version 0.5.0, the `{epidemics}` model functions transpose the contact matrix internally, so a matrix from `socialmixr::contact_matrix()` should be passed to `epidemics::population()` exactly as it is returned, with no call to `t()`:

```r
contacts_byage_matrix <- t(contacts_byage$matrix)
contacts_byage_matrix <- contacts_byage$matrix
```

This is the matrix used as $C_{i,j}$ in $\beta S_i \sum_j C_{i,j} I_j/N_j$ below.
Internally, it is the transposed matrix that is used as $C_{i,j}$ in $\beta S_i \sum_j C_{i,j} I_j/N_j$ below.

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

Expand Down
2 changes: 1 addition & 1 deletion episodes/disease-burden.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ contacts_byage <- socialmixr::contact_matrix(
)

# prepare contact matrix
contacts_byage_matrix <- t(contacts_byage$matrix)
contacts_byage_matrix <- contacts_byage$matrix

# prepare the demography vector
demography_vector <- contacts_byage$demography$population
Expand Down
10 changes: 5 additions & 5 deletions episodes/modelling-interventions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Learners should also familiarise themselves with the following concept dependenc

**Outbreak response**: [Intervention types](https://www.cdc.gov/nonpharmaceutical-interventions/).

**R packages installed**: `{epidemics}`, `{contactsurveys}`, `{socialmixr}`, `{scales}`, `{tidyverse}`.
**R packages installed**: `{epidemics}`, `{contactsurveys}`, `{socialmixr}`, `{wpp2024}`, `{scales}`, `{tidyverse}`.

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

Expand All @@ -39,7 +39,7 @@ Install packages if they are not already installed

```r
if (!base::require("pak")) install.packages("pak")
pak::pak(c("epiverse-trace/epidemics", "contactsurveys", "socialmixr", "scales", "tidyverse"))
pak::pak(c("epiverse-trace/epidemics", "PPgp/wpp2024", "contactsurveys", "socialmixr", "scales", "tidyverse"))
```

If you have any error message,
Expand Down Expand Up @@ -84,7 +84,7 @@ Then start with the livecoding directly with interventions.

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.

The SEIR model divides the population into four compartments: Susceptible (S), Exposed (E), Infectious (I), and Recovered (R). We will set the following parameters for our model: $R_0 = 2.7$ (basic reproduction number), latent period or pre-infectious period $= 4$ days, and the infectious period $= 5.5$ days (parameters adapted from [Davies et al. (2020)](https://doi.org/10.1016/S2468-2667(20)30133-X)). We adopt a contact matrix with age bins 0-18, 18-65, 65 years and older using `{socialmixr}`, and assume that one in every 1 million individuals in each age group is infectious at the start of the epidemic.
The SEIR model divides the population into four compartments: Susceptible (S), Exposed (E), Infectious (I), and Recovered (R). We will set the following parameters for our model: $R_0 = 2.7$ (basic reproduction number), latent period or pre-infectious period $= 4$ days, and the infectious period $= 5.5$ days (parameters adapted from [Davies et al. (2020)](https://doi.org/10.1016/S2468-2667(20)30133-X)). We adopt a contact matrix with age bins 0-15, 15-65, 65 years and older using `{socialmixr}`, and assume that one in every 1 million individuals in each age group is infectious at the start of the epidemic.

```{r model_setup, echo = TRUE, message = FALSE, warning = FALSE}
# download and load survey data
Expand All @@ -110,8 +110,8 @@ contacts_byage <- socialmixr::contact_matrix(
survey_pop = uk_pop
)

# transpose contact matrix
contacts_byage_matrix <- t(contacts_byage$matrix)
# prepare contact matrix
contacts_byage_matrix <- contacts_byage$matrix

# prepare the demography vector
demography_vector <- contacts_byage$demography$population
Expand Down
6 changes: 3 additions & 3 deletions episodes/simulating-transmission.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Learners should familiarise themselves with the following concept dependencies b

**Epidemic theory**: [Transmission](https://doi.org/10.1155/2011/267049), [Reproduction number](https://doi.org/10.3201/eid2501.171901).

**R packages installed**: `{epidemics}`, `{contactsurveys}`, `{socialmixr}`, `{scales}`, `{tidyverse}`.
**R packages installed**: `{epidemics}`, `{contactsurveys}`, `{socialmixr}`, `{wpp2024}`, `{scales}`, `{tidyverse}`.

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

Expand All @@ -41,7 +41,7 @@ Install these packages if they are not already installed

```r
if (!base::require("pak")) install.packages("pak")
pak::pak(c("epiverse-trace/epidemics", "contactsurveys", "socialmixr", "scales", "tidyverse"))
pak::pak(c("epiverse-trace/epidemics", "PPgp/wpp2024", "contactsurveys", "socialmixr", "scales", "tidyverse"))
```

If you have any error message,
Expand Down Expand Up @@ -195,7 +195,7 @@ contacts_byage <- socialmixr::contact_matrix(
)

# prepare contact matrix
contacts_byage_matrix <- t(contacts_byage$matrix)
contacts_byage_matrix <- contacts_byage$matrix

# print
contacts_byage_matrix
Expand Down
2 changes: 1 addition & 1 deletion episodes/vaccine-comparisons.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contacts_byage <- socialmixr::contact_matrix(


# prepare contact matrix
contacts_byage_matrix <- t(contacts_byage$matrix)
contacts_byage_matrix <- contacts_byage$matrix

# prepare the demography vector
demography_vector <- contacts_byage$demography$population
Expand Down
2 changes: 1 addition & 1 deletion learners/contact-normalization.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Rather than just using the raw number of contacts, we can instead normalise the
In the case of the above model, we want to define $\beta C_{i,j}$ so that the model has a specified valued of $R_0$. If the entry of the contact matrix $C[i,j]$ represents the contacts of population $i$ with $j$, it is equivalent to `contacts_byage$matrix[i,j]`, and the maximum eigenvalue of this matrix represents the typical magnitude of contacts, not the typical magnitude of transmission. We must therefore normalise the matrix $C$ so the maximum eigenvalue is one; we call this matrix $C_{normalised}$. Because the rate of recovery is $\gamma$, individuals will be infectious on average for $1/\gamma$ days. So $\beta$ as a model input is calculated from $R_0$, the scaling factor and the value of $\gamma$ (i.e. mathematically we use the fact that the dominant eigenvalue of the matrix $R_0 \times C_{normalised}$ is equal to $\beta / \gamma$).

```{r}
contacts_byage_matrix <- t(contacts_byage$matrix)
contacts_byage_matrix <- contacts_byage$matrix
scaling_factor <- 1 / max(eigen(contacts_byage_matrix)$values)
normalised_matrix <- contacts_byage_matrix * scaling_factor
```
Expand Down
4 changes: 2 additions & 2 deletions learners/files/baseline-interventions-en.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ cm_results <- socialmixr::contact_matrix(
survey_pop = uk_pop
)

# transpose contact matrix
cm_matrix <- t(cm_results$matrix)
# prepare contact matrix
cm_matrix <- cm_results$matrix

# prepare the demography vector
demography_vector <- cm_results$demography$population
Expand Down
2 changes: 1 addition & 1 deletion 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 arranged by the three stages of outbreak analytics.](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 stage 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 @@ -70,7 +70,7 @@

Hold on: This is a great time to make sure your R installation is current.

This tutorial requires **R version 4.0.0 or later**.
This tutorial requires **R version 4.1.0 or later**.

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

Expand Down
Loading