You can install lifequal
by running:
install.packages("devtools") devtools::install_github("jschoeley/lifequal")
lifequal
lets you calculate three measures of lifespan equality from a life-table:
1) ExDagger(x, ex, ax)
Life expectancy lost by those who die in age interval [x, x+w)
2) EDagger(dx, exdagger, radix)
Total life expectancy lost due to death
3) KeyfzEntro(edagger, e0)
Keyfitz's entropy
They are defined as follows,
Measure Definition
Start of age interval $x$
Width of age interval starting at $x$ $w_x$
Start of last age interval $\omega$
Average time spent in age interval $a_x$ $[x, x+wx)$ when dying in that interval
Deaths in age interval $[x, x+w_x)$ $d_x$
Life-expectancy at age $x$ $e_x$
Life expectancy lost due to death in age $$e_x^\dagger = \begin{cases} \frac {a_x} {w_x}e_{x+w_x} + (1-\frac {a_x} {w_x}) e_x & x \neq \omega \ \frac{e_\omega + 1.4}{2} & x = \omega \ \end{cases}$$ interval $[x, x+w_x)$
Total life expectancy lost due to death $e^\dagger = \sum_{x=0}^{\omega} d_x e_x^\dagger$
library(lifequal) library(dplyr) library(ggplot2)
The analysis starts with a demographic life-table. We want 1) age intervals ordered from low to high, 2) no gaps between subsequent age intervals, 3) an open last age interval (e.g. 110+). Something like this:
# Swedish 1x1 period life-tables by period and sex
sweden1x1
First, we use ExDagger()
on each single life-table (separate by period and sex) to calculate the life expectancy lost in each age. We then summarise each life-table into a set of 3 numbers: Life expectancy at birth, total life years lost due to death (EDagger()
) and lifespan equality (KeyfzEntro()
). Note that we transform Keyfitz's Entropy by taking the negative log.
sweden1x1 %>% # ...for each single life-table... group_by(period, sex) %>% #...we calculate the life years lost in age x... mutate(exdagger = ExDagger(x, ex)) %>% # ...and then summarise each life-table into a set of 3 numbers: # e0: Life-expectancy at birth # edagger: Total life years lost due to death # keyfzentro: Lifespan equality summarise( e0 = ex[x == 0], edagger = EDagger(dx, exdagger, radix = 100000), keyfzentro = -log(KeyfzEntro(edagger, e0)) ) -> sweden1x1summary
The summarised life-tables look like this:
sweden1x1summary
For each life-table we plot the life expectancy at birth versus the lifespan equality.
plot_lifequal <- ggplot(sweden1x1summary, aes(x = e0, y = keyfzentro, color = sex)) + geom_point(size = 0.6, alpha = 0.5) + theme(aspect.ratio = 1) plot_lifequal
The same exercise as before, only now we deal with life-tables aggregated over multiple year period and age intervals.
# Swedish 5x5 period life-tables by period and sex
sweden5x5
The width of each age interval, $w_x$, is calculated by the ExDagger()
function on the basis of the differences between the age interval starting points x
.
sweden5x5 %>% # ...for each single life-table... group_by(period, sex) %>% #...we calculate the life years lost in age interval [x, x+wx)... mutate(exdagger = ExDagger(x, ex, ax)) %>% # ...and then summarise each life-table into a set of 3 numbers: # e0: Life-expectancy at birth # edagger: Total life years lost due to death # keyfzentro: Lifespan equality summarise( e0 = ex[x == 0], edagger = EDagger(dx, exdagger, radix = 100000), keyfzentro = -log(KeyfzEntro(edagger, e0)) ) -> sweden5x5summary
The summarised life-tables look like this:
sweden5x5summary
The aggregated life-tables follow the same trend as the single year life-tables.
plot_lifequal + geom_point(shape = 22, fill = "white", data = sweden5x5summary)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.