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
+67-14Lines changed: 67 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,75 @@ 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:
167
+
168
+
```r
169
+
library(socialmixr)
170
+
library(tidyverse)
171
+
172
+
# 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:
185
+
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}:
186
+
187
+
+ Get access to the survey from Zambia.
188
+
+ Generate a symmetric contact matrix for Zambia using the following age bins:
189
+
190
+
+[0,20)
191
+
+ 20+
192
+
193
+
+ Get access to the vector of `population` size per age bin from the `demography` dataset inside the contact matrix output.
194
+
195
+
::::::::::::::::::::: hint
196
+
197
+
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.
198
+
168
199
169
-
+[0,20)
170
-
+ 20+
200
+
```r
201
+
# Inspect the countries within the survey object
202
+
levels(zambia_sa_survey$participants$country)
203
+
```
204
+
205
+
```output
206
+
[1] "South Africa" "Zambia"
207
+
```
208
+
209
+
Similar to the code above, to access vector values within a dataframe, you can use the dollar-sign operator: `$`
210
+
211
+
:::::::::::::::::::::
171
212
172
213
::::::::::::::::::::::::::::::::::::::::::::::::
173
214
174
215
:::::::::::::::::::::::: instructor
175
216
176
217
177
218
```r
178
-
contact_data_zambia<- contact_matrix(
219
+
# Generate the contact matrix for Zambia only
220
+
contact_data_zambia<-socialmixr::contact_matrix(
179
221
survey=zambia_sa_survey,
222
+
countries="Zambia", # key argument
180
223
age.limits= c(0, 20),
181
224
symmetric=TRUE
182
225
)
@@ -191,27 +234,37 @@ Removing participants that have contacts without age information. To change this
191
234
```
192
235
193
236
```r
237
+
# Print the contact matrix for Zambia only
194
238
contact_data_zambia
195
239
```
196
240
197
241
```output
198
242
$matrix
199
243
contact.age.group
200
244
age.group [0,20) 20+
201
-
[0,20) 3.643137 2.282138
202
-
20+ 1.795546 2.542346
245
+
[0,20) 3.650000 1.451168
246
+
20+ 1.988136 2.461856
203
247
204
248
$demography
205
249
age.group population proportion year
206
250
<char> <num> <num> <int>
207
-
1: [0,20) 28813173 0.4403347 2010
208
-
2: 20+ 36621532 0.5596653 2010
251
+
1: [0,20) 8006201 0.5780636 2010
252
+
2: 20+ 5843835 0.4219364 2010
209
253
210
254
$participants
211
255
age.group participants proportion
212
256
<char> <int> <num>
213
-
1: [0,20) 255 0.07535461
214
-
2: 20+ 3129 0.92464539
257
+
1: [0,20) 180 0.08490566
258
+
2: 20+ 1940 0.91509434
259
+
```
260
+
261
+
```r
262
+
# Print the vector of population size for {epidemics}
263
+
contact_data_zambia$demography$population
264
+
```
265
+
266
+
```output
267
+
[1] 8006201 5843835
215
268
```
216
269
:::::::::::::::::::::::::::::::::
217
270
@@ -315,7 +368,7 @@ Normalisation can be performed by the function `contact_matrix()` in `{socialmix
0 commit comments