Skip to contents

Computes a contact matrix from a contact_survey that has been processed by assign_age_groups() and optionally weigh(). This is the final step in the pipeline workflow.

For post-processing, pipe the result into symmetrise(), split_matrix(), or per_capita().

Usage

compute_matrix(survey, counts = FALSE, weight_threshold = NULL)

Arguments

survey

a survey() object with age groups assigned (via assign_age_groups())

counts

whether to return counts instead of means

weight_threshold

numeric; if provided, weights above this threshold are capped to the threshold value and then re-normalised (default NULL)

Value

a list with elements matrix and participants

Examples

data(polymod)
polymod |>
  assign_age_groups(age_limits = c(0, 5, 15)) |>
  compute_matrix()
#> $matrix
#>          contact.age.group
#> age.group     [0,5)   [5,15)       15+
#>    [0,5)  2.2370031 1.556575  6.434251
#>    [5,15) 0.5252009 8.948137  7.100804
#>    15+    0.3478261 1.019710 11.705507
#> 
#> $participants
#>    age.group participants proportion
#>       <char>        <int>      <num>
#> 1:     [0,5)          654 0.09085857
#> 2:    [5,15)         1369 0.19019172
#> 3:       15+         5175 0.71894971
#>