
Summarize Age Distribution for Exposure or Response Groups
Source:R/population_analysis.R
table_age_distribution.RdCreates a summary table of population counts and age statistics (minimum, median, mean, and maximum) for either the "exposure" or "response" group. Optionally, it can also include subgroups for a more detailed breakdown.
Arguments
- data
A data frame containing columns `exp.GROUP`, `resp.GROUP`, `exp.AGE_DG`, and `resp.AGE_DG`. These are expected to represent exposure/response group labels and ages at diagnosis.
- group
A character string, either `"exposure"` or `"response"`, indicating which group to summarize. Defaults to `"exposure"`.
- subgroups
Logical. If `TRUE`, adds subgroup statistics (cross-group summaries). Defaults to `FALSE`.
Value
A data frame summarizing the population size (`pop_n`) and age statistics:
pop_n- Population countage_min- Minimum age at diagnosisage_median- Median age at diagnosisage_mean- Mean age at diagnosisage_max- Maximum age at diagnosis
When `subgroups = TRUE`, an additional "All" row summarizes the entire group.