gen_lifetable_parameters | R Documentation |
These functions perform life table calculations, to add selected life table parameters from others, using established demographic relationships.
gen_lx_from_qx(dt, id_cols, assert_na = T)
gen_qx_from_lx(dt, id_cols, assert_na = T)
gen_dx_from_lx(dt, id_cols, assert_na = T)
gen_nLx(dt, id_cols, assert_na = T)
gen_Tx(dt, id_cols, assert_na = T)
gen_ex(dt, assert_na = T)
dt |
[
|
id_cols |
[ |
assert_na |
[ |
Parameter definitions:
For an age interval x to x+n:
mx = mortality rate (deaths / person-years)
qx = probability of death, conditional on survival to x-th birthday
ax = average years lived of those who died in the age interval
dx = number (or proportion of cohort) who died in the age interval
lx = number (or proportion of cohort) alive at the beginning of the age interval
ex = life expectancy, expected value for years lived after age x
Tx = total person-years lived beyond age x
nLx = total person-years lived in interval
gen_lx_from_qx: Use probability of death (qx) to get the proportion of survivors in the beginning of an age group (lx). l0 = 1; lx for ages > 0 is lx for previous age group times the probability of surviving the previous age group.
gen_qx_from_lx: Use survival proportion (lx) at age x and x+n to get
probability of death between x and x+n (qx). This relationship is an
algebraic equivalent to the gen_lx_from_qx
relationship as described.
Terminal age qx is set to 1.
gen_dx_from_lx: Calculate the proportion dying between age x and x+n (dx) as the difference between the proportion surviving (lx) at age x and the proportion surviving at age x+n. In the terminal age group all survivors die in the age group, so dx = lx.
gen_nLx: nLx is calculated as the sum of years lived by survivors and years lived by those who die between ages x and x+n. The first component is n times l(x+n). The second component is ax * dx. For terminal ages, assume that average person years lived equals number at the start of the age group divided by the mortality rate.
gen_Tx: Person-years lived above age x (Tx) is the cumulative sum of person-years lived by people in each age interval above age x (nLx). For the terminal age group, Tx = nLx.
gen_ex: Life expectancy (ex) at age x is based on person-years lived above the age group (Tx) and proportion of people alive at the start of age group (lx): ex = Tx / lx.
dt
with column added for new life table parameter. Modifies
data.tables in place.
mx_qx_ax_conversions
lifetable
vignette("introduction_to_life_tables", package = "demCore")
dt <- data.table::data.table(
sex = rep("both", 4),
age_start = c(0, 5, 10, 15),
age_end = c(5, 10, 15, Inf),
age_length = c(5, 5, 5, Inf),
mx = c(0.1, 0.2, 0.3, 0.4),
ax = c(2.5, 2.5, 2.5, 2.5)
)
dt[, qx := mx_ax_to_qx(mx, ax, age_length)]
gen_lx_from_qx(dt, id_cols = c("sex", "age_start", "age_end"))
gen_dx_from_lx(dt, id_cols = c("sex", "age_start", "age_end"))
gen_nLx(dt, id_cols = c("sex", "age_start", "age_end"))
gen_Tx(dt, id_cols = c("sex", "age_start", "age_end"))
gen_ex(dt)
gen_qx_from_lx(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.