bayesLife-package: Bayesian Projection of the Life Expectancy

bayesLife-packageR Documentation

Bayesian Projection of the Life Expectancy


Collection of functions for making probabilistic projections of the life expectancy for all countries of the world, using a Bayesian hierarchical model and the United Nations demographic time series. Projections on a subnational level are also supported.


The projection follows a method developed by Chunn et al (2010, 2013). It uses historical data provided by the United Nations to simulate a posterior distribution of the life expectancy for all countries in the world simultaneously.

The package is implemented in a similar way as the bayesTFR package and thus, many functions have their equivalents in bayesTFR. The main functions of the bayesLife package are:

  • run.e0.mcmc: Runs a Markov Chain Monte Carlo (MCMC) simulation for one or more chains, possibly in parallel. It results in a posterior sample of the MCMC parameters. Existing simulation runs can be resumed using continue.e0.mcmc.

  • e0.predict: Using the posterior parameter samples it derives posterior trajectories of the life expectancy for all countries.

  • e0.jmale.predict: Given existing outputs of e0.predict for female life expectancy, this function estimates and predicts a joint male life expectancy as described in Raftery et al (2014).

  • e0.predict.subnat: Given existing projections on national level, it generates projections on a subnational level, for both, female and male (Sevcikova and Raftery 2021).

A number of functions analyzing results are included in the package:

  • e0.trajectories.plot: Shows the posterior trajectories for a given country, including their median and given probability intervals.

  • e0.trajectories.table: Shows the posterior trajectories for a given country in a tabular form.

  • and Show a world map of life expectancy for a given projection period.

  • e0.DLcurve.plot: Shows the posterior curves of the double logistic function used in the simulation, including their median and given probability intervals.

  • e0.partraces.plot and e0.partraces.cs.plot: Plot the MCMC traces of country-independent parameters and country-specific parameters, respectively.

  • e0.pardensity.plot and e0.pardensity.cs.plot: Plot the posterior density of the MCMCs for country-independent parameters and country-specific parameters, respectively.

  • summary.bayesLife.mcmc.set: Summary function for the MCMC results.

  • summary.bayesLife.prediction: Summary function for the prediction results.

For MCMC diagnostics, function e0.coda.list.mcmc creates an object of type “mcmc.list” that can be used with the coda package. Furthermore, function e0.diagnose analyzes the MCMCs using the Raftery diagnostics implemented in the coda package and gives information about parameters that did not converge. Function e0.dl.coverage computes a goodness of fit of the double logistic function.

Existing simulation results can be accessed using the get.e0.mcmc function. An existing prediction can be accessed via get.e0.prediction. Existing predictions on a subnational level can be accessed via get.rege0.prediction.

For a table with countries included in the mcmc or prediction object, the function get.countries.table can be used in the same way as in bayesTFR.

Historical data are taken from one of the packages wpp2019 (default), wpp2017, wpp2015, wpp2012 or wpp2010, depending on users settings. For more recent data, package wpp2022 can be installed from Github (@PPgp).


There is a directory ex-data shipped with the package which contains results from an example simulation, containing one chain with 60 iterations. The Example section below shows how these results were created. These data are used in Example sections throughout the manual. The user can either reproduce the data in her/his local directory, or use the ones from the package.


Hana Sevcikova, Adrian Raftery, Jennifer Chunn

Maintainer: Hana Sevcikova <>


J. L. Chunn, A. E. Raftery, P. Gerland, H. Sevcikova (2013): Bayesian Probabilistic Projections of Life Expectancy for All Countries. Demography 50(3):777-801. <doi:10.1007/s13524-012-0193-x>

A. E. Raftery, N. Li, H. Sevcikova, P. Gerland, G. K. Heilig (2012). Bayesian probabilistic population projections for all countries. Proceedings of the National Academy of Sciences 109:13915-13921.

A. E. Raftery, N. Lalic, P. Gerland (2014). Joint Probabilistic Projection of Female and Male Life Expectancy. Demographic Research, 30:795-822.

H. Sevcikova, A. E. Raftery (2021). Probabilistic Projection of Subnational Life Expectancy. Journal of Official Statistics, , Vol. 37, no. 3, 591-610.

See Also



## Not run: 
sim.dir <- tempfile()
m <- run.e0.mcmc(sex = 'F', nr.chains = 1, iter = 60, seed = 1, 
        thin = 1, output.dir = sim.dir, verbose = TRUE)
pred <- e0.predict(m, burnin = 30, verbose = TRUE)
summary(pred, country = "Canada")
unlink(sim.dir, recursive = TRUE)
## End(Not run)

bayesLife documentation built on Sept. 16, 2023, 9:07 a.m.