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
+65-14Lines changed: 65 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,7 @@ Then we can obtain the contact matrix for the age categories we want by specifyi
89
89
90
90
91
91
```r
92
-
contact_data<- contact_matrix(
92
+
contact_data<-socialmixr::contact_matrix(
93
93
survey=polymod,
94
94
countries="United Kingdom",
95
95
age.limits= c(0, 20, 40),
@@ -151,32 +151,73 @@ If `symmetric` is set to TRUE, the `contact_matrix()` function will internally u
151
151
152
152
::::::::::::::::::::::::::::::::::::::::::::::::
153
153
154
-
The example above uses the POLYMOD survey. There are a number of surveys available in `socialmixr`, to list the available surveys use `list_surveys()`. To download a survey, we can use `get_survey()`
154
+
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()`
You can explore all the available surveys from the Zenodo repository at <https://zenodo.org/communities/social_contact_data/>. If you are interested in accessing to a specific URL within R, you can try:
165
+
166
+
```r
167
+
library(socialmixr)
168
+
library(tidyverse)
169
+
170
+
# Get URL for Zambia contact survey data from {socialmixr}
After downloading the survey, generate a symmetric contact matrix for Zambia using the following age bins:
183
+
The R package {socialmixr} contains functions which can estimate contact matrices from POLYMOD and other surveys. Outputs include demographic information like population size and number of participants in the study. Using {socialmixr}:
184
+
185
+
+ Get access to the survey from Zambia.
186
+
+ Generate a symmetric contact matrix for Zambia using the following age bins:
168
187
169
-
+[0,20)
170
-
+ 20+
188
+
+[0,20)
189
+
+ 20+
190
+
191
+
+ Get access to the vector of `population` size per age bin from the `demography` dataset inside the contact matrix output.
192
+
193
+
::::::::::::::::::::: hint
194
+
195
+
The survey object `zambia_sa_survey` contains data from two countries. If you need to estimate the social contact matrix from data of the specific country of Zambia, identify what argument in `socialmixr::contact_matrix()` you need for this.
196
+
197
+
198
+
```r
199
+
# Inspect the countries within the survey object
200
+
levels(zambia_sa_survey$participants$country)
201
+
```
202
+
203
+
```output
204
+
[1] "South Africa" "Zambia"
205
+
```
206
+
207
+
Similar to the code above, to access vector values within a dataframe, you can use the dollar-sign operator: `$`
208
+
209
+
:::::::::::::::::::::
171
210
172
211
::::::::::::::::::::::::::::::::::::::::::::::::
173
212
174
213
:::::::::::::::::::::::: instructor
175
214
176
215
177
216
```r
178
-
contact_data_zambia<- contact_matrix(
217
+
# Generate the contact matrix for Zambia only
218
+
contact_data_zambia<-socialmixr::contact_matrix(
179
219
survey=zambia_sa_survey,
220
+
countries="Zambia", # key argument
180
221
age.limits= c(0, 20),
181
222
symmetric=TRUE
182
223
)
@@ -191,27 +232,37 @@ Removing participants that have contacts without age information. To change this
191
232
```
192
233
193
234
```r
235
+
# Print the contact matrix for Zambia only
194
236
contact_data_zambia
195
237
```
196
238
197
239
```output
198
240
$matrix
199
241
contact.age.group
200
242
age.group [0,20) 20+
201
-
[0,20) 3.643137 2.282138
202
-
20+ 1.795546 2.542346
243
+
[0,20) 3.650000 1.451168
244
+
20+ 1.988136 2.461856
203
245
204
246
$demography
205
247
age.group population proportion year
206
248
<char> <num> <num> <int>
207
-
1: [0,20) 28813173 0.4403347 2010
208
-
2: 20+ 36621532 0.5596653 2010
249
+
1: [0,20) 8006201 0.5780636 2010
250
+
2: 20+ 5843835 0.4219364 2010
209
251
210
252
$participants
211
253
age.group participants proportion
212
254
<char> <int> <num>
213
-
1: [0,20) 255 0.07535461
214
-
2: 20+ 3129 0.92464539
255
+
1: [0,20) 180 0.08490566
256
+
2: 20+ 1940 0.91509434
257
+
```
258
+
259
+
```r
260
+
# Print the vector of population size for {epidemics}
261
+
contact_data_zambia$demography$population
262
+
```
263
+
264
+
```output
265
+
[1] 8006201 5843835
215
266
```
216
267
:::::::::::::::::::::::::::::::::
217
268
@@ -315,7 +366,7 @@ Normalisation can be performed by the function `contact_matrix()` in `{socialmix
0 commit comments