Add ax onto a data.table for ages <1 and 1-4 years, with algorithm based on under-1 qx.
gen_u5_ax_from_qx(dt, id_cols)
[data.table()
]
Columns:
'age_start' with values 0 (for under-1) and 1 (for 1-4). Other ages
permitted but will result in NA output for ax or unchanged ax if ax in
input dt
.
'age_end' with values 1 (for under-1) and 5 (for 1-4).
'sex' where values must be 'male', 'female', or 'both'
'qx' for mortality rate
All additional columns from 'id_cols'
[character()
]
Columns that uniquely identify
observations in dt
. Must include 'age_start', 'age_end', and 'sex'.
Modifies dt
in place with 'ax' column added on.
Takes a data.table
with 'age_start', 'age_end', 'sex', and
infant probability of death ('qx') and adds a column 'ax'. There is no
absolute relationship between ax and qx without mx also known. Instead,
this function performs an inverse calculation of the calculation described
for gen_u5_ax_from_mx()
which estimates ax from 1m0. Since
the inverse involves a quadratic, we use stats::uniroot()
to find the
solution.
Preston Samuel H, Patrick H, Michel G. Demography: measuring and modeling population processes. MA: Blackwell Publishing. 2001.
dt <- data.table::data.table(
age_start = c(0, 1),
age_end = c(1, 5),
qx = c(0.0846, 0.3658),
sex = c("male", "male")
)
gen_u5_ax_from_qx(dt, id_cols = c("age_start", "age_end", "sex"))
#> age_start age_end qx sex ax
#> <num> <num> <num> <char> <num>
#> 1: 0 1 0.0846 male 0.286650
#> 2: 1 5 0.3658 male 1.397466