Skip to content

Commit 92f9e06

Browse files
committed
recover code chunk required for outputs
1 parent ec2c4e9 commit 92f9e06

1 file changed

Lines changed: 51 additions & 24 deletions

File tree

episodes/compare-interventions.Rmd

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ uk_population <- epidemics::population(
4848
initial_conditions = initial_conditions
4949
)
5050
51-
close_schools <- intervention(
51+
close_schools <- epidemics::intervention(
5252
name = "School closure",
5353
type = "contacts",
5454
time_begin = 50,
5555
time_end = 50 + 100,
5656
reduction = matrix(c(0.5, 0.01, 0.01))
5757
)
5858
59-
mask_mandate <- intervention(
59+
mask_mandate <- epidemics::intervention(
6060
name = "mask mandate",
6161
type = "rate",
6262
time_begin = 40,
@@ -74,7 +74,7 @@ infectiousness_rate <- 1.0 / preinfectious_period
7474
recovery_rate <- 1.0 / infectious_period
7575
transmission_rate <- basic_reproduction / infectious_period
7676
77-
output_baseline <- model_default(
77+
output_baseline <- epidemics::model_default(
7878
population = uk_population,
7979
transmission_rate = transmission_rate,
8080
infectiousness_rate = infectiousness_rate,
@@ -121,10 +121,13 @@ We must also define our *outcome of interest* to make comparisons between interv
121121
- Health impact measures (e.g., Quality-Adjusted Life Years [QALYs] or Disability-Adjusted Life Years [DALYs])
122122
- Economic measures (e.g., healthcare costs, productivity losses)
123123

124-
In this tutorial, we will learn how to use the R package `{epidemics}` to compare the effect of different interventions on simulated disease trajectories. We will use:
125-
- `{socialmixr}` for social contact data
126-
- `{tidyverse}` (including `{dplyr}` and `{ggplot2}`) for data manipulation and visualization
124+
In this tutorial, we will learn how to use the R package `{epidemics}` to compare the effect of different interventions on simulated disease trajectories. We will use `{socialmixr}` for social contact data and `{tidyverse}` (including `{dplyr}`, `{ggplot2}`, and the pipe `%>%`) for data manipulation and visualization.
127125

126+
```{r}
127+
library(epidemics)
128+
library(socialmixr)
129+
library(tidyverse)
130+
```
128131

129132
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: instructor
130133

@@ -138,15 +141,15 @@ To compare the baseline scenario against the intervention scenarios, we can make
138141

139142
If we wanted to investigate the change in epidemic peak with an intervention applied, we could plot the model trajectories through time:
140143
```{r}
141-
output_baseline <- model_default(
144+
output_baseline <- epidemics::model_default(
142145
population = uk_population,
143146
transmission_rate = transmission_rate,
144147
infectiousness_rate = infectiousness_rate,
145148
recovery_rate = recovery_rate,
146149
time_end = 300, increment = 1.0
147150
)
148151
149-
output_school <- model_default(
152+
output_school <- epidemics::model_default(
150153
# population
151154
population = uk_population,
152155
# rate
@@ -336,7 +339,7 @@ We can run the Vacamole model with [default parameter values](https://epiverse-t
336339

337340

338341
```{r, eval = FALSE}
339-
output <- model_vacamole(
342+
output <- epidemics::model_vacamole(
340343
population = uk_population,
341344
time_end = 300
342345
)
@@ -384,7 +387,7 @@ initial_conditions_vacamole <- rbind(
384387
rownames(initial_conditions_vacamole) <- rownames(contact_matrix)
385388
386389
# prepare population object
387-
uk_population_vacamole <- population(
390+
uk_population_vacamole <- epidemics::population(
388391
name = "UK",
389392
contact_matrix = contact_matrix,
390393
demography_vector = demography_vector,
@@ -393,15 +396,15 @@ uk_population_vacamole <- population(
393396
394397
# prepare two vaccination objects
395398
# dose 1 vaccination
396-
dose_1 <- vaccination(
399+
dose_1 <- epidemics::vaccination(
397400
name = "two-dose vaccination", # name given to first dose
398401
nu = matrix(0.01, nrow = 3),
399402
time_begin = matrix(30, nrow = 3),
400403
time_end = matrix(300, nrow = 3)
401404
)
402405
403406
# prepare the second dose with a 30 day interval in start date
404-
dose_2 <- vaccination(
407+
dose_2 <- epidemics::vaccination(
405408
name = "two-dose vaccination", # name given to first dose
406409
nu = matrix(0.01, nrow = 3),
407410
time_begin = matrix(30 + 30, nrow = 3),
@@ -412,14 +415,14 @@ dose_2 <- vaccination(
412415
double_vaccination <- c(dose_1, dose_2)
413416
414417
# run baseline model
415-
output_baseline_vc <- model_vacamole(
418+
output_baseline_vc <- epidemics::model_vacamole(
416419
population = uk_population_vacamole,
417420
vaccination = double_vaccination,
418421
time_end = 300
419422
)
420423
421424
# create mask intervention
422-
mask_mandate <- intervention(
425+
mask_mandate <- epidemics::intervention(
423426
name = "mask mandate",
424427
type = "rate",
425428
time_begin = 60,
@@ -428,7 +431,7 @@ mask_mandate <- intervention(
428431
)
429432
430433
# run intervention model
431-
output_intervention_vc <- model_vacamole(
434+
output_intervention_vc <- epidemics::model_vacamole(
432435
population = uk_population_vacamole,
433436
vaccination = double_vaccination,
434437
intervention = list(
@@ -487,10 +490,34 @@ While visualizations are useful for comparing intervention scenarios over time,
487490

488491
The R package `{epidemics}` provides the `outcomes_averted()` function to calculate infections averted while accounting for parameter uncertainty. Let's extend our COVID-19 example from [Modelling interventions](../episodes/modelling-interventions.md) to account for uncertainty in the basic reproduction number ($R_0$).
489492

493+
```{r}
494+
# time periods
495+
preinfectious_period <- 4.0
496+
infectious_period <- 5.5
497+
498+
# specify the mean and standard deviation of R0
499+
r_estimate_mean <- 2.7
500+
r_estimate_sd <- 0.05
501+
502+
# generate 100 R samples
503+
r_samples <- withr::with_seed(
504+
seed = 1,
505+
rnorm(
506+
n = 100, mean = r_estimate_mean, sd = r_estimate_sd
507+
)
508+
)
509+
510+
beta <- r_samples / infectious_period
511+
512+
# rates
513+
infectiousness_rate <- 1.0 / preinfectious_period
514+
recovery_rate <- 1.0 / infectious_period
515+
```
516+
490517
We use these parameter values alongside the population structure and contact matrix used in [Modelling interventions](../episodes/modelling-interventions.md) to run the model for the baseline scenario:
491518

492519
```{r}
493-
output_baseline <- model_default(
520+
output_baseline <- epidemics::model_default(
494521
population = uk_population,
495522
transmission_rate = beta,
496523
infectiousness_rate = infectiousness_rate,
@@ -525,7 +552,7 @@ intervention_scenarios <- list(
525552
We use this list as our input to `intervention` in `model_default`
526553

527554
```{r}
528-
output <- model_default(
555+
output <- epidemics::model_default(
529556
uk_population,
530557
transmission_rate = beta,
531558
infectiousness_rate = infectiousness_rate,
@@ -544,7 +571,7 @@ We can do this using `outcomes_averted()` in `{epidemics}`. This function calcul
544571
+ outputs of the intervention scenario(s).
545572

546573
```{r}
547-
intervention_effect <- outcomes_averted(
574+
intervention_effect <- epidemics::outcomes_averted(
548575
baseline = output_baseline, scenarios = output
549576
)
550577
intervention_effect
@@ -553,7 +580,7 @@ intervention_effect
553580
The output gives us the infections averted in each scenario compared to the baseline. To obtain the infections averted overall we specify `by_group = FALSE`:
554581

555582
```{r}
556-
intervention_effect <- outcomes_averted(
583+
intervention_effect <- epidemics::outcomes_averted(
557584
baseline = output_baseline, scenarios = output,
558585
by_group = FALSE
559586
)
@@ -632,7 +659,7 @@ beta <- withr::with_seed(
632659
)
633660
634661
# run the baseline
635-
output_baseline <- model_ebola(
662+
output_baseline <- epidemics::model_ebola(
636663
population = guinea_population,
637664
transmission_rate = beta,
638665
infectiousness_rate = 2.0 / 5,
@@ -645,12 +672,12 @@ output_baseline <- model_ebola(
645672
)
646673
647674
# create intervention objects
648-
reduce_transmission_1 <- intervention(
675+
reduce_transmission_1 <- epidemics::intervention(
649676
type = "rate",
650677
time_begin = 60, time_end = 100, reduction = 0.5
651678
)
652679
653-
reduce_transmission_2 <- intervention(
680+
reduce_transmission_2 <- epidemics::intervention(
654681
type = "rate",
655682
time_begin = 30, time_end = 100, reduction = 0.1
656683
)
@@ -666,7 +693,7 @@ intervention_scenarios <- list(
666693
)
667694
668695
# run model
669-
output_intervention <- model_ebola(
696+
output_intervention <- epidemics::model_ebola(
670697
population = guinea_population,
671698
transmission_rate = beta,
672699
infectiousness_rate = 2.0 / 5,
@@ -680,7 +707,7 @@ output_intervention <- model_ebola(
680707
)
681708
682709
# calculate outcomes averted
683-
intervention_effect <- outcomes_averted(
710+
intervention_effect <- epidemics::outcomes_averted(
684711
baseline = output_baseline, scenarios = output_intervention,
685712
by_group = FALSE
686713
)

0 commit comments

Comments
 (0)