as.APC.NA.df {MAPCtools} | R Documentation |
Create NA structure across age, period and cohort groups based on strata
Description
Creates a data frame where age, period, and cohort values are placed into
columns specific to their stratum (defined by stratify_var
), with other
strata combinations marked as NA. This structure is often useful for
specific modeling approaches, like certain Age-Period-Cohort (APC) models.
Optionally includes unique indices for random effects.
Usage
as.APC.NA.df(data, stratify_by, age, period, cohort, include.random = FALSE)
Arguments
data |
Data frame with age, period, cohort, and stratification columns. |
stratify_by |
Stratification variable column. This column will be used to create the stratum-specific NA structure. It should ideally be a factor or character vector. |
age |
Age column in |
period |
Name of the period column (must be a numeric/integer column). |
cohort |
Name of the cohort column (must be a numeric/integer column). |
include.random |
Logical. Whether to include a unique index ('random') for each combination of age, period, and stratum, potentially for use as random effect identifiers in models. Defaults to FALSE. |
Value
A data frame containing the original age
, period
,
cohort
, and stratify_by
columns, plus:
Dummy indicator columns for each level of
stratify_by
(e.g.,Region_North
,Region_South
ifRegion
was a stratifying variable).Stratum-specific age, period, and cohort columns (e.g.,
age_Region_North
,period_Region_North
,cohort_Region_North
), containing the respective value if the row belongs to that stratum, andNA
otherwise.If
include.random = TRUE
, a column namedrandom
with unique integer indices. The rows are ordered primarily by the stratification variable levels. This is useful for defining random components in MAPC models.