Learn R Programming

socialmixr (version 0.7.0)

align_ages: Align a population table to a contact matrix's grouping levels

Description

Aligns a population table to the groupings of a contact matrix produced by compute_matrix(), returning the survey_pop data frame that symmetrise(), split_matrix() and per_capita() expect.

The age grouping is rebinned to the matrix's age groups (via rebin_ages(), summing) within each combination of the other groupings; the population must be at least as fine as the matrix's age groups, otherwise rebin_ages() errors. Categorical groupings are aggregated to the matrix's levels by exact name; a level not present in the matrix is an error.

Usage

align_ages(pop, x)

Value

a data frame with one column per grouping (named after the grouping, holding the matrix's levels) plus a population column, ready to pass as survey_pop

Arguments

pop

a data frame with a population column and one column per grouping: an age column of age-group labels for the age grouping, and a column named after each categorical grouping holding its levels.

x

a contact_matrix object as returned by compute_matrix()

Examples

Run this code
data(polymod)
result <- polymod |>
  (\(s) s[country == "United Kingdom"])() |>
  assign_age_groups(age_limits = c(0, 5, 15)) |>
  compute_matrix()
uk_pop <- data.frame(
  age = limits_to_age_groups(0:80, notation = "brackets"),
  population = rep(1e5, 81)
)
result |> symmetrise(survey_pop = align_ages(uk_pop, result))

Run the code above in your browser using DataLab