# R code for migration expectancy (Rowland's textbook Chapter 11, Table 11.3) library(fmsb) migexpectable <- function(A1, A2, TP, Mov, lx) { MR <- Mov/TP Lx <- lifetable3(lx, 0.5, A2-A1+1)$Lx ENM <- MR*Lx CNM <- rev(cumsum(rev(ENM))) ME <- CNM/lx return(data.frame(Age=sprintf("%d-%d",A1,A2), TotalPop=TP, Movers=Mov, MigRate=MR, lx=lx, Lx=Lx, ExpectedMov=ENM, CumlativeMov=CNM, MigExp=ME)) } US1997 <- data.frame( A1 = c(1, 1:17*5), A2 = c(4, 1:16*5+4, 97), TP = c(15802, 20453, 19663, 19466, 17613, 18996, 20358, 22691, 21771, 18634, 15424, 12190, 10065, 9361, 8512, 6898, 4383, 2928), Mov = c(3552, 3526, 2755, 2864, 5607, 5442, 4267, 3568, 2570, 1798, 1242, 916, 574, 439, 389, 276, 186, 130), lx = c(99268, 99118, 99022, 98905, 98519, 98020, 97487, 96795, 95881, 94651, 92946, 90406, 86630, 80870, 73056, 62422, 49276, 33629)) migexpectable(US1997$A1, US1997$A2, US1997$TP, US1997$Mov, US1997$lx) # The table is slightly different from Table 11.3, due to the open-end # Lx value is different from the table.