@@ -45,8 +45,8 @@ Learners should familiarise themselves with following concept dependencies befor
4545
4646Install 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" )
5050pak :: 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
291287polymod <- socialmixr::polymod
288+
289+ # Generate the contact matrix
292290contact_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
299298contact_matrix <- t(contact_data$matrix)
299+
300+ # print
300301contact_matrix
301302```
302303
0 commit comments