Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fdae8b4
fix deprecated age.limits -> age_limits in contact_matrix() calls
avallecam Mar 20, 2026
bfe07cc
update contact-matrices.Rmd with contactsurveys/socialmixr pattern
avallecam Mar 20, 2026
8d5ce7f
apply contactsurveys/socialmixr pattern to all downstream episodes
avallecam Mar 20, 2026
d2e3678
suppress load_survey() 'No reference provided' warning
avallecam Mar 20, 2026
f2227d8
remove unnecessary warning = FALSE from zambia_solution chunk
avallecam Mar 20, 2026
7251923
polish the setup page
Degoot-AM Mar 23, 2026
c9fbb94
remove an empty instructor call.
Degoot-AM Mar 23, 2026
2fa8026
shortend the explanation of contact matrix.
Degoot-AM Mar 23, 2026
1687a28
remove compartment E fron SIR model example.
Degoot-AM Mar 23, 2026
3ff67d5
polish transmission episode
Degoot-AM Mar 23, 2026
31f35d0
polish model choice episode.
Degoot-AM Mar 23, 2026
c2b888f
fix space and :
Degoot-AM Mar 23, 2026
6e966a6
fix deprecated socialmixr::list_surveys() and link Zenodo community i…
avallecam Mar 23, 2026
75ef4cc
clarify country selection prose and update callout title in contact-m…
avallecam Mar 23, 2026
d245791
convert spoiler code block to executable chunk in contact-matrices
avallecam Mar 23, 2026
3204b5f
rename zambia survey objects to survey_files_zambia and survey_load_z…
avallecam Mar 23, 2026
f562936
rename _2 survey objects to survey_files_uk, survey_load_uk, contacts…
avallecam Mar 23, 2026
d76eea5
rewrite survey discovery prose and update spoiler structure in contac…
avallecam Mar 23, 2026
7642fca
suppress spoiler chunk output in contact-matrices
avallecam Mar 23, 2026
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
82 changes: 47 additions & 35 deletions episodes/compare-interventions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ library(epidemics)
# hidden seed for stable stochastic output in lesson
set.seed(33)

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

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

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

# prepare the demography vector
demography_vector <- contact_data$demography$population
names(demography_vector) <- rownames(contact_matrix)
demography_vector <- contacts_byage$demography$population
names(demography_vector) <- rownames(contacts_byage_matrix)

# initial conditions: one in every 1 million is infected
initial_i <- 1e-6
Expand All @@ -35,15 +41,15 @@ initial_conditions <- c(

# build for all age groups
initial_conditions <- matrix(
rep(initial_conditions, dim(contact_matrix)[1]),
rep(initial_conditions, dim(contacts_byage_matrix)[1]),
ncol = 5, byrow = TRUE
)
rownames(initial_conditions) <- rownames(contact_matrix)
rownames(initial_conditions) <- rownames(contacts_byage_matrix)

# prepare the population to model as affected by the epidemic
uk_population <- epidemics::population(
name = "UK",
contact_matrix = contact_matrix,
contact_matrix = contacts_byage_matrix,
demography_vector = demography_vector,
initial_conditions = initial_conditions
)
Expand Down Expand Up @@ -103,7 +109,7 @@ output_baseline <- epidemics::model_default(

Learners should familiarise themselves with following concept dependencies before working through this tutorial:

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


Expand Down Expand Up @@ -334,7 +340,7 @@ There is no vaccination scheme in place

::::::::::::::::: hint

### HINT : Running the model with default parameter values
### 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/model_vacamole.html#model-epidemic-using-vacamole) by just specifying the population object and number of time steps to run the model for:

Expand All @@ -354,20 +360,26 @@ output <- epidemics::model_vacamole(

1. Run the model

```{r}
polymod <- socialmixr::polymod
contact_data <- socialmixr::contact_matrix(
survey = polymod,
```{r, message = FALSE, warning = FALSE}
survey_files_uk <- contactsurveys::download_survey(
survey = "https://doi.org/10.5281/zenodo.3874557",
verbose = FALSE
)
survey_load_uk <- socialmixr::load_survey(files = survey_files_uk)

contacts_byage_uk <- socialmixr::contact_matrix(
survey = survey_load_uk,
countries = "United Kingdom",
age.limits = c(0, 20, 40),
symmetric = TRUE
age_limits = c(0, 20, 40),
symmetric = TRUE,
return_demography = TRUE
)
# prepare contact matrix
contact_matrix <- t(contact_data$matrix)
contacts_byage_matrix_uk <- t(contacts_byage_uk$matrix)

# extract demography vector
demography_vector <- contact_data$demography$population
names(demography_vector) <- rownames(contact_matrix)
demography_vector <- contacts_byage_uk$demography$population
names(demography_vector) <- rownames(contacts_byage_matrix_uk)

# prepare initial conditions
initial_i <- 1e-6
Expand All @@ -385,12 +397,12 @@ initial_conditions_vacamole <- rbind(
initial_conditions_vacamole,
initial_conditions_vacamole
)
rownames(initial_conditions_vacamole) <- rownames(contact_matrix)
rownames(initial_conditions_vacamole) <- rownames(contacts_byage_matrix_uk)

# prepare population object
uk_population_vacamole <- epidemics::population(
name = "UK",
contact_matrix = contact_matrix,
contact_matrix = contacts_byage_matrix_uk,
demography_vector = demography_vector,
initial_conditions = initial_conditions_vacamole
)
Expand Down Expand Up @@ -531,9 +543,9 @@ output_baseline <- epidemics::model_default(

Then, we create a list of all the interventions we want to include in our comparison. We define our scenarios as follows:

+ scenario 1 : close schools
+ scenario 2 : mask mandate
+ scenario 3 : close schools and mask mandate.
+ scenario 1: close schools
+ scenario 2: mask mandate
+ scenario 3: close schools and mask mandate.

In R we specify this as:
```{r}
Expand Down Expand Up @@ -567,7 +579,7 @@ head(output)

Now that we have our model output for all of our scenarios, we want to compare the outputs of the interventions to our baseline.

We can do this using `outcomes_averted()` in `{epidemics}`. This function calculates the final epidemic size for each scenario, and then calculates the number of infections averted in each scenario compared to the baseline. To use this function we specify the :
We can do this using `outcomes_averted()` in `{epidemics}`. This function calculates the final epidemic size for each scenario, and then calculates the number of infections averted in each scenario compared to the baseline. To use this function we specify the:

+ output of the baseline scenario
+ outputs of the intervention scenario(s).
Expand Down Expand Up @@ -605,9 +617,9 @@ We recommend to read the vignette on [Modelling responses to a stochastic Ebola

::::::::::::::::::::::::::::::::::::: challenge

## Challenge : Ebola outbreak analysis
## Challenge: Ebola outbreak analysis

You have been tasked to investigate the potential impact of an intervention on an Ebola outbreak in Guinea (e.g. a reduction in risky contacts with cases). Using `model_ebola()` and the the information detailed below, find the number of infections averted when :
You have been tasked to investigate the potential impact of an intervention on an Ebola outbreak in Guinea (e.g. a reduction in risky contacts with cases). Using `model_ebola()` and the the information detailed below, find the number of infections averted when:

+ an intervention is applied to reduce the transmission rate by 50% from day 60 and,
+ an intervention is applied to reduce transmission by 10% from day 30.
Expand All @@ -616,11 +628,11 @@ For both interventions, we assume there is some uncertainty about the baseline t

*Note: Depending on the number of replicates used, this simulation may take several minutes to run.*

+ Population size : 14 million
+ Initial number of exposed individuals : 10
+ Initial number of infectious individuals : 5
+ Time of simulation : 120 days
+ Parameter values :
+ 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,
Expand Down
Loading
Loading