Skip to content
Open
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
21 changes: 19 additions & 2 deletions episodes/compare-interventions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ exercises: 30 # exercise time in minutes
```{r setup, echo= FALSE, message = FALSE, warning = FALSE}
webshot::install_phantomjs(force = TRUE)
library(epidemics)
library(contactsurveys)
library(wpp2024)
library(tidyverse)

# hidden seed for stable stochastic output in lesson
set.seed(33)
Expand All @@ -18,12 +21,19 @@ survey_files <- contactsurveys::download_survey(
)
survey_load <- socialmixr::load_survey(files = survey_files)

data(popAge1dt, package = "wpp2024")

uk_pop <- popAge1dt %>%
dplyr::filter(name == "United Kingdom", year == max(year)) %>%
dplyr::select(lower.age.limit = age, population = pop) %>%
dplyr::mutate(population = population * 1000)

contacts_byage <- socialmixr::contact_matrix(
survey = survey_load,
countries = "United Kingdom",
age_limits = c(0, 15, 65),
symmetric = TRUE,
return_demography = TRUE
survey_pop = uk_pop
)

# prepare contact matrix
Expand Down Expand Up @@ -344,12 +354,19 @@ survey_files_uk <- contactsurveys::download_survey(
)
survey_load_uk <- socialmixr::load_survey(files = survey_files_uk)

data(popAge1dt, package = "wpp2024")

uk_pop <- popAge1dt %>%
dplyr::filter(name == "United Kingdom", year == max(year)) %>%
dplyr::select(lower.age.limit = age, population = pop) %>%
dplyr::mutate(population = population * 1000)

contacts_byage_uk <- socialmixr::contact_matrix(
survey = survey_load_uk,
countries = "United Kingdom",
age_limits = c(0, 20, 40),
symmetric = TRUE,
return_demography = TRUE
survey_pop = uk_pop
)
# prepare contact matrix
contacts_byage_matrix_uk <- t(contacts_byage_uk$matrix)
Expand Down
27 changes: 23 additions & 4 deletions episodes/contact-matrices.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ webshot::install_phantomjs(force = TRUE)

## Introduction

Some groups of individuals have more contacts than others; the average schoolchild has many more daily contact than the average elderly person, for example. This heterogeneity of contact patterns between different groups can affect disease transmission, because certain groups are more likely to transmit to others within that group, as well as to other groups. The rate at which individuals within and between groups make contact with others can be summarised in a contact matrix. In this tutorial we are going to learn how contact matrices can be used in different analyses and how the `{socialmixr}` package can be used to estimate contact matrices.
Some groups of individuals have more contacts than others; the average schoolchild has many more daily contact than the average elderly person, for example. This heterogeneity of contact patterns between different groups can affect disease transmission, because certain groups are more likely to transmit to others within that group, as well as to other groups. The rate at which individuals within and between groups make contact with others can be summarised in a contact matrix.

In this tutorial we are going to learn how contact matrices can be used in different analyses, how the package `{contactsurveys}` can be used to access survey data from different countries, and how the `{socialmixr}` package can be used to estimate contact matrices. We'll use `{dplyr}`, `{ggplot2}` and the pipe `%>%` to connect some of their functions, so let's also call to the `{tidyverse}` package:


```{r,message=FALSE,warning=FALSE}
library(contactsurveys)
library(socialmixr)
library(wpp2024)
library(tidyverse)
```

## The contact matrix
Expand Down Expand Up @@ -96,15 +100,22 @@ levels(survey_load$participants$country)

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

We obtain the contact matrix for the United Kingdom — passing `countries = "United Kingdom"` to select data from the intended country, `age_limits` to define age categories, and `return_demography = TRUE` to include demographic information required by `{epidemics}`.
We obtain the contact matrix for the United Kingdom — passing `countries = "United Kingdom"` to select data from the intended country, `age_limits` to define age categories, and `survey_pop` to supply the population structure from `{wpp2024}` required by `{socialmixr}`.

```{r polymod_uk, echo = TRUE}
data(popAge1dt, package = "wpp2024")

uk_pop <- popAge1dt %>%
dplyr::filter(name == "United Kingdom", year == max(year)) %>%
dplyr::select(lower.age.limit = age, population = pop) %>%
dplyr::mutate(population = population * 1000)

contacts_byage <- socialmixr::contact_matrix(
survey = survey_load,
countries = "United Kingdom",
age_limits = c(0, 20, 40),
symmetric = TRUE,
return_demography = TRUE
survey_pop = uk_pop
)
contacts_byage
```
Expand Down Expand Up @@ -195,13 +206,20 @@ Similar to the code above, to access vector values within a dataframe, you can u
:::::::::::::::::::::::: instructor

```{r zambia_solution}
data(popAge1dt, package = "wpp2024")

zambia_pop <- popAge1dt %>%
dplyr::filter(name == "Zambia", year == max(year)) %>%
dplyr::select(lower.age.limit = age, population = pop) %>%
dplyr::mutate(population = population * 1000)

# Generate the contact matrix for Zambia only
contacts_byage_zambia <- socialmixr::contact_matrix(
survey = survey_load_zambia,
countries = "Zambia", # key argument
age_limits = c(0, 20),
symmetric = TRUE,
return_demography = TRUE
survey_pop = zambia_pop
)

# Print the contact matrix for Zambia only
Expand Down Expand Up @@ -315,6 +333,7 @@ contact_data_split <- socialmixr::contact_matrix(
countries = "United Kingdom",
age_limits = c(0, 20, 40),
symmetric = TRUE,
survey_pop = uk_pop,
split = TRUE
)

Expand Down
10 changes: 9 additions & 1 deletion episodes/disease-burden.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ library(epiparameter)
library(epidemics)
library(contactsurveys)
library(socialmixr)
library(wpp2024)
library(tidyverse)
```

Expand Down Expand Up @@ -91,12 +92,19 @@ survey_files <- contactsurveys::download_survey(
)
survey_load <- socialmixr::load_survey(files = survey_files)

data(popAge1dt, package = "wpp2024")

uk_pop <- popAge1dt %>%
dplyr::filter(name == "United Kingdom", year == max(year)) %>%
dplyr::select(lower.age.limit = age, population = pop) %>%
dplyr::mutate(population = population * 1000)

contacts_byage <- socialmixr::contact_matrix(
survey = survey_load,
countries = "United Kingdom",
age_limits = c(0, 20, 40),
symmetric = TRUE,
return_demography = TRUE
survey_pop = uk_pop
)

# prepare contact matrix
Expand Down
10 changes: 9 additions & 1 deletion episodes/modelling-interventions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ In this tutorial, we will learn how to use `{epidemics}` to model interventions
library(epidemics)
library(contactsurveys)
library(socialmixr)
library(wpp2024)
library(tidyverse)
```

Expand Down Expand Up @@ -93,13 +94,20 @@ survey_files <- contactsurveys::download_survey(
)
survey_load <- socialmixr::load_survey(files = survey_files)

data(popAge1dt, package = "wpp2024")

uk_pop <- popAge1dt %>%
dplyr::filter(name == "United Kingdom", year == max(year)) %>%
dplyr::select(lower.age.limit = age, population = pop) %>%
dplyr::mutate(population = population * 1000)

# generate contact matrix
contacts_byage <- socialmixr::contact_matrix(
survey = survey_load,
countries = "United Kingdom",
age_limits = c(0, 15, 65),
symmetric = TRUE,
return_demography = TRUE
survey_pop = uk_pop
)

# transpose contact matrix
Expand Down
22 changes: 21 additions & 1 deletion episodes/simulating-transmission.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ In this tutorial we are going to learn how to use the `{epidemics}` package to s
library(epidemics)
library(contactsurveys)
library(socialmixr)
library(wpp2024)
library(tidyverse)
```

Expand Down Expand Up @@ -183,13 +184,20 @@ survey_files <- contactsurveys::download_survey(
)
survey_load <- socialmixr::load_survey(files = survey_files)

data(popAge1dt, package = "wpp2024")

uk_pop <- popAge1dt %>%
dplyr::filter(name == "United Kingdom", year == max(year)) %>%
dplyr::select(lower.age.limit = age, population = pop) %>%
dplyr::mutate(population = population * 1000)

# Generate the contact matrix
contacts_byage <- socialmixr::contact_matrix(
survey = survey_load,
countries = "United Kingdom",
age_limits = c(0, 20, 40),
symmetric = TRUE,
return_demography = TRUE
survey_pop = uk_pop
)

# prepare contact matrix
Expand Down Expand Up @@ -301,6 +309,18 @@ uk_population <- epidemics::population(
)
```

:::::::::::: checklist

Print the `uk_population` object.

It must collect all the input information:

- Population name
- Demography
- Contact matrix
- Initial conditions

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

:::::::::::::::::::::: instructor

Expand Down
10 changes: 9 additions & 1 deletion episodes/vaccine-comparisons.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ library(ggplot2)
library(epidemics)
library(contactsurveys)
library(socialmixr)
library(wpp2024)
library(dplyr)
library(purrr)
```
Expand Down Expand Up @@ -74,12 +75,19 @@ survey_files <- contactsurveys::download_survey(
)
survey_load <- socialmixr::load_survey(files = survey_files)

data(popAge1dt, package = "wpp2024")

uk_pop <- popAge1dt %>%
dplyr::filter(name == "United Kingdom", year == max(year)) %>%
dplyr::select(lower.age.limit = age, population = pop) %>%
dplyr::mutate(population = population * 1000)

contacts_byage <- socialmixr::contact_matrix(
survey = survey_load,
countries = "United Kingdom",
age_limits = c(0, 15, 65),
symmetric = TRUE,
return_demography = TRUE
survey_pop = uk_pop
)


Expand Down
21 changes: 17 additions & 4 deletions learners/files/baseline-interventions-en.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,30 @@
# load packages
library(epidemics)
library(socialmixr)
library(contactsurveys)
library(tidyverse)

# load survey data
survey_data <- socialmixr::polymod
survey_files <- contactsurveys::download_survey(
survey = "https://doi.org/10.5281/zenodo.3874557",
verbose = FALSE
)
survey_load <- socialmixr::load_survey(files = survey_files)

data(popAge1dt, package = "wpp2024")

uk_pop <- popAge1dt %>%
dplyr::filter(name == "United Kingdom", year == max(year)) %>%
dplyr::select(lower.age.limit = age, population = pop) %>%
dplyr::mutate(population = population * 1000)

# generate contact matrix
cm_results <- socialmixr::contact_matrix(
survey = survey_data,
survey = survey_load,
countries = "United Kingdom",
age.limits = c(0, 15, 65),
symmetric = TRUE
age_limits = c(0, 15, 65),
symmetric = TRUE,
survey_pop = uk_pop
)

# transpose contact matrix
Expand Down
4 changes: 4 additions & 0 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 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 @@ -173,6 +173,8 @@

new_packages <- c(
"socialmixr",
"contactsurveys",
"PPgp/wpp2024",
"finalsize",
"epiverse-trace/epidemics",
"epiparameter",
Expand Down Expand Up @@ -247,6 +249,8 @@

```r
library(socialmixr)
library(contactsurveys)
library(wpp2024)
library(finalsize)
library(epidemics)
library(epiparameter)
Expand Down
26 changes: 26 additions & 0 deletions renv/profiles/lesson-requirements/renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5354,6 +5354,32 @@
"NeedsCompilation": "no",
"Repository": "CRAN"
},
"wpp2024": {
"Package": "wpp2024",
"Version": "1.1-3",
"Source": "GitHub",
"Date": "2024-11-26",
"Title": "World Population Prospects 2024",
"Author": "United Nations Population Division",
"Maintainer": "Hana Sevcikova <hanas@uw.edu>",
"Depends": [
"R (>= 2.14.2)",
"data.table"
],
"Suggests": [],
"Description": "Provides data from the United Nation's World Population Prospects 2024.",
"License": "file LICENSE",
"URL": "http://population.un.org/wpp",
"NeedsCompilation": "no",
"LazyData": "no",
"RemoteType": "github",
"RemoteHost": "api.github.com",
"RemoteRepo": "wpp2024",
"RemoteUsername": "PPgp",
"RemotePkgRef": "PPgp/wpp2024",
"RemoteRef": "HEAD",
"RemoteSha": "2da7768ae64fc74105d3f9e98f9a74d37b62f99a"
},
"xfun": {
"Package": "xfun",
"Version": "0.58",
Expand Down
Loading