generate_apc_lincombs: Generate Age-Period-Cohort Linear Combinations for INLA

View source: R/export-ModelEstimation.R

generate_apc_lincombsR Documentation

Generate Age-Period-Cohort Linear Combinations for INLA

Description

Constructs a set of linear combinations (contrasts) for age, period, and/or cohort effects across different strata, relative to a specified reference strata, suitable for use with inla.make.lincomb from the INLA package.

Usage

generate_apc_lincombs(
  apc_format,
  data,
  strata,
  reference_strata,
  age = "age",
  period = "period",
  cohort = "cohort"
)

Arguments

apc_format

Character string containing any combination of "a", "p", "c":

"a"

include age contrasts

"p"

include period contrasts

"c"

include cohort contrasts

e.g. "ap" to generate age and period contrasts only.

data

A data.frame containing the variables specified by age, period, cohort, and strata. The age, period, and cohort variables must be integer-valued (or coercible to integer).

strata

String giving the name of the factor column in data that defines strata.

reference_strata

String indicating which level of strata should be used as the reference.

age

String name of the column in data containing age indices (default "age").

period

String name of the column in data containing period indices (default "period").

cohort

String name of the column in data containing cohort indices (default "cohort").

Details

For each specified dimension (a, p, c), the function loops over all unique values of age, period, or cohort in the data, and over all strata levels except the reference. It then constructs a contrast that subtracts the effect in the reference stratum from the effect in the other strata at each index.

Value

A named list of linear combination objects as returned by inla.make.lincomb() (INLA function). Each element corresponds to one contrast, with names of the form “Age = x, Strata = y vs ref”, “Period = x, Strata = y vs ref”, or “Cohort = x, Strata = y vs ref”, depending on apc_format.


MAPCtools documentation built on June 25, 2025, 5:09 p.m.