lifetable | R Documentation |
Given a data.table
with at least two of variables mx, ax, and
qx, compute a complete life table. This is a helper function that combines
many other functions in this package to calculate px, lx, dx, Tx, nLx,
and ex.
lifetable(
dt,
id_cols,
preserve_u5 = FALSE,
assert_na = TRUE,
format_long = FALSE
)
dt |
[ |
id_cols |
[ |
preserve_u5 |
[ |
assert_na |
[ |
format_long |
[ |
Note that while it typically takes estimation techniques to arrive at mx, ax, and qx from empirical data, the solution of the remaining life table parameters as compiled in this function is deterministic once mx, ax, and qx are specified. The steps of this solution are as follows:
Calculate mx, ax, or qx if one of the three is missing
Recalculate qx if all three of mx, ax, and qx are provided to confirm
the three agree. See mx_qx_ax_conversions
functions. Will not recalculate
under-5 qx if preserve_u5
is true.
Compute px from qx
gen_lx_from_qx()
gen_dx_from_lx()
gen_nLx()
gen_Tx()
gen_ex()
Replace terminal (age_end = Inf) ax with terminal ex
[data.table()
]
Input life table(s) with additional columns: px, lx, dx, Tx, nLx, ex.
Or, if format_long
is TRUE, additional columns 'life_table_parameter'
and 'value' with data long on life table parameter.
dt <- data.table::data.table(
sex = rep("both", 4),
age_start = c(0, 5, 10, 15),
age_end = c(5, 10, 15, Inf),
mx = c(0.1, 0.2, 0.3, 0.4),
ax = c(2.5, 2.5, 2.5, 2.5)
)
dt <- lifetable(dt, id_cols = c("sex", "age_start", "age_end"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.