View source: R/export-DataPreprocessing.R
as.APC.NA.df | R Documentation |
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.
as.APC.NA.df(data, stratify_by, age, period, cohort, include.random = FALSE)
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. |
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
if Region
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, and NA
otherwise.
If include.random = TRUE
, a column named random
with unique integer indices.
The rows are ordered primarily by the stratification variable levels. This is useful for defining random components in MAPC models.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.