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: episodes/contact-matrices.Rmd
+49-8Lines changed: 49 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,7 @@ polymod <- socialmixr::polymod
89
89
Then we can obtain the contact matrix for the age categories we want by specifying `age.limits`.
90
90
91
91
```{r polymod_uk, echo = TRUE}
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),
@@ -121,34 +121,75 @@ If `symmetric` is set to TRUE, the `contact_matrix()` function will internally u
121
121
122
122
::::::::::::::::::::::::::::::::::::::::::::::::
123
123
124
-
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()`
124
+
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:
134
+
135
+
```r
136
+
library(socialmixr)
137
+
library(tidyverse)
138
+
139
+
# 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:
152
+
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}:
153
+
154
+
+ Get access to the survey from Zambia.
155
+
+ Generate a symmetric contact matrix for Zambia using the following age bins:
156
+
157
+
+[0,20)
158
+
+ 20+
159
+
160
+
+ Get access to the vector of `population` size per age bin from the `demography` dataset inside the contact matrix output.
137
161
138
-
+[0,20)
139
-
+ 20+
162
+
::::::::::::::::::::: hint
163
+
164
+
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.
165
+
166
+
```{r}
167
+
# Inspect the countries within the survey object
168
+
levels(zambia_sa_survey$participants$country)
169
+
```
170
+
171
+
Similar to the code above, to access vector values within a dataframe, you can use the dollar-sign operator: `$`
Normalisation can be performed by the function `contact_matrix()` in `{socialmixr}`. To obtain the normalised matrix we must specify that we want to split out the different components of the contact matrix using the argument `split = TRUE`. Then we can obtain the normalised matrix as follows:
0 commit comments