Skip to content

Commit a42b125

Browse files
committed
add guides to tutors
1 parent 6a40b74 commit a42b125

1 file changed

Lines changed: 41 additions & 93 deletions

File tree

episodes/simulating-transmission.Rmd

Lines changed: 41 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -67,103 +67,16 @@ library(socialmixr)
6767
library(tidyverse)
6868
```
6969

70+
:::::::::::::::::::::: instructor
7071

71-
```{r traj, echo = FALSE, message = FALSE, fig.width = 10, eval = TRUE}
72-
# load contact and population data from socialmixr::polymod
73-
polymod <- socialmixr::polymod
74-
contact_data <- socialmixr::contact_matrix(
75-
polymod,
76-
countries = "United Kingdom",
77-
age.limits = c(0, 20, 40),
78-
symmetric = TRUE
79-
)
80-
81-
# prepare contact matrix
82-
contact_matrix <- t(contact_data$matrix)
83-
84-
# prepare the demography vector
85-
demography_vector <- contact_data$demography$population
86-
names(demography_vector) <- rownames(contact_matrix)
87-
88-
# initial conditions: one in every 1 million is infected
89-
initial_i <- 1e-6
90-
initial_conditions_inf <- c(
91-
S = 1 - initial_i, E = 0, I = initial_i, R = 0, V = 0
92-
)
93-
94-
initial_conditions_free <- c(
95-
S = 1, E = 0, I = 0, R = 0, V = 0
96-
)
97-
98-
# build for all age groups
99-
initial_conditions <- rbind(
100-
initial_conditions_inf,
101-
initial_conditions_free,
102-
initial_conditions_free
103-
)
104-
rownames(initial_conditions) <- rownames(contact_matrix)
105-
106-
# prepare the population to model as affected by the epidemic
107-
uk_population <- epidemics::population(
108-
name = "UK",
109-
contact_matrix = contact_matrix,
110-
demography_vector = demography_vector,
111-
initial_conditions = initial_conditions
112-
)
113-
114-
# time periods
115-
preinfectious_period <- 3.0
116-
infectious_period <- 7.0
117-
basic_reproduction <- 1.46
118-
119-
# rates
120-
infectiousness_rate <- 1.0 / preinfectious_period
121-
recovery_rate <- 1.0 / infectious_period
122-
transmission_rate <- basic_reproduction / infectious_period
123-
124-
# run an epidemic model using `epidemic()`
125-
output_plot <- epidemics::model_default(
126-
population = uk_population,
127-
transmission_rate = transmission_rate,
128-
infectiousness_rate = infectiousness_rate,
129-
recovery_rate = recovery_rate,
130-
time_end = 600, increment = 1.0
131-
)
132-
133-
output_plot %>%
134-
filter(compartment %in% c("exposed", "infectious")) %>%
135-
ggplot() +
136-
geom_line(
137-
aes(
138-
x = time,
139-
y = value,
140-
colour = demography_group,
141-
linetype = compartment
142-
),
143-
linewidth = 1.2
144-
) +
145-
scale_y_continuous(
146-
labels = scales::comma
147-
) +
148-
scale_colour_brewer(
149-
palette = "Dark2",
150-
name = "Age group"
151-
) +
152-
theme_bw() +
153-
labs(
154-
x = "Simulation time (days)",
155-
linetype = "Compartment",
156-
y = "Individuals"
157-
)
158-
```
72+
Use slides to introduce the topics of:
15973

74+
- Scenario modelling and
75+
- Contact matrix.
16076

161-
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: instructor
162-
163-
By the end of this tutorial, learners should be able to replicate the above image on their own computers.
164-
165-
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
77+
Then start with the livecoding.
16678

79+
::::::::::::::::::::::
16780

16881
## Simulating disease spread
16982

@@ -315,6 +228,19 @@ In `{epidemics}` the contact matrix normalisation happens within the function ca
315228

316229
::::::::::::::::::::::::::::::::::::::::::::::::
317230

231+
:::::::::::::::::::::: instructor
232+
233+
Make a pause.
234+
235+
Use slides to introduce the topics of:
236+
237+
- Initial conditions and
238+
- Population structure.
239+
240+
Then continue with the livecoding.
241+
242+
::::::::::::::::::::::
243+
318244
### 2. Initial conditions
319245

320246
The initial conditions are the proportion of individuals in each disease state $S$, $E$, $I$ and $R$ for each age group at time 0. In this example, we have three age groups age between 0 and 20 years, age between 20 and 40 years and over. Let's assume that in the youngest age category, one in a million individuals are infectious, and the remaining age categories are infection free.
@@ -377,6 +303,18 @@ uk_population <- population(
377303
```
378304

379305

306+
:::::::::::::::::::::: instructor
307+
308+
Make a pause.
309+
310+
Use slides to introduce the topics of:
311+
312+
- Model parameters and
313+
- New infections.
314+
315+
Then continue with the livecoding.
316+
317+
::::::::::::::::::::::
380318

381319

382320
### 4. Model parameters
@@ -540,6 +478,16 @@ newinfections_bygroup %>%
540478

541479
:::::::::::::::::::::::
542480

481+
:::::::::::::::::::::: instructor
482+
483+
Stop the livecoding.
484+
485+
Suggest learners to read the rest of the episode.
486+
487+
Return to slides.
488+
489+
::::::::::::::::::::::
490+
543491
## Accounting for uncertainty
544492

545493
The epidemic model is [deterministic](../learners/reference.md#deterministic), which means it runs like clockwork: the same parameters will always lead to the same trajectory. A deterministic model is one where the outcome is completely determined by the initial conditions and parameters, with no random variation. However, reality is not so predictable. There are two main reasons for this: the transmission process can involve randomness, and we may not know the exact epidemiological characteristics of the pathogen we're interested in. In the next episode, we will consider 'stochastic' models (i.e. models where we can define the process that creates randomness in transmission). In the meantime, we can include uncertainty in the value of the parameters that go into the deterministic model. To account for this, we must run our model for different parameter combinations.

0 commit comments

Comments
 (0)