Skip to content

Commit abd3c67

Browse files
committed
update practical steps
1 parent f441de0 commit abd3c67

File tree

2 files changed

+76
-34
lines changed

2 files changed

+76
-34
lines changed

instructors/data/04-practical-activity-1.R

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,43 @@ library(tidyverse)
1414

1515
# (1) Contact matrix ------------------------------------------------------
1616

17-
# step: paste the survey link for your room
17+
# note: all input parameters come from
18+
# the table of parameters of the practical document
19+
20+
# step: paste the survey link assigned to your room
21+
# then run the function to download the social contact data
1822
socialsurvey <- socialmixr::get_survey(
1923
#<COMPLETE>
2024
)
2125

22-
# step: generate contact matrix by defining
23-
# survey class object, country name,
24-
# age limits from table of parameters,
25-
# and whether to make a symmetric matrix
26+
socialsurvey
27+
28+
# step: generate the contact matrix by defining
29+
# - the survey class object just downloaded,
30+
# - the country name,
31+
# - the age limits, as in the table of parameters, and
32+
# - TRUE or FALSE to create a symmetric matrix.
2633
contact_data <- socialmixr::contact_matrix(
2734
#<COMPLETE>
2835
)
2936

3037
contact_data
3138

32-
# Matrix are symmetric for the total number of contacts
33-
# of one group with another is the same as the reverse
39+
# run: confirm the symmetry of the matrix
40+
# Matrix are symmetric for the total number of contacts.
41+
# The total number of contacts from one group to another is the same in both directions.
42+
# Check this by multiplying the mean contacts by the population size for each group.
3443
contact_data$matrix * contact_data$demography$proportion
3544

36-
# Prepare contact matrix
37-
# {socialmixr} provides contacts from-to
38-
# {epidemics} expects contacts to-from
45+
# run: Prepare contact matrix
46+
#
47+
# - {socialmixr} provides a matrix from-to: from-participants -> to-contacts
48+
# In surveys, participants report their contacts.
49+
#
50+
# - {epidemics} expects a matrix to-from: to-contacts <- from-participants
51+
# Models assume that each susceptible (contact) is exposed to infection based on
52+
# how often they are contacted (by participants) and how infectious (participatns) are.
53+
#
3954
socialcontact_matrix <- t(contact_data$matrix)
4055

4156
socialcontact_matrix
@@ -48,6 +63,7 @@ socialcontact_matrix
4863
# as given in table of parameter
4964
initial_i <- #<COMPLETE>
5065

66+
# run: create an infectious vector
5167
initial_conditions_inf <- c(
5268
S = 1 - initial_i,
5369
E = 0,
@@ -60,6 +76,7 @@ initial_conditions_inf
6076

6177
## Free of infection population ---------
6278

79+
# run: create an infection-free vector
6380
initial_conditions_free <- c(
6481
S = 1,
6582
E = 0,
@@ -72,31 +89,34 @@ initial_conditions_free
7289

7390
## Combine initial conditions ------------
7491

92+
# note: not all the population needs to be infectious.
93+
# The epidemic can start with infecitous in a specific age range.
94+
7595
# step: Combine the initial conditions
76-
# add initial_conditions_inf or initial_conditions_free
77-
# to the each age group as given in table of parameter
96+
# Add initial_conditions_inf or initial_conditions_free
97+
# to the each age group as detailed in table of parameter
7898
initial_conditions <- base::rbind(
7999
#<COMPLETE>, # age group 1
80100
#<COMPLETE>, # age group 2
81101
#<COMPLETE> # age group 3
82102
)
83103

84-
# Use contact matrix to assign age group names
104+
# run: Use contact matrix to assign age group names
85105
rownames(initial_conditions) <- rownames(socialcontact_matrix)
86106

87107
initial_conditions
88108

89109
# (3) Population structure ------------------------------------------------
90110

91-
# Prepare the demography vector
111+
# run: Prepare the demography vector
92112
demography_vector <- contact_data$demography$population
93113
names(demography_vector) <- rownames(socialcontact_matrix)
94114

95-
# step: Prepare the population to model as affected by the epidemic
96-
# add the name of the country,
97-
# the symmetric and transposed contact matrix,
98-
# the vector with the population size of each age group
99-
# the binded matrix with initial conditions for each age group
115+
# step: Prepare the population to model as affected by the epidemic adding
116+
# - the name of the country,
117+
# - the symmetric and transposed contact matrix,
118+
# - the vector with the population size of each age group
119+
# - the binded matrix with initial conditions for each age group
100120
population_object <- epidemics::population(
101121
#<COMPLETE>
102122
)
@@ -105,7 +125,7 @@ population_object
105125

106126
# (4) Model parameters ----------------------------------------------------
107127

108-
# step: Rates
128+
# step: define the disease-specific parameters: the rates
109129
# add the values as given in table of parameter
110130
infectiousness_rate <- 1 / #<COMPLETE> # 1/pre-infectious period
111131
recovery_rate <- 1 / #<COMPLETE> # 1/infectious period
@@ -115,20 +135,22 @@ transmission_rate <- recovery_rate * #<COMPLETE> # recovery rate * R0
115135
# (5) Run the model --------------------------------------------------------
116136

117137
# step: in each function argument add
118-
# the population object
119-
# each of the previously defined rates
120-
# the total simulation time as given in table of parameter
138+
# - the population object
139+
# - each of the previously defined disease-specific rates
140+
# - the total simulation time as given in table of parameter
121141
simulate_baseline <- epidemics::model_default(
122142
#<COMPLETE>
123143
)
124144

125145
simulate_baseline
126146

127147

128-
# Plot all compartments --------------------------------------------------
148+
# (6) Plot all compartments ------------------------------------------------
129149

130-
# step: paste plot and table output in report
150+
# run: paste plot in report
131151

152+
# plot with total number of individual per compartment
153+
# at different points in time
132154
simulate_baseline %>%
133155
ggplot(aes(
134156
x = time,
@@ -142,14 +164,20 @@ simulate_baseline %>%
142164
labels = scales::comma
143165
)
144166

167+
# (7) Peak of infectious -------------------------------------------------
168+
169+
# run: paste table output in report
170+
171+
# table of epidemic peak size and time
172+
# per demographic group
145173
epidemics::epidemic_peak(data = simulate_baseline)
146174

147175

148-
# Plot new infections ----------------------------------------------------
176+
# (8) Plot new infections -------------------------------------------------
149177

150-
# step: paste plot output in report
178+
# run: paste plot output in report
151179

152-
# New infections
180+
# New infections per demographic group in time
153181
newinfections_bygroup <- epidemics::new_infections(data = simulate_baseline)
154182

155183
# Visualize the spread of the epidemic in terms of new infections

instructors/data/04-practical-activity-2.R

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@ room_number <- #<COMPLETE> replace with 1/2/3/4
88

99
# Intervention ---------------------------------------------------------
1010

11+
# note: all input parameters come from
12+
# the table of parameters of the practical document
13+
1114
rownames(socialcontact_matrix)
1215

1316
# step: create the intervention object:
17+
#
1418
# identify if you need to keep:
1519
# epidemics::intervention() or epidemics::vaccination()
20+
#
1621
# then add:
1722
# - name of the intervention
1823
# - type of intervention ("rate" or "contacts"), if needed
1924
# - time when the intervention begins and ends (as values or matrix*)
20-
# as given in table of inputs
2125
# - reduction or vaccination rate (as values or matrix*)
26+
#
2227
# *if matrix, values follow same order as in the social contact matrix
28+
#
2329
test_intervention <- epidemics::intervention(#<COMPLETE>
2430
)
31+
# or
2532
test_intervention <- epidemics::vaccination(#<COMPLETE>
2633
)
2734

@@ -30,8 +37,10 @@ test_intervention
3037
# Run {epidemics} ---------------------------------------------------------
3138

3239
# step: add the intervention argument
40+
#
3341
# as a list (for interventions against contacts or transmission rate)
3442
# or as an object (for vaccination)
43+
#
3544
simulate_intervention <- epidemics::model_default(
3645
population = population_object,
3746
transmission_rate = transmission_rate,
@@ -47,7 +56,7 @@ simulate_intervention
4756

4857
# Plot all compartments --------------------------------------------------
4958

50-
# step: paste plot and table output in report
59+
# run: paste plot in report
5160

5261
simulate_intervention %>%
5362
ggplot(aes(
@@ -67,16 +76,21 @@ simulate_intervention %>%
6776
labels = scales::comma
6877
)
6978

79+
80+
# Peak of infectious -----------------------------------------------------
81+
82+
# run: paste table output in report
83+
7084
epidemics::epidemic_peak(data = simulate_intervention)
7185

7286
# Visualize effect --------------------------------------------------------
7387
# Plot new infections
7488

7589
# step:
76-
# add intervention name
77-
# if your intervention is vaccination, then
78-
# activate the argument exclude_compartments
79-
# run and paste plot output in report
90+
# - add intervention name
91+
# - if your intervention is vaccination, then
92+
# - activate the argument "exclude_compartments"
93+
# - run and paste plot output in report
8094

8195
infections_baseline <- epidemics::new_infections(
8296
data = simulate_baseline,

0 commit comments

Comments
 (0)