Life tables: A super brief introduction

A life table is just one way of summarizing a cohort’s mortality experience. Below a simple way to build a life table using R.

dat <- read.csv("frmales85.csv", sep = ",", header = T)
# length of intervals
dat$n <- c(diff(dat$x), NA)
# number of intervals
max <- length(dat$x)
# age 85 is an open interval
dat
##     x     nNx   nDx   nax  n
## 1   0  379985  3741 0.087  1
## 2   1 1559722   770 1.500  4
## 3   5 1896295   532 2.500  5
## 4  10 2160190   673 2.966  5
## 5  15 2179837  2138 2.769  5
## 6  20 2159556  3432 2.574  5
## 7  25 2106750  3291 2.512  5
## 8  30 2147845  3657 2.586  5
## 9  35 2165387  4956 2.657  5
## 10 40 1516952  5269 2.697  5
## 11 45 1498630  8654 2.695  5
## 12 50 1552746 14490 2.663  5
## 13 55 1476770 20831 2.625  5
## 14 60 1350479 26805 2.601  5
## 15 65  722430 20233 2.615  5
## 16 70  842589 38315 2.598  5
## 17 75  636848 46903 2.538  5
## 18 80  372059 44443 2.466  5
## 19 85  175169 37759 4.639 NA
# age-specific mortality rates assuming $_nM_x=_nm_x$
dat$nmx <- dat$nDx/dat$nNx
# age-specific probability to die
dat$nqx <- (dat$n * dat$nmx)/(1 + (dat$n - dat$nax) * dat$nmx)
dat$nqx[max] <- 1
dat$npx <- 1 - dat$nqx
# definition of radix
radix <- 100000
# easy way to get lx without a loop
dat$lx <- radix * c(1, cumprod(dat[1:max - 1, "npx"]))
dat$ndx <- dat$lx * dat$nqx
dat[, c(-2, -3)]
##     x   nax  n      nmx     nqx   npx     lx   ndx
## 1   0 0.087  1 0.009845 0.00976 0.990 100000   976
## 2   1 1.500  4 0.000494 0.00197 0.998  99024   195
## 3   5 2.500  5 0.000281 0.00140 0.999  98829   139
## 4  10 2.966  5 0.000312 0.00156 0.998  98690   154
## 5  15 2.769  5 0.000981 0.00489 0.995  98537   482
## 6  20 2.574  5 0.001589 0.00792 0.992  98055   776
## 7  25 2.512  5 0.001562 0.00778 0.992  97278   757
## 8  30 2.586  5 0.001703 0.00848 0.992  96522   818
## 9  35 2.657  5 0.002289 0.01138 0.989  95703  1089
## 10 40 2.697  5 0.003473 0.01723 0.983  94614  1630
## 11 45 2.695  5 0.005775 0.02849 0.972  92984  2649
## 12 50 2.663  5 0.009332 0.04566 0.954  90334  4125
## 13 55 2.625  5 0.014106 0.06824 0.932  86209  5883
## 14 60 2.601  5 0.019849 0.09473 0.905  80326  7609
## 15 65 2.615  5 0.028007 0.13127 0.869  72717  9545
## 16 70 2.598  5 0.045473 0.20498 0.795  63171 12949
## 17 75 2.538  5 0.073649 0.31172 0.688  50223 15656
## 18 80 2.466  5 0.119451 0.45848 0.542  34567 15848
## 19 85 4.639 NA 0.215558 1.00000 0.000  18719 18719
# Lx for the open interval
dat$nLx <- dat$lx * dat$n - (dat$n - dat$nax) * dat$ndx
dat$nLx[max] <- dat$lx[max]/dat$nmx[max]
dat$Tx <- rev(cumsum(rev(dat$nLx)))
dat$ex <- dat$Tx/dat$lx
dat[, c(-2:-6)]
##     x     nqx   npx     lx   ndx    nLx      Tx    ex
## 1   0 0.00976 0.990 100000   976  99109 7131028 71.31
## 2   1 0.00197 0.998  99024   195 395609 7031919 71.01
## 3   5 0.00140 0.999  98829   139 493798 6636310 67.15
## 4  10 0.00156 0.998  98690   154 493140 6142512 62.24
## 5  15 0.00489 0.995  98537   482 491608 5649372 57.33
## 6  20 0.00792 0.992  98055   776 488390 5157764 52.60
## 7  25 0.00778 0.992  97278   757 484509 4669374 48.00
## 8  30 0.00848 0.992  96522   818 480632 4184865 43.36
## 9  35 0.01138 0.989  95703  1089 475964 3704232 38.71
## 10 40 0.01723 0.983  94614  1630 469315 3228268 34.12
## 11 45 0.02849 0.972  92984  2649 458812 2758953 29.67
## 12 50 0.04566 0.954  90334  4125 442031 2300141 25.46
## 13 55 0.06824 0.932  86209  5883 417074 1858110 21.55
## 14 60 0.09473 0.905  80326  7609 383376 1441035 17.94
## 15 65 0.13127 0.869  72717  9545 340818 1057660 14.54
## 16 70 0.20498 0.795  63171 12949 284755  716841 11.35
## 17 75 0.31172 0.688  50223 15656 212570  432087  8.60
## 18 80 0.45848 0.542  34567 15848 132677  219516  6.35
## 19 85 1.00000 0.000  18719 18719  86839   86839  4.64



blog comments powered by Disqus