Learn R Programming

socialmixr (version 0.7.0)

flatten: Flatten a multi-grouping contact matrix to its T x T form

Description

Returns the contact matrix in the flattened representation of Manna et al. — a T x T matrix where each axis enumerates the Cartesian product of grouping levels. For a single-grouping matrix this is the matrix itself.

Row/column names join the grouping levels with a colon, e.g. "[0,5):F" for the age group [0,5) combined with gender level F. The participant axes vary fastest in the first grouping (column-major reshape).

Usage

flatten(x)

Value

a numeric T x T matrix

Arguments

x

a contact_matrix object as returned by compute_matrix()

References

Manna A, Dall'Amico L, Tizzoni M, Karsai M, Perra N (2024). Generalized contact matrices allow integrating socioeconomic variables into epidemic models. Science Advances 10(41), eadk4606. tools:::Rd_expr_doi("10.1126/sciadv.adk4606")

Examples

Run this code
data(polymod)
polymod |>
  (\(s) s[country == "United Kingdom"])() |>
  assign_age_groups(age_limits = c(0, 5, 15)) |>
  compute_matrix(by = c("age", "gender")) |>
  flatten()

Run the code above in your browser using DataLab