You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contact-matrices.md
+51-22Lines changed: 51 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,7 @@ Some groups of individuals have more contacts than others; the average schoolchi
36
36
37
37
38
38
```r
39
+
library(contactsurveys)
39
40
library(socialmixr)
40
41
```
41
42
@@ -78,25 +79,49 @@ For a contact matrix with rows $i$ and columns $j$:
78
79
79
80
Contact matrices are commonly estimated from studies that use diaries to record interactions. For example, the POLYMOD survey measured contact patterns in 8 European countries using data on the location and duration of contacts reported by the study participants [(Mossong et al. 2008)](https://doi.org/10.1371/journal.pmed.0050074).
80
81
81
-
The R package `{socialmixr}` contains functions which can estimate contact matrices from POLYMOD and other surveys. We can load the POLYMOD survey data:
82
+
The R package `{socialmixr}` contains functions which can estimate contact matrices from POLYMOD and other surveys. We can download and load the POLYMOD survey data directly from Zenodo using `{contactsurveys}` and `{socialmixr}`:
Always pass the `countries =` argument to `contact_matrix()` to make sure you use data from the intended country only.
110
+
111
+
::::::::::::::::::::::::::::::::::::::::::::::::
112
+
113
+
Then we can obtain the contact matrix for the age categories we want by specifying `age_limits`. We also add `return_demography = TRUE` to include demographic information in the output, which is required when using the contact matrix with `{epidemics}`.
90
114
91
115
92
116
```r
93
-
contact_data<-socialmixr::contact_matrix(
94
-
survey=polymod,
117
+
contacts_byage<-socialmixr::contact_matrix(
118
+
survey=survey_load,
95
119
countries="United Kingdom",
96
120
age_limits= c(0, 20, 40),
97
-
symmetric=TRUE
121
+
symmetric=TRUE,
122
+
return_demography=TRUE
98
123
)
99
-
contact_data
124
+
contacts_byage
100
125
```
101
126
102
127
```output
@@ -124,8 +149,8 @@ $participants
124
149
125
150
126
151
127
-
**Note: although the contact matrix `contact_data$matrix` is not itself mathematically symmetric, it satisfies the condition that the total number of contacts of one group with another is the same as the reverse. In other words:
**Note: although the contact matrix `contacts_byage$matrix` is not itself mathematically symmetric, it satisfies the condition that the total number of contacts of one group with another is the same as the reverse. In other words:
For the mathematical explanation see [the corresponding section in the socialmixr documentation](https://epiforecasts.io/socialmixr/articles/socialmixr.html#symmetric-contact-matrices).**
130
155
131
156
@@ -145,14 +170,17 @@ If `symmetric` is set to TRUE, the `contact_matrix()` function will internally u
145
170
146
171
::::::::::::::::::::::::::::::::::::::::::::::::
147
172
148
-
The example above uses the POLYMOD survey. There are a number of surveys available in `socialmixr`. To list the available surveys, use `socialmixr::list_surveys()`. To download a survey, we can use `socialmixr::get_survey()`
173
+
The example above uses the POLYMOD survey. There are a number of surveys available in `socialmixr`. To list the available surveys, use `socialmixr::list_surveys()`. To download a survey from Zenodo and load it, we use `contactsurveys::download_survey()` followed by `socialmixr::load_survey()`:
149
174
150
175
151
176
```r
152
-
# Access the contact survey data from Zenodo
153
-
zambia_sa_survey<-socialmixr::get_survey(
154
-
"https://doi.org/10.5281/zenodo.3874675"
177
+
# Download and load the contact survey data for Zambia from Zenodo
# Print the vector of population size for {epidemics}
256
-
contact_data_zambia$demography$population
285
+
contacts_byage_zambia$demography$population
257
286
```
258
287
259
288
```output
@@ -329,13 +358,13 @@ When simulating an epidemic, we often want to ensure that the average number of
329
358
330
359
Rather than just using the raw number of contacts, we can instead normalise the contact matrix to make it easier to work in terms of $R_0$. In particular, we normalise the matrix by scaling it so that if we were to calculate the average number of secondary cases based on this normalised matrix, the result would be 1 (in mathematical terms, we are scaling the matrix so the largest eigenvalue is 1). This transformation scales the entries but preserves their relative values.
331
360
332
-
In the case of the above model, we want to define $\beta C_{i,j}$ so that the model has a specified valued of $R_0$. If the entry of the contact matrix $C[i,j]$ represents the contacts of population $i$ with $j$, it is equivalent to `contact_data$matrix[i,j]`, and the maximum eigenvalue of this matrix represents the typical magnitude of contacts, not typical magnitude of transmission. We must therefore normalise the matrix $C$ so the maximum eigenvalue is one; we call this matrix $C_{normalised}$. Because the rate of recovery is $\gamma$, individuals will be infectious on average for $1/\gamma$ days. So $\beta$ as a model input is calculated from $R_0$, the scaling factor and the value of $\gamma$ (i.e. mathematically we use the fact that the dominant eigenvalue of the matrix $R_0 \times C_{normalised}$ is equal to $\beta / \gamma$).
361
+
In the case of the above model, we want to define $\beta C_{i,j}$ so that the model has a specified valued of $R_0$. If the entry of the contact matrix $C[i,j]$ represents the contacts of population $i$ with $j$, it is equivalent to `contacts_byage$matrix[i,j]`, and the maximum eigenvalue of this matrix represents the typical magnitude of contacts, not typical magnitude of transmission. We must therefore normalise the matrix $C$ so the maximum eigenvalue is one; we call this matrix $C_{normalised}$. Because the rate of recovery is $\gamma$, individuals will be infectious on average for $1/\gamma$ days. So $\beta$ as a model input is calculated from $R_0$, the scaling factor and the value of $\gamma$ (i.e. mathematically we use the fact that the dominant eigenvalue of the matrix $R_0 \times C_{normalised}$ is equal to $\beta / \gamma$).
0 commit comments