scale_qx: Scale qx values over age

View source: R/scale_qx.R

scale_qxR Documentation

Scale qx values over age

Description

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

Usage

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.

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()).

Value

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

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"))


ihmeuw-demographics/demCore documentation built on Feb. 24, 2024, 11:05 p.m.