Software
bayesTFR bayesLife bayesLifeHIV bayesPop wppExplorer & data MortCast
All packages described below are available on CRAN. Development versions are available from GitHub.
bayesTFR
bayesTFR is an R package for probabilistic projections of the total fertility rate (TFR). It implements the Bayesian hierarchical model described in Alkema et al. (2011). Ševčíková et al. (2011) gives more detail about the package. Probabilistic subnational projections as described in Ševčíková et al. (2018) are also supported.
Recently, the package went through a major overhaul. It now implements the methodology of Liu and Raftery that accounts for uncertainty in the observed data, as well as can be used with annual time series. The bayesTFR GitHub page gives more detail on the new features.
A converged simulation from WPP2019 that can be used for exploring TFR projections using the package can be found here (95M). (It has 3x62000 long MCMCs of phase II and 3x70000 long MCMCs of phase III, both thinned by 30. Projections contain 1000 trajectories.) The directory has a README file with the code used to produce this simulation. Note that more recent simulations are available on the download page.
After unpacking into a directory say ‘my_path’, use the commands
library(bayesTFR)
tfdir <- 'my_path/TFR/sim20190525'
m2 <- get.tfr.mcmc(tfdir)
m3 <- get.tfr3.mcmc(tfdir)
to retrieve the MCMC Phase II and Phase III objects, respectively, and the command
pred <- get.tfr.prediction(tfdir)
to retrieve the prediction object. Follow instructions from the package documentation to explore results. For example, to view projections for Nigeria, do
tfr.trajectories.plot(pred, country = "Nigeria", nr.traj = 50)
or
summary(pred, country = "Nigeria")
To view an interactive world map with projections in 2050, including a sortable table, do
tfr.map.gvis(pred, year = 2050)
bayesLife
bayesLife is an R package for probabilistic projections of life expectancy (e0). It implements the Bayesian hierarchical model (BHM) described in Raftery et al. (2013) and Raftery et al. (2014). Probabilistic subnational projections as described in Ševčíková et al. (2021) are also supported.
An MCMC estimation of the e0 parameters can take a long time to run, therefore we provide here results from a converged simulation (using WPP2019 data), including predictions. It consists of 3 chains, 180,000 iterations each, with thin being 50 and 1000 projection trajectories for both, the female and male e0 (159M). The BHM was estimated using 180 countries without HIV/AIDS epidemic. Parameters for the remaining 21 countries were estimated via the “extra” option. The directory has a README file with the code used to produce this simulation. Note that more recent simulations are available on the download page.
After unpacking into a directory say ‘my_path’, use the commands
library(bayesLife)
e0dir <- 'my_path/e0/sim20190528'
m <- get.e0.mcmc(e0dir)
to retrieve the MCMC object, and the command
pred <- get.e0.prediction(e0dir)
to retrieve the prediction object. Follow instructions from the package documentation to view results. For example, to view projections for Japan, both male and female, do
e0.trajectories.plot(pred, country = "Japan", both.sexes = TRUE, nr.traj = 50)
or in tabular form for female:
summary(pred, country = "Japan")
and male:
pred.male <- get.e0.jmale.prediction(pred)
summary(pred.male, country = "Japan")
To view an interactive world map with projections in 2050, including a sortable table, do
e0.map.gvis(pred, year = 2050)
Please note that trajectories for the 21 countries with generalized HIV/AIDS epidemics are only illustrative and do not correspond to the UN projections for those countries. To view a list of those countries, do
all.cntries <- get.countries.table(m)
all.cntries[(get.nrest.countries(m$meta)+1):nrow(all.cntries),]
bayesLifeHIV
bayesLifeHIV is an extension of the bayesLife R package that takes into account HIV/AIDS, as described in Godwin and Raftery (2017). Follow the GitHub instructions to generate a simulation and projections. As it estimates and projects for ALL countries, it replaces the need of using bayesLife on its own. Handling of the resulting objects is the same as for bayesLife.
bayesPop
bayesPop is an R package for probabilistic population projections using outputs from bayesTFR and bayesLife as inputs. Raftery et al. (2012) describes the methodology. Ševčíková, Raftery (2016) and Ševčíková et al. (2014) gives more technical details.
Exploring WPP datasets
Data on the World Population Prospects published by the United Nations Population Division are available in R packages wpp2024 (see the GitHub page for installation), wpp2022, wpp2019, wpp2017, wpp2015, wpp2012, and wpp2010. They also include probabilistic projections derived by the UN using the methodology above.
An interactive interface for exploration of the data is available online or in the shiny-based R package wppExplorer.
MortCast
The MortCast R package can be used for estimation and projection of age-specific mortality rates. It is used from within bayesPop to match mortality rates to the projected life expectancies. However, the package functions can be used on its own. See the GitHub page for an overview of the functions.
If you have any question about the software, please send an email to Hana or (preferably) subscribe to our mailing list.