@@ -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
1822socialsurvey <- 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.
2633contact_data <- socialmixr :: contact_matrix(
2734 # <COMPLETE>
2835)
2936
3037contact_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.
3443contact_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+ #
3954socialcontact_matrix <- t(contact_data $ matrix )
4055
4156socialcontact_matrix
@@ -48,6 +63,7 @@ socialcontact_matrix
4863# as given in table of parameter
4964initial_i <- # <COMPLETE>
5065
66+ # run: create an infectious vector
5167initial_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
6380initial_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
7898initial_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
85105rownames(initial_conditions ) <- rownames(socialcontact_matrix )
86106
87107initial_conditions
88108
89109# (3) Population structure ------------------------------------------------
90110
91- # Prepare the demography vector
111+ # run: Prepare the demography vector
92112demography_vector <- contact_data $ demography $ population
93113names(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
100120population_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
110130infectiousness_rate <- 1 / # <COMPLETE> # 1/pre-infectious period
111131recovery_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
121141simulate_baseline <- epidemics :: model_default(
122142 # <COMPLETE>
123143)
124144
125145simulate_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
132154simulate_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
145173epidemics :: 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
153181newinfections_bygroup <- epidemics :: new_infections(data = simulate_baseline )
154182
155183# Visualize the spread of the epidemic in terms of new infections
0 commit comments