Skip to contents

Makes a contact matrix symmetric so that \(c_{ij} N_i = c_{ji} N_j\), where \(c_{ij}\) is the (i, j) entry and \(N_i\) is the population of age group i. This is done by replacing each pair with half their sum, weighted by population size.

Usage

symmetrise(x, survey_pop, symmetric_norm_threshold = 2, ...)

Arguments

x

a list as returned by compute_matrix(), with elements matrix and participants

survey_pop

a data frame with columns lower.age.limit and population (e.g. from wpp_age())

symmetric_norm_threshold

threshold for the normalisation factor before issuing a warning (default 2)

...

passed to pop_age() for interpolation

Value

x with $matrix replaced by the symmetrised version

Examples

data(polymod)
pop <- wpp_age("United Kingdom", 2005)
polymod |>
  (\(s) s[country == "United Kingdom"])() |>
  assign_age_groups(age_limits = c(0, 5, 15)) |>
  compute_matrix() |>
  symmetrise(survey_pop = pop)
#> 
#> ── Contact matrix (3 age groups) ──
#> 
#> Ages: "[0,5)", "[5,15)", and "[15,Inf)"
#> Participants: 1011
#> 
#>           contact.age.group
#> age.group      [0,5)   [5,15) [15,Inf)
#>   [0,5)    1.9157895 1.281846 5.558271
#>   [5,15)   0.5994315 7.946078 7.428739
#>   [15,Inf) 0.3882175 1.109550 9.594101