Convenience wrapper for a single province: builds a period life table
(Andreev-Kingkade a0, Kannisto old-age smoothing, per HMD Methods
Protocol V6) from already-computed central death rates and extracts
life expectancy at birth (e0) and at age 65 (e65) for every year
present. Operates on compute_death_rates()'s mx_1x1 output
directly — data already retrieved/computed via the mortality
pipeline — the same way plot_lexis_diagram() does, rather than
requiring build_life_tables() to be run for every province first
and life_expectancy_summary() applied afterwards.
life_expectancy(mx_df, province, sex = c("total", "female", "male"))Output of the mx_1x1 element of compute_death_rates()
(rates mx_*, deaths d_*, and exposures e_* for all three sexes,
which build_life_tables() needs for Kannisto smoothing).
Character, a province name (regular expressions
allowed, matched against province_name — same convention as
province in plot_lexis_diagram()). Must match exactly one
province.
Character, one of "total", "female", "male".
A tibble with nuts3_code, province_name, year, e0,
e65, sex.
age <- 0:100
e <- 1e5
m <- 0.0003 * exp(0.07 * age)
mx <- tibble::tibble(
nuts3_code = "ES111", province_name = "A Coruna", year = 2023, age = age,
mx_female = m, mx_male = 1.2 * m, mx_total = 1.1 * m,
d_female = m * e, d_male = 1.2 * m * e, d_total = 2.2 * m * e,
e_female = e, e_male = e, e_total = 2 * e
)
life_expectancy(mx, province = "A Coruna", sex = "female")
#> All 3 life tables passed validation.
#> # A tibble: 1 × 6
#> nuts3_code province_name year e0 e65 sex
#> <chr> <chr> <dbl> <dbl> <dbl> <chr>
#> 1 ES111 A Coruna 2023 70.5 15.1 female