knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(conmat)

The primary goal of the conmat package is to be able to get a contact matrix for a given age population. It was initially written for work done in Australia, and so the initial focus was on cleaning and extracting data from the Australian Bureau of Statistics.

This vignette focusses on using other data sources with conmat.

We can use some other functions from socialmixr to extract similar estimates for different populations in different countries.

We could extract some data from Italy using the socialmixr R package

library(socialmixr)

italy_2005 <- wpp_age("Italy", "2005")

head(italy_2005)

We can then convert this data into a conmat_population object and use it in extrapolate_polymod

italy_2005_pop <- as_conmat_population(
  data = italy_2005,
  age = lower.age.limit,
  population = population
)
age_breaks_0_80_plus <- c(seq(0, 80, by = 5), Inf)
italy_contact <- extrapolate_polymod(
  population = italy_2005_pop,
  age_breaks = age_breaks_0_80_plus
)

italy_contact

Creating a next generation matrix (NGM)

To create a next generation matrix, you can use either a conmat population object, or setting prediction matrices, like so:

# using a conmat population object
italy_2005_ngm <- generate_ngm(
  italy_2005_pop,
  age_breaks = age_breaks_0_80_plus,
  R_target = 1.5
)

italy_2005_ngm

# using a setting prediction matrix
italy_2005_ngm_polymod <- generate_ngm(
  italy_contact,
  age_breaks = age_breaks_0_80_plus,
  R_target = 1.5
)

italy_2005_ngm_polymod

# these are the same
identical(italy_2005_ngm, italy_2005_ngm_polymod)

Applying vaccination to an NGM

We can then take a next generation matrix and apply vaccination data, such as the provided vaccination_effect_example_data dataset.

vaccination_effect_example_data

ngm_italy_vacc <- apply_vaccination(
  ngm = italy_2005_ngm,
  data = vaccination_effect_example_data,
  coverage_col = coverage,
  acquisition_col = acquisition,
  transmission_col = transmission
)

ngm_italy_vacc


njtierney/conmat documentation built on April 17, 2025, 10:27 p.m.