Skip to content

Commit db4c182

Browse files
committed
make contact matrix a challenge
1 parent e5fac0a commit db4c182

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

episodes/simulating-transmission.Rmd

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Learners should familiarise themselves with following concept dependencies befor
4545

4646
Install packages if their are not already installed
4747

48-
```{r, eval = FALSE}
49-
if(!require("pak")) install.packages("pak")
48+
```r
49+
if (!base::require("pak")) install.packages("pak")
5050
pak::pak(c("epidemics", "socialmixr", "tidyverse"))
5151
```
5252

@@ -266,37 +266,38 @@ A contact matrix represents the average number of contacts between individuals i
266266

267267
## Load contact and population data
268268

269-
Using the R package `socialmixr`, run the following lines of R code to obtain the contact matrix for the United Kingdom for the year age bins:
269+
Using the R package `socialmixr`, obtain the contact matrix for the United Kingdom for the year age bins:
270270

271271
+ age between 0 and 20 years,
272272
+ age between 20 and 40,
273273
+ 40 years and over.
274274

275-
```r
276-
polymod <- socialmixr::polymod
277-
contact_data <- socialmixr::contact_matrix(
278-
survey = polymod,
279-
countries = "United Kingdom",
280-
age.limits = c(0, 20, 40),
281-
symmetric = TRUE
282-
)
283-
# prepare contact matrix
284-
contact_matrix <- t(contact_data$matrix)
285-
contact_matrix
286-
```
275+
Use the survey available at `socialmixr::polymod`
276+
277+
:::::::::::::::: hint
278+
279+
+ Complete tutorial on [Contact matrices](../episodes/contact-matrices.md).
280+
281+
::::::::::::::::
287282

288283
:::::::::::::::::::::::: solution
289284

290-
```{r polymod_uk, echo = FALSE, message = FALSE}
285+
```{r polymod_uk, echo = TRUE, message = FALSE}
286+
# Access the contact survey data
291287
polymod <- socialmixr::polymod
288+
289+
# Generate the contact matrix
292290
contact_data <- socialmixr::contact_matrix(
293291
polymod,
294292
countries = "United Kingdom",
295293
age.limits = c(0, 20, 40),
296294
symmetric = TRUE
297295
)
296+
298297
# prepare contact matrix
299298
contact_matrix <- t(contact_data$matrix)
299+
300+
# print
300301
contact_matrix
301302
```
302303

0 commit comments

Comments
 (0)