Skip to content

Commit 40a9e0a

Browse files
committed
differences for PR #104
1 parent fdb7e72 commit 40a9e0a

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

.DS_Store

-6 KB
Binary file not shown.

contact-matrices.md

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Then we can obtain the contact matrix for the age categories we want by specifyi
8989

9090

9191
``` r
92-
contact_data <- contact_matrix(
92+
contact_data <- socialmixr::contact_matrix(
9393
survey = polymod,
9494
countries = "United Kingdom",
9595
age.limits = c(0, 20, 40),
@@ -151,32 +151,73 @@ If `symmetric` is set to TRUE, the `contact_matrix()` function will internally u
151151

152152
::::::::::::::::::::::::::::::::::::::::::::::::
153153

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()`
155155

156156

157157
``` r
158-
zambia_sa_survey <- get_survey("https://doi.org/10.5281/zenodo.3874675")
158+
# Access the contact survey data from Zenodo
159+
zambia_sa_survey <- socialmixr::get_survey("https://doi.org/10.5281/zenodo.3874675")
159160
```
160161

162+
:::::::::::::::::: spoiler
163+
164+
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}
171+
socialmixr::list_surveys() %>%
172+
dplyr::filter(stringr::str_detect(title, "Zambia")) %>%
173+
dplyr::pull(url)
174+
```
175+
176+
::::::::::::::::::
161177

162178

163179
::::::::::::::::::::::::::::::::::::: challenge
164180

165181
## Zambia contact matrix
166182

167-
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:
168187

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+
:::::::::::::::::::::
171210

172211
::::::::::::::::::::::::::::::::::::::::::::::::
173212

174213
:::::::::::::::::::::::: instructor
175214

176215

177216
``` r
178-
contact_data_zambia <- contact_matrix(
217+
# Generate the contact matrix for Zambia only
218+
contact_data_zambia <- socialmixr::contact_matrix(
179219
survey = zambia_sa_survey,
220+
countries = "Zambia", # key argument
180221
age.limits = c(0, 20),
181222
symmetric = TRUE
182223
)
@@ -191,27 +232,37 @@ Removing participants that have contacts without age information. To change this
191232
```
192233

193234
``` r
235+
# Print the contact matrix for Zambia only
194236
contact_data_zambia
195237
```
196238

197239
``` output
198240
$matrix
199241
contact.age.group
200242
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
203245
204246
$demography
205247
age.group population proportion year
206248
<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
209251
210252
$participants
211253
age.group participants proportion
212254
<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
215266
```
216267
:::::::::::::::::::::::::::::::::
217268

@@ -315,7 +366,7 @@ Normalisation can be performed by the function `contact_matrix()` in `{socialmix
315366

316367

317368
``` r
318-
contact_data_split <- contact_matrix(
369+
contact_data_split <- socialmixr::contact_matrix(
319370
survey = polymod,
320371
countries = "United Kingdom",
321372
age.limits = c(0, 20, 40),

md5sum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"config.yaml" "a0c04c1d43ce0640c3ea333b140e89c8" "site/built/config.yaml" "2025-07-15"
55
"index.md" "32bc80d6f4816435cc0e01540cb2a513" "site/built/index.md" "2025-07-15"
66
"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2025-07-15"
7-
"episodes/contact-matrices.Rmd" "58cf0b0b77bddf65087de009f15466e0" "site/built/contact-matrices.md" "2025-07-23"
7+
"episodes/contact-matrices.Rmd" "a6496abb6001b71f1155a4f0524b2f8a" "site/built/contact-matrices.md" "2025-07-23"
88
"episodes/simulating-transmission.Rmd" "f9c2d01ff04250732a0c24b06cfac63f" "site/built/simulating-transmission.md" "2025-07-23"
99
"episodes/model-choices.Rmd" "aa195e66455fb6a97b4930fd08c08001" "site/built/model-choices.md" "2025-07-15"
1010
"episodes/modelling-interventions.Rmd" "0f695729b90387ec3449f9c46c9b4ae7" "site/built/modelling-interventions.md" "2025-07-15"

0 commit comments

Comments
 (0)