R/decomposition.R
decompose_life_expectancy.RdAttributes the difference in life expectancy at birth (e0) between
two life tables to age-specific contributions, using either Arriaga's
(1984) or Pollard's (1988) method. Arriaga's is an exact discrete
decomposition: sum(contribution) recovers e2(0) - e1(0) exactly.
Pollard's is exact in continuous time; here each closed single-year
interval is integrated with the midpoint rule and the open interval
exactly under its constant hazard, so sum(contribution) differs from
e2(0) - e1(0) by a small discretisation residual. The residual is
returned as an attribute so it can be reported and checked against a
tolerance; treat Arriaga's method (the default) as the primary result
and Pollard's as a cross-check. Use this to answer "how much
of the life-expectancy gap
between province A and B (or between year Y1 and Y2) comes from
mortality at each age?" - complementing life_expectancy_summary()/
life_expectancy(), which report e0/e65 but don't explain why
two values differ.
decompose_life_expectancy(lt1, lt2, method = c("arriaga", "pollard"))A single life table (the "before"/reference table) - one
province-year-sex slice of build_life_tables()'s fltper,
mltper, or bltper (or build_life_table()'s direct output).
Must have one row per age, sorted or unsorted, with columns age,
mx, lx, Lx, Tx, ex.
The "after"/comparison life table, same shape as lt1,
over the same set of ages as lt1.
"arriaga" (default) or "pollard".
A tibble with age, contribution (years of the e2(0) - e1(0) gap attributable to mortality differences at that age;
positive means that age group contributed to a gain from lt1 to
lt2). Attributes e0_difference (the actual e2(0) - e1(0)) and
residual (e0_difference - sum(contribution), zero up to rounding
for Arriaga).
age <- 0:100
lt1 <- build_life_table(
data.frame(age = age, mx = 0.0004 * exp(0.075 * age)), "female"
)
lt2 <- build_life_table(
data.frame(age = age, mx = 0.0003 * exp(0.070 * age)), "female"
)
decomp <- decompose_life_expectancy(lt1, lt2)
sum(decomp$contribution)
#> [1] 7.522332
lt2$ex[1] - lt1$ex[1]
#> [1] 7.522332