# NOT RUN {
# estimate parameters from historical mortality data (5-year age groups)
data(mxM, mxF, e0Fproj, e0Mproj, package = "wpp2017")
country <- "Brazil"
mxm <- subset(mxM, name == country)[,4:16]
mxf <- subset(mxF, name == country)[,4:16]
rownames(mxm) <- rownames(mxf) <- c(0,1, seq(5, 100, by=5))
lc <- lileecarter.estimate(mxm, mxf)
# project into future for given levels of life expectancy
e0f <- as.numeric(subset(e0Fproj, name == country)[-(1:2)])
e0m <- as.numeric(subset(e0Mproj, name == country)[-(1:2)])
pred <- mortcast(e0m, e0f, lc)
# plot first projection in black and the remaining ones in grey
plot(lc$ages, pred$female$mx[,1], type="b", log="y", ylim=range(pred$female$mx),
ylab="female mx", xlab="Age", main=paste(country, "(5-year age groups)"), cex=0.5)
for(i in 2:ncol(pred$female$mx)) lines(lc$ages, pred$female$mx[,i], col="grey")
# similarly for 1-year age groups
# derive toy 1-year mx using model life tables at given level of e0
mxm1y <- mlt(seq(65, 71, length = 4), sex = "male", nx = 1)
mxf1y <- mlt(seq(73, 78, length = 4), sex = "female", nx = 1)
# estimate parameters
lc1y <- lileecarter.estimate(mxm1y, mxf1y, nx = 1)
# project into the future
pred1y <- mortcast(e0m, e0f, lc1y)
# plot first projection in black and the remaining ones in grey
plot(lc1y$ages, pred1y$female$mx[,1], type="b", log="y", ylim=range(pred1y$female$mx),
ylab="female mx", xlab="Age", main="1-year age groups", cex=0.5)
for(i in 2:ncol(pred1y$female$mx)) lines(lc1y$ages, pred1y$female$mx[,i], col="grey")
# }
Run the code above in your browser using DataLab