Skip to content

Commit a5150d6

Browse files
committed
differences for PR #104
1 parent dd0e7e6 commit a5150d6

3 files changed

Lines changed: 68 additions & 15 deletions

File tree

.DS_Store

-6 KB
Binary file not shown.

contact-matrices.md

Lines changed: 67 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,75 @@ 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(
160+
"https://doi.org/10.5281/zenodo.3874675"
161+
)
162+
```
163+
164+
:::::::::::::::::: spoiler
165+
166+
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}
173+
socialmixr::list_surveys() %>%
174+
dplyr::filter(stringr::str_detect(title, "Zambia")) %>%
175+
dplyr::pull(url)
159176
```
160177

178+
::::::::::::::::::
161179

162180

163181
::::::::::::::::::::::::::::::::::::: challenge
164182

165183
## Zambia contact matrix
166184

167-
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+
168199

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

172213
::::::::::::::::::::::::::::::::::::::::::::::::
173214

174215
:::::::::::::::::::::::: instructor
175216

176217

177218
``` r
178-
contact_data_zambia <- contact_matrix(
219+
# Generate the contact matrix for Zambia only
220+
contact_data_zambia <- socialmixr::contact_matrix(
179221
survey = zambia_sa_survey,
222+
countries = "Zambia", # key argument
180223
age.limits = c(0, 20),
181224
symmetric = TRUE
182225
)
@@ -191,27 +234,37 @@ Removing participants that have contacts without age information. To change this
191234
```
192235

193236
``` r
237+
# Print the contact matrix for Zambia only
194238
contact_data_zambia
195239
```
196240

197241
``` output
198242
$matrix
199243
contact.age.group
200244
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
203247
204248
$demography
205249
age.group population proportion year
206250
<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
209253
210254
$participants
211255
age.group participants proportion
212256
<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
215268
```
216269
:::::::::::::::::::::::::::::::::
217270

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

316369

317370
``` r
318-
contact_data_split <- contact_matrix(
371+
contact_data_split <- socialmixr::contact_matrix(
319372
survey = polymod,
320373
countries = "United Kingdom",
321374
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" "19856620d33f9b7f4e8ee312460494f1" "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)