Scale granular qx values to be consistent with aggregate age interval qx values already present in the data.

scale_qx(dt, id_cols, missing_dt_severity = "stop")

Arguments

dt

[data.table()]
Data to be aggregated.

  • Must only include columns 'qx' and those specified in id_cols

  • Must include 'age_start' and 'age_end' columns

id_cols

[character()]
ID columns that uniquely identify each row of dt.

missing_dt_severity

[character(1)]
What should happen when dt is missing levels of col_stem that prevent aggregation or scaling from occurring? Can be either 'skip', 'stop', 'warning', 'message', or 'none'. Default is 'stop'. See section on 'Severity Arguments' for more information.

Value

[data.table()]
Scaled qx values, has id_cols and 'qx' columns for all age groups.

Details

Convert to px-space, scale up age-hierarchy so that granular px values multiply to aggregate px values, convert back to qx-space. scale_qx() is a wrapper for hierarchyUtils::scale().

This function is unique to aggregating and scaling qx over age because of the dependence between age and the definition of qx. Aggregation of qx across sex, location, or other variables should be done by first aggregating ax and mx as population-weighted means (can use hierarchyUtils::agg() and hierarchyUtils::scale() directly), then recalculating qx from mx and ax (see mx_ax_to_qx()).

See also

Vignette on scaling multiplicative aggregates in hierarchyUtils.

Examples

# scale qx up single-year to abridged u5 hierarchy
dt <- data.table::data.table(
  sex = "male",
  qx = c(0.03, 0.015, 0.005, 0.004, 0.001, 0.03, 0.05),
  age_start = c(0, 1, 2, 3, 4, 1, 0),
  age_end = c(1, 2, 3, 4, 5, 5, 5)
)
dt <- scale_qx(dt, id_cols = c("sex", "age_start", "age_end"))
#> Scaling age
#> Scaling 1 of 2: [0, 5)
#> Scaling 2 of 2: [1, 5)