From 60cf631efb5cd5d2d2de7d07ffce4c5ee492f141 Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Wed, 27 Sep 2023 12:35:33 -0700 Subject: [PATCH 01/20] defaults for parameter names in e0.raftery.diag changed --- ChangeLog | 4 ++++ DESCRIPTION | 4 ++-- R/diagnostics.R | 2 +- man/e0.raftery.diag.Rd | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ebb032b..98bc7a19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +5.2-0.9xxx (09/27/2023) +----- +Default for par.names and par.names.cs in e0.raftery.diag changed to all parameters. + 5.2-0 (09/15/2023) ----- Annual subnational projections are now possible, via the argument "annual" diff --git a/DESCRIPTION b/DESCRIPTION index fb288ce9..60e69410 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0 -Date: 2023-09-15 +Version: 5.2-0.9001 +Date: 2023-09-27 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova Description: Making probabilistic projections of life expectancy for all countries of the world, using a Bayesian hierarchical model . Subnational projections are also supported. diff --git a/R/diagnostics.R b/R/diagnostics.R index 9ac1c054..7702abd5 100644 --- a/R/diagnostics.R +++ b/R/diagnostics.R @@ -1,7 +1,7 @@ e0.raftery.diag <- function(mcmc = NULL, sim.dir = file.path(getwd(), 'bayesLife.output'), burnin = 0, country = NULL, - par.names = NULL, par.names.cs = NULL, + par.names = NA, par.names.cs = NA, country.sampling.prop = 1, verbose = TRUE, ...) { mcmc.set <- if (is.null(mcmc)) get.e0.mcmc(sim.dir = sim.dir, low.memory = TRUE) else mcmc diff --git a/man/e0.raftery.diag.Rd b/man/e0.raftery.diag.Rd index 456b640b..b4929a13 100644 --- a/man/e0.raftery.diag.Rd +++ b/man/e0.raftery.diag.Rd @@ -8,7 +8,7 @@ Raftery Diagnostics for Parameters of the Life Expectancy The function computes the Raftery diagnostics for each parameter in the same way as \code{\link[bayesTFR]{tfr.raftery.diag}} of the \pkg{bayesTFR} package.} \usage{ e0.raftery.diag(mcmc = NULL, sim.dir = file.path(getwd(), "bayesLife.output"), - burnin = 0, country = NULL, par.names = NULL, par.names.cs = NULL, + burnin = 0, country = NULL, par.names = NA, par.names.cs = NA, country.sampling.prop = 1, verbose = TRUE, \dots) } @@ -25,9 +25,9 @@ Burnin. \item{country}{Name or code of a country. If it is given, only country-specific parameters parameters of that country are considered.} \item{par.names}{ Names of country-independent parameters for which the Raftery diagnostics should be computed. By default all parameters are used. -} + If it is \code{NULL}, no country-independent parameters are used.} \item{par.names.cs}{ -Names of country-specific parameters for which the Raftery diagnostics should be computed. By default all parameters are used. +Names of country-specific parameters for which the Raftery diagnostics should be computed. By default all parameters are used. If it is \code{NULL}, no country-specific parameters are used. } \item{country.sampling.prop}{Proportion of countries that are included in the diagnostics. It should be between 0 and 1. If it is smaller than 1, the countries are randomly sampled. It is only relevant if \code{par.names.cs} is not \code{NULL}. } \item{verbose}{Logical switching log messages on and off.} From b47f5d73cf723679fe205f4a119ad14f7ede0092 Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Wed, 27 Sep 2023 13:09:38 -0700 Subject: [PATCH 02/20] changed badge link --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index ed3669e4..91f598da 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # bayesLife -[![R build status](https://github.com/PPgp/bayesLife/workflows/R-CMD-check/badge.svg?branch=master)](https://github.com/PPgp/bayesLife/actions?workflow=R-CMD-check) - +[![R-CMD-check](https://github.com/PPgp/bayesLife/actions/workflows/check-standard.yaml/badge.svg?branch=master&event=push)](https://github.com/PPgp/bayesLife/actions/workflows/check-standard.yaml) R package for projecting life expectancy at birth probabilistically. See [Documentation on CRAN](https://cran.r-project.org/web/packages/bayesLife/bayesLife.pdf). From ee100a8d6cd79f43613d8ced974aba8f7c1c381c Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Fri, 22 Dec 2023 18:29:53 -0800 Subject: [PATCH 03/20] bug fix in e0.joint.plot --- ChangeLog | 4 +++- DESCRIPTION | 4 ++-- R/plot_functions.R | 9 +++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98bc7a19..fad5d790 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,9 @@ -5.2-0.9xxx (09/27/2023) +5.2-0.9xxx (12/22/2023) ----- Default for par.names and par.names.cs in e0.raftery.diag changed to all parameters. +Fixed bug in e0.joint.plot for annual prediction object. + 5.2-0 (09/15/2023) ----- Annual subnational projections are now possible, via the argument "annual" diff --git a/DESCRIPTION b/DESCRIPTION index 60e69410..c8db2279 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9001 -Date: 2023-09-27 +Version: 5.2-0.9002 +Date: 2023-12-22 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova Description: Making probabilistic projections of life expectancy for all countries of the world, using a Bayesian hierarchical model . Subnational projections are also supported. diff --git a/R/plot_functions.R b/R/plot_functions.R index d630d385..57fd3aaf 100644 --- a/R/plot_functions.R +++ b/R/plot_functions.R @@ -106,8 +106,13 @@ e0.joint.plot <- function(e0.pred, country, pi=95, years, nr.points=500, if(!has.e0.jmale.prediction(e0.pred)) stop('A male prediction does not exist for the given prediction object. Run e0.jmale.predict.') start.year <- as.integer(dimnames(e0.pred$quantiles)[[3]][1]) - years.obs <- years[years <= start.year+2] - years.pred <- years[years > start.year+2] + if(e0.pred$mcmc.set$meta$annual.simulation){ + years.obs <- years[years <= start.year] + years.pred <- years[years > start.year] + } else { + years.obs <- years[years <= start.year+2] + years.pred <- years[years > start.year+2] + } years.idx <- unlist(lapply(years.pred, bayesTFR:::get.prediction.year.index, pred=e0.pred)) years.idx <- years.idx[years.idx > 1] years.obs.idx <- unlist(lapply(years.obs, bayesTFR:::get.estimation.year.index, meta=e0.pred$mcmc.set$meta)) From 10afd15fd2335ba22a0f2919b3e7fcdb01d8f6e3 Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Fri, 2 Feb 2024 12:12:01 -0800 Subject: [PATCH 04/20] fix in time index for imputation --- ChangeLog | 2 ++ DESCRIPTION | 4 ++-- R/project_subnat.R | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index fad5d790..1a4a2912 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Default for par.names and par.names.cs in e0.raftery.diag changed to all paramet Fixed bug in e0.joint.plot for annual prediction object. +Fixed bug in setting time index when imputation is present in e0.predict.subnat(). + 5.2-0 (09/15/2023) ----- Annual subnational projections are now possible, via the argument "annual" diff --git a/DESCRIPTION b/DESCRIPTION index c8db2279..56e87fb9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9002 -Date: 2023-12-22 +Version: 5.2-0.9003 +Date: 2024-02-02 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova Description: Making probabilistic projections of life expectancy for all countries of the world, using a Bayesian hierarchical model . Subnational projections are also supported. diff --git a/R/project_subnat.R b/R/project_subnat.R index b7f310bc..a6091c63 100644 --- a/R/project_subnat.R +++ b/R/project_subnat.R @@ -153,7 +153,7 @@ e0.predict.subnat <- function(countries, my.e0.file, sim.dir=file.path(getwd(), PIs_cqp <- array(NA, c(nr.reg, length(quantiles.to.keep), nrow(wtrajs)), dimnames=list(meta$regions$country_code, dimnames(wpred$quantiles)[[2]], dimnames(wtrajs)[[1]])) mean_sd <- array(NA, c(nr.reg, 2, nrow(wtrajs))) - #meta$Tc.index <- .get.Tcindex(meta$e0.matrix, cnames = meta$regions$country_name) + meta$Tc.index <- .get.Tcindex(meta$e0.matrix, cnames = meta$regions$country_name) country.char <- as.character(country.obj$code) e0reconstructed <- meta$e0.matrix @@ -171,7 +171,7 @@ e0.predict.subnat <- function(countries, my.e0.file, sim.dir=file.path(getwd(), widx <- which(rownames(wtrajs.all) %in% names(rege0[i])) c.first <- rep(do.call(paste0("compute.alpha.", method), list(rege0[i], wtrajs.all[widx,])), nr.traj) # set of initial scales - meta$Tc.index[region] <- i + meta$Tc.index[[region]] <- meta$Tc.index[[region]][meta$Tc.index[[region]] <= i] imptraj <- matrix(NA, nrow = length(rege0) - i, ncol = nr.traj) # trajectory matrix for imputation for(tr in 1:nr.traj) { # iterate over trajectories imp.time <- i:(length(rege0)-1) From 72e8b43d3ee80740efa578d72b2dfe365a6a5160 Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Sun, 24 Mar 2024 13:48:50 -0700 Subject: [PATCH 05/20] passing annual to underying functions --- DESCRIPTION | 4 ++-- R/wpp_data.R | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 56e87fb9..962c58da 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9003 -Date: 2024-02-02 +Version: 5.2-0.9004 +Date: 2024-03-24 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova Description: Making probabilistic projections of life expectancy for all countries of the world, using a Bayesian hierarchical model . Subnational projections are also supported. diff --git a/R/wpp_data.R b/R/wpp_data.R index da27e384..06c94243 100644 --- a/R/wpp_data.R +++ b/R/wpp_data.R @@ -110,7 +110,7 @@ set.e0.wpp.extra <- function(meta, countries=NULL, my.e0.file=NULL, my.locations locations <- bayesTFR:::read.UNlocations(data$data, wpp.year=meta$wpp.year, my.locations.file=my.locations.file, package='bayesLife', verbose=verbose) suppl.wpp <- bayesTFR:::.get.suppl.matrix.and.regions(un.object, extra.wpp, locations$loc_data, - meta$start.year, meta$present.year) + meta$start.year, meta$present.year, annual = annual) extra.wpp$suppl.data <- bayesTFR:::.get.suppl.data.list(suppl.wpp, matrix.name='e0.matrix') } else extra.wpp$suppl.data <- bayesTFR:::.get.suppl.data.list(NULL) } From 2c627c526f9c3edb080be08794c09e746ea3aa3c Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Sun, 24 Mar 2024 20:36:23 -0700 Subject: [PATCH 06/20] added argument use.wpp.data --- ChangeLog | 2 ++ DESCRIPTION | 2 +- R/run_mcmc.R | 22 +++++++++++++++------- R/wpp_data.R | 16 ++++++++++------ man/run.e0.mcmc.Rd | 8 +++++--- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a4a2912..b302b999 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ Fixed bug in e0.joint.plot for annual prediction object. Fixed bug in setting time index when imputation is present in e0.predict.subnat(). +Added argument use.wpp.data to run.e0.mcmc(). + 5.2-0 (09/15/2023) ----- Annual subnational projections are now possible, via the argument "annual" diff --git a/DESCRIPTION b/DESCRIPTION index 962c58da..8be3f3f3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9004 +Version: 5.2-0.9005 Date: 2024-03-24 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova diff --git a/R/run_mcmc.R b/R/run_mcmc.R index c58e7615..11d0921a 100644 --- a/R/run_mcmc.R +++ b/R/run_mcmc.R @@ -70,7 +70,7 @@ run.e0.mcmc <- function(sex=c("Female", "Male"), nr.chains = 3, iter = 160000, output.dir = file.path(getwd(), 'bayesLife.output'), thin = 10, replace.output = FALSE, annual = FALSE, start.year = 1873, present.year = 2020, wpp.year = 2019, - my.e0.file = NULL, my.locations.file = NULL, + my.e0.file = NULL, my.locations.file = NULL, use.wpp.data = TRUE, constant.variance = FALSE, seed = NULL, parallel = FALSE, nr.nodes = nr.chains, compression.type = 'None', verbose = FALSE, verbose.iter = 100, mcmc.options = NULL, ...) { @@ -120,7 +120,9 @@ run.e0.mcmc <- function(sex=c("Female", "Male"), nr.chains = 3, iter = 160000, my.e0.file = my.e0.file, my.locations.file = my.locations.file, output.dir = output.dir, mcmc.options = mcoptions, constant.variance = constant.variance, - compression.type = compression.type, verbose = verbose) + compression.type = compression.type, + use.wpp.data = use.wpp.data, + verbose = verbose) store.bayesLife.meta.object(bayesLife.mcmc.meta, output.dir) starting.values <- match.ini.to.chains(nr.chains, annual = annual) iter <- .match.length.to.nr.chains(iter, nr.chains, "iter") @@ -466,19 +468,24 @@ e0.mcmc.run.chain.extra <- function(chain.id, mcmc.list, countries, posterior.sa e0.mcmc.meta.ini <- function(sex = "F", nr.chains = 1, start.year = 1950, present.year = 2020, wpp.year = 2019, my.e0.file = NULL, my.locations.file = NULL, annual.simulation = FALSE, output.dir = file.path(getwd(), 'bayesLife.output'), - mcmc.options = NULL, ..., verbose=FALSE) { + mcmc.options = NULL, use.wpp.data = TRUE, ..., verbose=FALSE) { mcmc.input <- c(list(sex = sex, nr.chains = nr.chains, start.year = start.year, present.year = present.year, wpp.year = wpp.year, my.e0.file = my.e0.file, annual.simulation = annual.simulation, - output.dir = output.dir, mcmc.options = mcmc.options), list(...)) + use.wpp.data = use.wpp.data, output.dir = output.dir, + mcmc.options = mcmc.options), list(...)) if(present.year - 3 > wpp.year) - warning("present.year is much larger then wpp.year. Make sure WPP data for present.year are available.") + warning("present.year is much larger then wpp.year. Make sure WPP data for present.year are available.") + if(!use.wpp.data && is.null(my.e0.file)) { + warning("If use.wpp.data is set to FALSE, my.e0.file should be given. The simulation will use default WPP data.") + use.wpp.data <- TRUE + } data <- get.wpp.e0.data (sex, start.year = start.year, present.year = present.year, wpp.year = wpp.year, my.e0.file = my.e0.file, include.hiv = mcmc.options$include.hiv.countries, my.locations.file = my.locations.file, - annual = annual.simulation, verbose = verbose) + annual = annual.simulation, use.wpp.data = use.wpp.data, verbose = verbose) part.ini <- .do.part.e0.mcmc.meta.ini(data, mcmc.input) new.meta <- c(mcmc.input, part.ini) if(!is.null(mcmc.options$meta.ini.fun)) @@ -587,7 +594,8 @@ e0.mcmc.meta.ini.extra <- function(mcmc.set, countries = NULL, my.e0.file = NULL #create e0 matrix only for the extra countries e0.with.regions <- set.e0.wpp.extra(meta, countries=countries, my.e0.file = my.e0.file, my.locations.file = my.locations.file, - annual = meta$annual.simulation, verbose = verbose) + annual = meta$annual.simulation, use.wpp.data = meta$use.wpp.data, + verbose = verbose) if(is.null(e0.with.regions)) return(list(meta = meta, index = c())) # join old and new country.overwrites option; remove possible duplicates if(!is.null(country.overwrites)) { diff --git a/R/wpp_data.R b/R/wpp_data.R index 06c94243..0c35db1d 100644 --- a/R/wpp_data.R +++ b/R/wpp_data.R @@ -1,6 +1,7 @@ get.wpp.e0.data <- function(sex = 'M', start.year = 1950, present.year = 2015, wpp.year = 2017, my.e0.file = NULL, include.hiv = FALSE, - my.locations.file = NULL, annual = FALSE, verbose = FALSE) { + my.locations.file = NULL, annual = FALSE, use.wpp.data = TRUE, + verbose = FALSE) { sex <- toupper(sex) if(sex != 'M' && sex != 'F') stop('Allowed values for argument "sex" are "M" and "F".') @@ -9,7 +10,7 @@ get.wpp.e0.data <- function(sex = 'M', start.year = 1950, present.year = 2015, ######################################## un.object <- read.UNe0(sex=sex, wpp.year=wpp.year, my.e0.file=my.e0.file, present.year=present.year, annual = annual, - verbose=verbose) + use.wpp.data = use.wpp.data, verbose=verbose) data <- un.object$data.object$data # get region and area data locations <- bayesTFR:::read.UNlocations(data, wpp.year=wpp.year, my.locations.file=my.locations.file, @@ -90,10 +91,11 @@ read.UNe0 <- function(sex, wpp.year, my.e0.file=NULL, annual = FALSE, ...) { } set.e0.wpp.extra <- function(meta, countries=NULL, my.e0.file=NULL, my.locations.file=NULL, - annual = FALSE, verbose=FALSE) { + annual = FALSE, verbose=FALSE, use.wpp.data = TRUE) { #'countries' is a vector of country or region codes un.object <- read.UNe0(sex=meta$sex, wpp.year=meta$wpp.year, my.e0.file=my.e0.file, - present.year=meta$present.year, annual = annual, verbose=verbose) + present.year=meta$present.year, annual = annual, + use.wpp.data = use.wpp.data, verbose=verbose) data <- un.object$data.object extra.wpp <- bayesTFR:::.extra.matrix.regions(data=data, countries=countries, meta=meta, package="bayesLife", my.locations.file=my.locations.file, @@ -117,7 +119,8 @@ set.e0.wpp.extra <- function(meta, countries=NULL, my.e0.file=NULL, my.locations return(extra.wpp) } -get.wpp.e0.data.for.countries <- function(meta, sex='M', my.e0.file=NULL, my.locations.file=NULL, verbose=FALSE) { +get.wpp.e0.data.for.countries <- function(meta, sex='M', my.e0.file=NULL, + my.locations.file=NULL, verbose=FALSE) { sex <- toupper(sex) if(sex != 'M' && sex != 'F') stop('Allowed values for argument "sex" are "M" and "F".') @@ -125,7 +128,8 @@ get.wpp.e0.data.for.countries <- function(meta, sex='M', my.e0.file=NULL, my.loc # set data and match with areas ######################################## un.object <- read.UNe0(sex=sex, wpp.year=meta$wpp.year, present.year=meta$present.year, - my.e0.file=my.e0.file, annual = meta$annual.simulation, verbose=verbose) + my.e0.file=my.e0.file, annual = meta$annual.simulation, + use.wpp.data = meta$use.wpp.data, verbose=verbose) data <- un.object$data.object$data # get region and area data locations <- bayesTFR:::read.UNlocations(data, wpp.year=meta$wpp.year, diff --git a/man/run.e0.mcmc.Rd b/man/run.e0.mcmc.Rd index f8bcc394..0324e8e8 100644 --- a/man/run.e0.mcmc.Rd +++ b/man/run.e0.mcmc.Rd @@ -14,8 +14,9 @@ run.e0.mcmc(sex = c("Female", "Male"), nr.chains = 3, iter = 160000, output.dir = file.path(getwd(), "bayesLife.output"), thin = 10, replace.output = FALSE, annual = FALSE, start.year = 1873, present.year = 2020, wpp.year = 2019, - my.e0.file = NULL, my.locations.file = NULL, constant.variance = FALSE, - seed = NULL, parallel = FALSE, nr.nodes = nr.chains, compression.type = 'None', + my.e0.file = NULL, my.locations.file = NULL, use.wpp.data = TRUE, + constant.variance = FALSE, seed = NULL, + parallel = FALSE, nr.nodes = nr.chains, compression.type = 'None', verbose = FALSE, verbose.iter = 100, mcmc.options = NULL, \dots) continue.e0.mcmc(iter, chain.ids = NULL, @@ -37,6 +38,7 @@ continue.e0.mcmc(iter, chain.ids = NULL, \item{wpp.year}{Year for which WPP data is used. The functions loads a package called \pkg{wpp}\eqn{x} where \eqn{x} is the \code{wpp.year} and uses the \code{\link[wpp2019]{e0}*} datasets.} \item{my.e0.file}{File name containing user-specified e0 time series for one or more countries. See Details below.} \item{my.locations.file}{File name containing user-specified locations. See Details below.} + \item{use.wpp.data}{Logical indicating if default WPP data should be used, i.e. if \code{my.e0.file} will be matched with the WPP data in terms of time periods and locations. If \code{FALSE}, it is assumed that the \code{my.e0.file} contains all locations and time periods to be included in the simulation.} \item{constant.variance}{Logical indicating if the model should be estimated using constant variance. It should only be used if the standard deviation lowess is to be analysed, see \code{\link{compute.loess}}.} \item{seed}{Seed of the random number generator. If \code{NULL} no seed is set. It can be used to generate reproducible results.} \item{parallel}{Logical determining if the simulation should run multiple chains in parallel. If it is \code{TRUE}, the package \pkg{snowFT} is required.} @@ -56,7 +58,7 @@ The function \code{run.e0.mcmc} creates an object of class \code{\link{bayesLife Using the function \code{continue.e0.mcmc} one can continue simulating an existing MCMCs by \code{iter} iterations for either all or selected chains. The global options used for generating the existing MCMCs will be used. Only the \code{auto.conf} option can be overwritten by passing the new value as an argument. -The function loads observed data (further denoted as WPP dataset), depending on the specified sex, from the \code{\link[wpp2019]{e0F}} (\code{\link[wpp2019]{e0M}}) and \code{\link[wpp2019]{e0F_supplemental}} (\code{\link[wpp2019]{e0M_supplemental}}) datasets in a \pkg{wpp}\eqn{x} package where \eqn{x} is the \code{wpp.year}. It is then merged with the \code{\link{include}} dataset that corresponds to the same \code{wpp.year}. The argument \code{my.e0.file} can be used to overwrite those default data. Such a file can include a subset of countries contained in the WPP dataset, as well as a set of new countries. In the former case, +The function loads observed data (further denoted as WPP dataset), depending on the specified sex, from the \code{\link[wpp2019]{e0F}} (\code{\link[wpp2019]{e0M}}) and \code{\link[wpp2019]{e0F_supplemental}} (\code{\link[wpp2019]{e0M_supplemental}}) datasets in a \pkg{wpp}\eqn{x} package where \eqn{x} is the \code{wpp.year}. It is then merged with the \code{\link{include}} dataset that corresponds to the same \code{wpp.year}. The argument \code{my.e0.file} can be used to overwrite those default data. If \code{use.wpp.data} is \code{FALSE}, it fully replaces the default dataset. Otherwise (by default), such a file can include a subset of countries contained in the WPP dataset, as well as a set of new countries. In the former case, the function replaces the corresponding country data from the WPP dataset with values in this file. Only columns are replaced that match column names of the WPP dataset, and in addition, columns \sQuote{last.observed} and \sQuote{include_code} are used, if present. Countries are merged with WPP using the column \sQuote{country_code}. In addition, in order the countries to be included in the simulation, in both cases (whether they are included in the WPP dataset or not), they must be contained in the table of locations (\code{\link[wpp2019]{UNlocations}}). In addition, their corresponding \sQuote{include_code} must be set to 2. If the column \sQuote{include_code} is present in \code{my.e0.file}, its value overwrites the default include code, unless is -1. If \code{annual} is \code{TRUE} the default WPP dataset is not used and the \code{my.e0.file} argument must provide the dataset to be used for estimation. Its time-related columns should be single years. From a5c31e6b55b292485f403e4c8dd0e94416c837a2 Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Sat, 6 Apr 2024 19:19:39 -0700 Subject: [PATCH 07/20] not load supplemental data if use.wpp.data is FALSE --- DESCRIPTION | 4 ++-- R/wpp_data.R | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8be3f3f3..9e6925a4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9005 -Date: 2024-03-24 +Version: 5.2-0.9006 +Date: 2024-04-06 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova Description: Making probabilistic projections of life expectancy for all countries of the world, using a Bayesian hierarchical model . Subnational projections are also supported. diff --git a/R/wpp_data.R b/R/wpp_data.R index 0c35db1d..0eaa8081 100644 --- a/R/wpp_data.R +++ b/R/wpp_data.R @@ -53,7 +53,7 @@ get.wpp.e0.data <- function(sex = 'M', start.year = 1950, present.year = 2015, if (verbose) cat('Dimension of the e0 matrix:', dim(LEXmatrix.regions$obs_matrix), '\n') - if(!annual || wpp.year >= 2022) { + if((!annual || wpp.year >= 2022) && use.wpp.data) { LEXmatrixsuppl.regions <- bayesTFR:::.get.suppl.matrix.and.regions(un.object, LEXmatrix.regions, loc_data, start.year, present.year, annual = annual) if(!is.null(un.object$suppl.data.object) && verbose) From 5265b937229aba4b79c1f308714b6db0664c8fc2 Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Sat, 6 Apr 2024 19:52:40 -0700 Subject: [PATCH 08/20] finished supplemental data fix --- R/wpp_data.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/wpp_data.R b/R/wpp_data.R index 0eaa8081..cfd4013a 100644 --- a/R/wpp_data.R +++ b/R/wpp_data.R @@ -150,7 +150,7 @@ get.wpp.e0.data.for.countries <- function(meta, sex='M', my.e0.file=NULL, interpolate = meta$wpp.year < 2022 && meta$annual && is.null(my.e0.file)) if (verbose) cat('Dimension of the e0 matrix:', dim(LEXmatrix.regions$obs_matrix), '\n') - if(!meta$annual.simulation || meta$wpp.year >= 2022) { + if((!meta$annual.simulation || meta$wpp.year >= 2022) && meta$use.wpp.data) { LEXmatrixsuppl.regions <- bayesTFR:::.get.suppl.matrix.and.regions(un.object, LEXmatrix.regions, loc_data, meta$start.year, meta$present.year, annual = meta$annual.simulation) } else LEXmatrixsuppl.regions <- NULL From 78b55d232d19cc52d8ff571396f8148fccd330de Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Sat, 6 Apr 2024 19:57:52 -0700 Subject: [PATCH 09/20] finished supplemental data fix --- DESCRIPTION | 2 +- R/wpp_data.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9e6925a4..9beb7b49 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9006 +Version: 5.2-0.9007 Date: 2024-04-06 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova diff --git a/R/wpp_data.R b/R/wpp_data.R index cfd4013a..10fdb294 100644 --- a/R/wpp_data.R +++ b/R/wpp_data.R @@ -108,7 +108,7 @@ set.e0.wpp.extra <- function(meta, countries=NULL, my.e0.file=NULL, my.locations regions=extra.wpp$regions, nr.countries.estimation=extra.wpp$nr_countries_estimation, is_processed = extra.wpp$is_processed) - if(!annual || meta$wpp.year >= 2022) { + if((!annual || meta$wpp.year >= 2022)) && use.wpp.data) { locations <- bayesTFR:::read.UNlocations(data$data, wpp.year=meta$wpp.year, my.locations.file=my.locations.file, package='bayesLife', verbose=verbose) suppl.wpp <- bayesTFR:::.get.suppl.matrix.and.regions(un.object, extra.wpp, locations$loc_data, From a193285483d0f00dc269f0d41bda08824979c07f Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Sun, 7 Apr 2024 13:34:01 -0700 Subject: [PATCH 10/20] fixed syntax error --- R/wpp_data.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/wpp_data.R b/R/wpp_data.R index 10fdb294..d2fec125 100644 --- a/R/wpp_data.R +++ b/R/wpp_data.R @@ -108,7 +108,7 @@ set.e0.wpp.extra <- function(meta, countries=NULL, my.e0.file=NULL, my.locations regions=extra.wpp$regions, nr.countries.estimation=extra.wpp$nr_countries_estimation, is_processed = extra.wpp$is_processed) - if((!annual || meta$wpp.year >= 2022)) && use.wpp.data) { + if((!annual || meta$wpp.year >= 2022) && use.wpp.data) { locations <- bayesTFR:::read.UNlocations(data$data, wpp.year=meta$wpp.year, my.locations.file=my.locations.file, package='bayesLife', verbose=verbose) suppl.wpp <- bayesTFR:::.get.suppl.matrix.and.regions(un.object, extra.wpp, locations$loc_data, From e0868bb041ac7241ad45e19e5082bf228a9d5e1e Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Wed, 5 Jun 2024 18:26:39 -0700 Subject: [PATCH 11/20] added mean variant to summary output --- ChangeLog | 4 +++- DESCRIPTION | 4 ++-- R/projection_fcns.R | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b302b999..a0fb566b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -5.2-0.9xxx (12/22/2023) +5.2-0.9xxx (06/05/2024) ----- Default for par.names and par.names.cs in e0.raftery.diag changed to all parameters. @@ -8,6 +8,8 @@ Fixed bug in setting time index when imputation is present in e0.predict.subnat( Added argument use.wpp.data to run.e0.mcmc(). +Added the mean variant into sumary output. + 5.2-0 (09/15/2023) ----- Annual subnational projections are now possible, via the argument "annual" diff --git a/DESCRIPTION b/DESCRIPTION index 9beb7b49..2cf5b5cf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9007 -Date: 2024-04-06 +Version: 5.2-0.9008 +Date: 2024-06-05 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova Description: Making probabilistic projections of life expectancy for all countries of the world, using a Bayesian hierarchical model . Subnational projections are also supported. diff --git a/R/projection_fcns.R b/R/projection_fcns.R index ae92747c..d39f9f59 100644 --- a/R/projection_fcns.R +++ b/R/projection_fcns.R @@ -353,10 +353,10 @@ get.projection.summary.header.bayesLife.prediction <- function(pred, ...) return (list(revision='RevID', variant='VarID', country='LocID', year='TimeID', indicator='IndicatorID', sex='SexID', tfr='Value')) get.UN.variant.names.bayesLife.prediction <- function(pred, ...) - return(c('BHM median', 'BHM80 lower', 'BHM80 upper', 'BHM95 lower', 'BHM95 upper', 'Constant mortality')) + return(c('BHM median', 'BHM80 lower', 'BHM80 upper', 'BHM95 lower', 'BHM95 upper', 'BHM mean', 'Constant mortality')) get.friendly.variant.names.bayesLife.prediction <- function(pred, ...) - return(c('median', 'lower 80', 'upper 80', 'lower 95', 'upper 95', 'constant')) + return(c('median', 'lower 80', 'upper 80', 'lower 95', 'upper 95', 'mean', 'constant')) convert.e0.trajectories <- function(dir=file.path(getwd(), 'bayesLife.output'), n=1000, output.dir=NULL, From 3215f4cba69b997fbfcd6dbe10d082aabe80c456 Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Wed, 5 Jun 2024 21:04:02 -0700 Subject: [PATCH 12/20] arguments show.mean and traj.index in e0.tajectories.plot --- ChangeLog | 3 +++ DESCRIPTION | 2 +- R/plot_functions.R | 18 ++++++++++++++++++ man/e0.trajectories.plot.Rd | 3 +++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a0fb566b..c341169a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,9 @@ Added argument use.wpp.data to run.e0.mcmc(). Added the mean variant into sumary output. +e0.trajectories.plot() got arguments to plot the means (show.mean), +as well as selected trajectories (traj.index). + 5.2-0 (09/15/2023) ----- Annual subnational projections are now possible, via the argument "annual" diff --git a/DESCRIPTION b/DESCRIPTION index 2cf5b5cf..a5563613 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9008 +Version: 5.2-0.9009 Date: 2024-06-05 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova diff --git a/R/plot_functions.R b/R/plot_functions.R index 57fd3aaf..ce72767a 100644 --- a/R/plot_functions.R +++ b/R/plot_functions.R @@ -200,6 +200,7 @@ e0.trajectories.plot.all <- function(e0.pred, e0.trajectories.plot <- function(e0.pred, country, pi=c(80, 95), both.sexes=FALSE, nr.traj=NULL, adjusted.only = TRUE, typical.trajectory=FALSE, + traj.index = NULL, show.mean = FALSE, xlim=NULL, ylim=NULL, type='b', xlab='Year', ylab='Life expectancy at birth', main=NULL, lwd=c(2,2,2,2,1), col=c('black', 'green', 'red', 'red', '#00000020'), @@ -325,13 +326,20 @@ e0.trajectories.plot <- function(e0.pred, country, pi=c(80, 95), both.sexes=FALS e0pred <- pred[[ipred]] this.col <- plotcols[[ipred]] meta <- e0pred$mcmc.set$meta + if(!is.null(traj.index)) nr.traj <- length(traj.index) if(do.average) { trajectories <- get.e0.trajectories.object(pred, country$code, nr.traj=nr.traj, typical.trajectory=typical.trajectory, pi=pi) e0.median <- trajectories$median + if(show.mean) + e0.mean <- apply(trajectories$trajectories, 1, mean, na.rm=TRUE) } else { trajectories <- get.e0.trajectories.object(e0pred, country$code, nr.traj=nr.traj, typical.trajectory=typical.trajectory) e0.median <- bayesTFR::get.median.from.prediction(e0pred, country$index, country$code) + if(show.mean) + e0.mean <- bayesTFR::get.mean.from.prediction(e0pred, country$index, country$code) } + if(!is.null(traj.index) && !is.null(trajectories$trajectories)) trajectories$index <- traj.index + cqp <- list() if(ipred > 1) add <- TRUE if(!add) @@ -418,6 +426,16 @@ e0.trajectories.plot <- function(e0.pred, country, pi=c(80, 95), both.sexes=FALS lwds <- c(lwds, lwd[3]) lty <- c(lty, max(lty)+1) } + if(show.mean){ + # plot mean + lines(plot.data[[ipred]]$pred.x, e0.mean, type='l', col=this.col[3], lwd=1, lty=max(lty)+1) + mean.leg <- 'mean' + if(do.both.sexes) mean.leg <- paste(lowerize(get.sex.label(meta)), mean.leg) + legend <- c(legend, mean.leg) + cols <- c(cols, this.col[3]) + lwds <- c(lwds, 1) + lty <- c(lty, max(lty)+1) + } if(lpart2 > 0) { legend <- c(legend, paste('imputed', if(do.both.sexes) paste(lowerize(get.sex.label(meta)), 'e0') else 'e0')) cols <- c(cols, this.col[2]) diff --git a/man/e0.trajectories.plot.Rd b/man/e0.trajectories.plot.Rd index f4eb46eb..9ba00207 100644 --- a/man/e0.trajectories.plot.Rd +++ b/man/e0.trajectories.plot.Rd @@ -12,6 +12,7 @@ The functions plot/tabulate the posterior distribution of trajectories of the li \usage{ e0.trajectories.plot(e0.pred, country, pi = c(80, 95), both.sexes = FALSE, nr.traj = NULL, adjusted.only = TRUE, typical.trajectory = FALSE, + traj.index = NULL, show.mean = FALSE, xlim = NULL, ylim = NULL, type = "b", xlab = "Year", ylab = "Life expectancy at birth", main = NULL, lwd = c(2, 2, 2, 2, 1), col = c('black', 'green', 'red', 'red', '#00000020'), @@ -34,6 +35,8 @@ e0.trajectories.table(e0.pred, country, pi = c(80, 95), \item{nr.traj}{Number of trajectories to be plotted. If \code{NULL}, all trajectories are plotted, otherwise they are thinned evenly. If \code{both.sexes} is \code{TRUE} the default is zero.} \item{adjusted.only}{Logical. By default, if the projection median is adjusted using e.g. \code{\link{e0.median.set}}, the function plots the adjusted median. If \code{adjusted.only=FALSE} the original (non-adjusted) median is plotted as well.} \item{typical.trajectory}{Logical. If \code{TRUE} one trajectory is shown for which the median absolute deviation from the median e0 projection is the median among all the trajectories.} + \item{traj.index}{Vector of trajectory indices to show. If not given, the trajectories are selected using equidistant spacing.} + \item{show.mean}{Logical indicating if the mean of the distribution should be shown.} \item{xlim, ylim, type, xlab, ylab, main}{Graphical parameters passed to the \code{plot} function.} \item{lwd, col, col2}{Vector of five elements giving the line width and color for: 1. observed data, 2. imputed missing data, 3. median, 4. quantiles, 5. trajectories. \code{col2} is only used if \code{both.sexes} is \code{TRUE}. In such a case, \code{col2} is used for female lines and \code{col} is used for male lines, which in this case defaults to \code{c('black', 'green', 'darkgreen', 'darkgreen', 'gray')}.} From 806eaa3a76533690a202124a7e5c3ed4fccbe0d6 Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Thu, 20 Jun 2024 18:29:28 -0700 Subject: [PATCH 13/20] added argument show.median --- ChangeLog | 4 +-- DESCRIPTION | 4 +-- R/plot_functions.R | 65 +++++++++++++++++++++++++------------ man/e0.trajectories.plot.Rd | 4 +-- 4 files changed, 50 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index c341169a..f6d9bec5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -5.2-0.9xxx (06/05/2024) +5.2-0.9xxx (06/20/2024) ----- Default for par.names and par.names.cs in e0.raftery.diag changed to all parameters. @@ -10,7 +10,7 @@ Added argument use.wpp.data to run.e0.mcmc(). Added the mean variant into sumary output. -e0.trajectories.plot() got arguments to plot the means (show.mean), +e0.trajectories.plot() got arguments to plot the means (show.mean), the medians (show.median), as well as selected trajectories (traj.index). 5.2-0 (09/15/2023) diff --git a/DESCRIPTION b/DESCRIPTION index a5563613..b9ccb936 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9009 -Date: 2024-06-05 +Version: 5.2-0.9010 +Date: 2024-06-20 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova Description: Making probabilistic projections of life expectancy for all countries of the world, using a Bayesian hierarchical model . Subnational projections are also supported. diff --git a/R/plot_functions.R b/R/plot_functions.R index ce72767a..81508031 100644 --- a/R/plot_functions.R +++ b/R/plot_functions.R @@ -200,7 +200,7 @@ e0.trajectories.plot.all <- function(e0.pred, e0.trajectories.plot <- function(e0.pred, country, pi=c(80, 95), both.sexes=FALSE, nr.traj=NULL, adjusted.only = TRUE, typical.trajectory=FALSE, - traj.index = NULL, show.mean = FALSE, + traj.index = NULL, show.mean = FALSE, show.median = TRUE, xlim=NULL, ylim=NULL, type='b', xlab='Year', ylab='Life expectancy at birth', main=NULL, lwd=c(2,2,2,2,1), col=c('black', 'green', 'red', 'red', '#00000020'), @@ -327,30 +327,43 @@ e0.trajectories.plot <- function(e0.pred, country, pi=c(80, 95), both.sexes=FALS this.col <- plotcols[[ipred]] meta <- e0pred$mcmc.set$meta if(!is.null(traj.index)) nr.traj <- length(traj.index) + e0.median <- e0.mean <- e0.main.proj <- NULL if(do.average) { trajectories <- get.e0.trajectories.object(pred, country$code, nr.traj=nr.traj, typical.trajectory=typical.trajectory, pi=pi) - e0.median <- trajectories$median + if(show.median) + e0.median <- trajectories$median if(show.mean) e0.mean <- apply(trajectories$trajectories, 1, mean, na.rm=TRUE) } else { trajectories <- get.e0.trajectories.object(e0pred, country$code, nr.traj=nr.traj, typical.trajectory=typical.trajectory) - e0.median <- bayesTFR::get.median.from.prediction(e0pred, country$index, country$code) + if(show.median) + e0.median <- bayesTFR::get.median.from.prediction(e0pred, country$index, country$code) if(show.mean) e0.mean <- bayesTFR::get.mean.from.prediction(e0pred, country$index, country$code) } if(!is.null(traj.index) && !is.null(trajectories$trajectories)) trajectories$index <- traj.index - + # set the main projection (solid line) + main.proj.name <- "" + if(!is.null(e0.median)){ + e0.main.proj <- e0.median + main.proj.name <- "median" + } else { + if(!is.null(e0.mean)){ + e0.main.proj <- e0.mean + main.proj.name <- "mean" + } + } cqp <- list() if(ipred > 1) add <- TRUE if(!add) ylim.loc <- c(min(if (!is.null(trajectories$trajectories)) trajectories$trajectories[,trajectories$index] else NULL, - ylim.loc[1], e0.median, na.rm=TRUE), + ylim.loc[1], e0.main.proj, na.rm=TRUE), max(if (!is.null(trajectories$trajectories)) trajectories$trajectories[,trajectories$index] else NULL, - ylim.loc[2], e0.median, na.rm=TRUE)) + ylim.loc[2], e0.main.proj, na.rm=TRUE)) if(length(pi) > 0) { for (i in 1:length(pi)) { if(do.average) cqp[[i]] <- trajectories$quantiles[[i]] @@ -394,11 +407,16 @@ e0.trajectories.plot <- function(e0.pred, country, pi=c(80, 95), both.sexes=FALS col=this.col[5], lwd=lwd[5]) } } - # plot median - lines(plot.data[[ipred]]$pred.x, e0.median, type='l', col=this.col[3], lwd=lwd[3]) - legend <- if(adjusted.only) 'median' else 'adj. median' - if(do.both.sexes) legend <- paste(lowerize(get.sex.label(meta)), legend) - lty <- 1 + legend <- lty <- lwds <- cols <- c() + # plot main projection + if(!is.null(e0.main.proj)){ + lines(plot.data[[ipred]]$pred.x, e0.main.proj, type='l', col=this.col[3], lwd=lwd[3]) + legend <- if(adjusted.only) main.proj.name else paste('adj.', main.proj.name) + if(do.both.sexes) legend <- paste(lowerize(get.sex.label(meta)), legend) + lty <- 1 + lwds <- lwd[3] + cols <- this.col[3] + } # plot given CIs if(length(pi) > 0) { tlty <- 2:(length(pi)+1) @@ -414,20 +432,25 @@ e0.trajectories.plot <- function(e0.pred, country, pi=c(80, 95), both.sexes=FALS legend <- c(legend, paste('observed', if(do.both.sexes) paste(lowerize(get.sex.label(meta)), 'e0') else 'e0')) lty <- c(lty, 1) pchs <- c(rep(-1, length(legend)-1), pch[1]) - lwds <- c(lwd[3], rep(lwd[4], length(pi)), lwd[1]) - cols <- c(this.col[3], rep(this.col[4], length(pi)), this.col[1]) - if(!adjusted.only) { # plot unadjusted median - bhm.median <- bayesTFR::get.median.from.prediction(e0pred, country$index, country$code, adjusted=FALSE) - lines(plot.data[[ipred]]$pred.x, bhm.median, type='l', col=this.col[3], lwd=lwd[3], lty=max(lty)+1) - bhm.leg <- 'BHM median' - if(do.both.sexes) bhm.leg <- paste(lowerize(get.sex.label(meta)), bhm.leg) - legend <- c(legend, bhm.leg) + lwds <- c(lwds, rep(lwd[4], length(pi)), lwd[1]) + cols <- c(cols, rep(this.col[4], length(pi)), this.col[1]) + if(!adjusted.only) { # plot unadjusted median / mean + if(main.proj.name == "mean"){ + bhm.main <- bayesTFR::get.mean.from.prediction(e0pred, country$index, country$code, adjusted=FALSE) + bhm.main.name <- 'BHM mean' + } else { + bhm.main <- bayesTFR::get.median.from.prediction(e0pred, country$index, country$code, adjusted=FALSE) + bhm.main.name <- 'BHM median' + } + lines(plot.data[[ipred]]$pred.x, bhm.main, type='l', col=this.col[3], lwd=lwd[3], lty=max(lty)+1) + if(do.both.sexes) bhm.main.name <- paste(lowerize(get.sex.label(meta)), bhm.main.name) + legend <- c(legend, bhm.main.name) cols <- c(cols, this.col[3]) lwds <- c(lwds, lwd[3]) lty <- c(lty, max(lty)+1) } - if(show.mean){ - # plot mean + if(show.median && show.mean){ + # plot mean in addition to median lines(plot.data[[ipred]]$pred.x, e0.mean, type='l', col=this.col[3], lwd=1, lty=max(lty)+1) mean.leg <- 'mean' if(do.both.sexes) mean.leg <- paste(lowerize(get.sex.label(meta)), mean.leg) diff --git a/man/e0.trajectories.plot.Rd b/man/e0.trajectories.plot.Rd index 9ba00207..c6375171 100644 --- a/man/e0.trajectories.plot.Rd +++ b/man/e0.trajectories.plot.Rd @@ -12,7 +12,7 @@ The functions plot/tabulate the posterior distribution of trajectories of the li \usage{ e0.trajectories.plot(e0.pred, country, pi = c(80, 95), both.sexes = FALSE, nr.traj = NULL, adjusted.only = TRUE, typical.trajectory = FALSE, - traj.index = NULL, show.mean = FALSE, + traj.index = NULL, show.mean = FALSE, show.median = TRUE, xlim = NULL, ylim = NULL, type = "b", xlab = "Year", ylab = "Life expectancy at birth", main = NULL, lwd = c(2, 2, 2, 2, 1), col = c('black', 'green', 'red', 'red', '#00000020'), @@ -36,7 +36,7 @@ e0.trajectories.table(e0.pred, country, pi = c(80, 95), \item{adjusted.only}{Logical. By default, if the projection median is adjusted using e.g. \code{\link{e0.median.set}}, the function plots the adjusted median. If \code{adjusted.only=FALSE} the original (non-adjusted) median is plotted as well.} \item{typical.trajectory}{Logical. If \code{TRUE} one trajectory is shown for which the median absolute deviation from the median e0 projection is the median among all the trajectories.} \item{traj.index}{Vector of trajectory indices to show. If not given, the trajectories are selected using equidistant spacing.} - \item{show.mean}{Logical indicating if the mean of the distribution should be shown.} + \item{show.mean, show.median}{Logical indicating if the mean or/and the median of the distribution should be shown.} \item{xlim, ylim, type, xlab, ylab, main}{Graphical parameters passed to the \code{plot} function.} \item{lwd, col, col2}{Vector of five elements giving the line width and color for: 1. observed data, 2. imputed missing data, 3. median, 4. quantiles, 5. trajectories. \code{col2} is only used if \code{both.sexes} is \code{TRUE}. In such a case, \code{col2} is used for female lines and \code{col} is used for male lines, which in this case defaults to \code{c('black', 'green', 'darkgreen', 'darkgreen', 'gray')}.} From 3e72bcc8d16e450c264989a037610c861be016ea Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Thu, 26 Sep 2024 17:03:35 -0700 Subject: [PATCH 14/20] added include_2024 --- ChangeLog | 4 +- DESCRIPTION | 4 +- data-raw/create_includes.R | 2 + data-raw/include_2024.txt | 290 +++++++++++++++++++++++++++++++++++++ data/include_2024.rda | Bin 0 -> 815 bytes 5 files changed, 297 insertions(+), 3 deletions(-) create mode 100644 data-raw/include_2024.txt create mode 100644 data/include_2024.rda diff --git a/ChangeLog b/ChangeLog index f6d9bec5..dc6da4ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ -5.2-0.9xxx (06/20/2024) +5.2-0.9xxx (09/26/2024) ----- +Added dataset include_2024. + Default for par.names and par.names.cs in e0.raftery.diag changed to all parameters. Fixed bug in e0.joint.plot for annual prediction object. diff --git a/DESCRIPTION b/DESCRIPTION index b9ccb936..e7a08bc0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9010 -Date: 2024-06-20 +Version: 5.2-0.9011 +Date: 2024-09-26 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova Description: Making probabilistic projections of life expectancy for all countries of the world, using a Bayesian hierarchical model . Subnational projections are also supported. diff --git a/data-raw/create_includes.R b/data-raw/create_includes.R index 97c1be87..87e55533 100644 --- a/data-raw/create_includes.R +++ b/data-raw/create_includes.R @@ -2,6 +2,8 @@ library(data.table) library(usethis) # Run this from the data-raw directory +include_2024 <- as.data.frame(fread("include_2024.txt", sep = "\t")[, .(country_code, include_code)]) +use_data(include_2024, overwrite = TRUE) include_2022 <- as.data.frame(fread("include_2022.txt", sep = "\t")[, .(country_code, include_code)]) use_data(include_2022, overwrite = TRUE) diff --git a/data-raw/include_2024.txt b/data-raw/include_2024.txt new file mode 100644 index 00000000..40f94ed2 --- /dev/null +++ b/data-raw/include_2024.txt @@ -0,0 +1,290 @@ +name country_code include_code hiv_projection +World 900 0 0 +Sustainable Development Goal (SDG) regions 1828 0 0 +Sub-Saharan Africa 947 0 0 +Northern Africa and Western Asia 1833 0 0 +Central and Southern Asia 921 0 0 +Eastern and South-Eastern Asia 1832 0 0 +Latin America and the Caribbean 1830 0 0 +Australia/New Zealand 927 0 0 +Oceania (excluding Australia and New Zealand) 1835 0 0 +Europe and Northern America 1829 0 0 +Geographic regions 1840 0 0 +Africa 903 0 0 +Asia 935 0 0 +Europe 908 0 0 +Latin America and the Caribbean 904 0 0 +Northern America 905 0 0 +Oceania 909 0 0 +UN development groups 1803 0 0 +More developed regions 901 0 0 +Less developed regions 902 0 0 +Least developed countries 941 0 0 +"Less developed regions, excluding least developed countries" 934 0 0 +"Less developed regions, excluding China" 948 0 0 +Land-locked Developing Countries (LLDC) 1636 0 0 +Small Island Developing States (SIDS) 1637 0 0 +World Bank Income Groups 1802 0 0 +High-income countries 1503 0 0 +Middle-income countries 1517 0 0 +Upper-middle-income countries 1502 0 0 +Lower-middle-income countries 1501 0 0 +Low-income countries 1500 0 0 +No income group available 1518 0 0 +Eastern Africa 910 0 0 +Burundi 108 2 1 +Comoros 174 2 0 +Djibouti 262 2 1 +Eritrea 232 2 1 +Ethiopia 231 2 1 +Kenya 404 3 1 +Madagascar 450 2 0 +Malawi 454 3 1 +Mauritius 480 2 1 +Mayotte 175 2 0 +Mozambique 508 3 1 +Reunion 638 2 0 +Rwanda 646 3 1 +Seychelles 690 2 0 +Somalia 706 2 0 +South Sudan 728 2 1 +Uganda 800 3 1 +United Republic of Tanzania 834 3 1 +Zambia 894 3 1 +Zimbabwe 716 3 1 +Middle Africa 911 0 0 +Angola 24 2 1 +Cameroon 120 3 1 +Central African Republic 140 3 1 +Chad 148 2 1 +Congo 178 3 1 +Democratic Republic of the Congo 180 2 1 +Equatorial Guinea 226 3 1 +Gabon 266 3 1 +Sao Tome and Principe 678 2 0 +Southern Africa 913 0 0 +Botswana 72 3 1 +Eswatini 748 3 1 +Lesotho 426 3 1 +Namibia 516 3 1 +South Africa 710 3 1 +Western Africa 914 0 0 +Benin 204 2 1 +Burkina Faso 854 2 1 +Cabo Verde 132 2 1 +Cote d'Ivoire 384 3 1 +Gambia 270 2 1 +Ghana 288 2 1 +Guinea 324 2 1 +Guinea-Bissau 624 3 1 +Liberia 430 2 1 +Mali 466 2 1 +Mauritania 478 2 1 +Niger 562 2 0 +Nigeria 566 2 1 +Saint Helena 654 2 0 +Senegal 686 2 0 +Sierra Leone 694 2 1 +Togo 768 3 1 +Northern Africa 912 0 0 +Algeria 12 2 0 +Egypt 818 2 0 +Libya 434 2 0 +Morocco 504 2 0 +Sudan 729 2 0 +Tunisia 788 2 0 +Western Sahara 732 2 0 +Western Asia 922 0 0 +Armenia 51 2 0 +Azerbaijan 31 2 0 +Bahrain 48 2 0 +Cyprus 196 2 0 +Georgia 268 2 0 +Iraq 368 2 0 +Israel 376 2 0 +Jordan 400 2 0 +Kuwait 414 2 0 +Lebanon 422 2 0 +Oman 512 2 0 +Qatar 634 2 0 +Saudi Arabia 682 2 0 +State of Palestine 275 2 0 +Syrian Arab Republic 760 2 0 +Türkiye 792 2 0 +United Arab Emirates 784 2 0 +Yemen 887 2 0 +Central Asia 5500 0 0 +Kazakhstan 398 2 0 +Kyrgyzstan 417 2 0 +Tajikistan 762 2 0 +Turkmenistan 795 2 0 +Uzbekistan 860 2 0 +Southern Asia 5501 0 0 +Afghanistan 4 2 0 +Bangladesh 50 2 0 +Bhutan 64 2 0 +India 356 2 0 +Iran (Islamic Republic of) 364 2 0 +Maldives 462 2 0 +Nepal 524 2 0 +Pakistan 586 2 0 +Sri Lanka 144 2 0 +Eastern Asia 906 0 0 +China 156 2 0 +"China, Hong Kong SAR" 344 2 0 +"China, Macao SAR" 446 2 0 +"China, Taiwan Province of China" 158 2 0 +Dem. People's Republic of Korea 408 2 0 +Japan 392 2 0 +Mongolia 496 2 0 +Republic of Korea 410 2 0 +South-Eastern Asia 920 0 0 +Brunei Darussalam 96 2 0 +Cambodia 116 2 1 +Indonesia 360 2 0 +Lao People's Democratic Republic 418 2 0 +Malaysia 458 2 0 +Myanmar 104 2 1 +Philippines 608 2 0 +Singapore 702 2 0 +Thailand 764 2 1 +Timor-Leste 626 2 0 +Viet Nam 704 2 0 +Caribbean 915 0 0 +Anguilla 660 2 0 +Antigua and Barbuda 28 2 0 +Aruba 533 2 0 +Bahamas 44 2 1 +Barbados 52 2 1 +"Bonaire, Sint Eustatius and Saba" 535 2 0 +British Virgin Islands 92 2 0 +Cayman Islands 136 2 0 +Cuba 192 2 0 +Curacao 531 2 0 +Dominica 212 2 0 +Dominican Republic 214 2 1 +Grenada 308 2 0 +Guadeloupe 312 2 0 +Haiti 332 2 1 +Jamaica 388 2 1 +Martinique 474 2 0 +Montserrat 500 2 0 +Puerto Rico 630 2 0 +Saint Kitts and Nevis 659 2 0 +Saint Lucia 662 2 0 +Saint Vincent and the Grenadines 670 2 0 +Saint-Barthelemy 652 2 0 +Saint-Martin (French part) 663 2 0 +Sint Maarten (Dutch part) 534 2 0 +Trinidad and Tobago 780 2 1 +Turks and Caicos Islands 796 2 0 +United States Virgin Islands 850 2 0 +Central America 916 0 0 +Belize 84 2 1 +Costa Rica 188 2 0 +El Salvador 222 2 0 +Guatemala 320 2 0 +Honduras 340 2 1 +Mexico 484 2 0 +Nicaragua 558 2 0 +Panama 591 2 1 +South America 931 0 0 +Argentina 32 2 0 +Bolivia (Plurinational State of) 68 2 0 +Brazil 76 2 0 +Chile 152 2 0 +Colombia 170 2 0 +Ecuador 218 2 0 +Falkland Islands (Malvinas) 238 2 0 +French Guiana 254 2 0 +Guyana 328 2 1 +Paraguay 600 2 0 +Peru 604 2 0 +Suriname 740 2 1 +Uruguay 858 2 0 +Venezuela (Bolivarian Republic of) 862 2 0 +Australia 36 2 0 +New Zealand 554 2 0 +Melanesia 928 0 0 +Fiji 242 2 0 +New Caledonia 540 2 0 +Papua New Guinea 598 2 1 +Solomon Islands 90 2 0 +Vanuatu 548 2 0 +Micronesia 954 0 0 +Guam 316 2 0 +Kiribati 296 2 0 +Marshall Islands 584 2 0 +Micronesia (Fed. States of) 583 2 0 +Nauru 520 2 0 +Northern Mariana Islands 580 2 0 +Palau 585 2 0 +Polynesia 957 0 0 +American Samoa 16 2 0 +Cook Islands 184 2 0 +French Polynesia 258 2 0 +Niue 570 2 0 +Samoa 882 2 0 +Tokelau 772 2 0 +Tonga 776 2 0 +Tuvalu 798 2 0 +Wallis and Futuna Islands 876 2 0 +Eastern Europe 923 0 0 +Belarus 112 2 0 +Bulgaria 100 2 0 +Czechia 203 2 0 +Hungary 348 2 0 +Poland 616 2 0 +Republic of Moldova 498 2 0 +Romania 642 2 0 +Russian Federation 643 2 1 +Slovakia 703 2 0 +Ukraine 804 2 1 +Northern Europe 924 0 0 +Denmark 208 2 0 +Estonia 233 2 0 +Faroe Islands 234 2 0 +Finland 246 2 0 +Guernsey 831 2 0 +Iceland 352 2 0 +Ireland 372 2 0 +Isle of Man 833 2 0 +Jersey 832 2 0 +Latvia 428 2 0 +Lithuania 440 2 0 +Norway 578 2 0 +Sweden 752 2 0 +United Kingdom 826 2 0 +Southern Europe 925 0 0 +Albania 8 2 0 +Andorra 20 2 0 +Bosnia and Herzegovina 70 2 0 +Croatia 191 2 0 +Gibraltar 292 2 0 +Greece 300 2 0 +Holy See 336 2 0 +Italy 380 2 0 +Kosovo (under UNSC res. 1244) 412 2 0 +Malta 470 2 0 +Montenegro 499 2 0 +North Macedonia 807 2 0 +Portugal 620 2 0 +San Marino 674 2 0 +Serbia 688 2 0 +Slovenia 705 2 0 +Spain 724 2 0 +Western Europe 926 0 0 +Austria 40 2 0 +Belgium 56 2 0 +France 250 2 0 +Germany 276 2 0 +Liechtenstein 438 2 0 +Luxembourg 442 2 0 +Monaco 492 2 0 +Netherlands 528 2 0 +Switzerland 756 2 0 +Bermuda 60 2 0 +Canada 124 2 0 +Greenland 304 2 0 +Saint Pierre and Miquelon 666 2 0 +United States of America 840 2 0 diff --git a/data/include_2024.rda b/data/include_2024.rda new file mode 100644 index 0000000000000000000000000000000000000000..5fed3bf2f1990e7f4834b9777fd47c7ddb88979f GIT binary patch literal 815 zcmV+~1JL|JT4*^jL0KkKSv7wa{Qv|a|NsC0PtE83T~zh-)m86j-}hhl{r~xw-B|)T~)vWe3~%lAgLyr06j*4218F!0j7*V4Lw6Z2ATs#On@}dFn}@u0j7XG6HI~W z1|!M{ke;dPZ&b+BCQSx_00w{tfEody00000000000B8UKq3U{qDf>!PpQ!)<8UO$Q z7>0lV00006hK3LT0000000w{oB8p8Q$jHz%&;gJQ0K{kkra;IHfHWEa28MtQ4FDQ6 z&}aZ?8V9I?iv-7iYH5H)qzD^GZLn-iV;tLz%qE<&Vr`6R%cKz3ySd0_`K?_Y$_H+9 zf5V~YQ`i_1EpfTWR5L3m8gDpm6PJjV*(K7~q#JdQ zFSw%)+kL`CKSb+@5IY$-Xjr)ycEB2U18dV6n~IY00_B=+sIJVqdUOjosUj1`d`|r! zsau#f30YSzU)z->;J#H`dY?}vuM&yg;^n)dKtLe~I|=~`8G!Nr%bJ~c!9?ne(xFu5 zVkkef8EJU*tKSL7j(8~#;o(EQ+SnMlP0njGr##g99}$N*wj1K0kxa?-s!~35kN^-6 zln5XK5)X}O_aUe@amsQYQIp++hQ5v3234Is<_xjw9O>j~ocyeW66qo)u|s}UBZ=8& z)5+i1uYr_r3Pt+@p%9i4-a zL4rttG?G4SY(i}fq}yn1w3|t>CeYd##4&=`F+qYGB())=Bt^?H0vsR+kikYU19>Cs zz>x^alPRWZX5luQaG?-_2x6EeB?FU*Cf#jOqf`w0989QPKXdVH%DKZcz z)032oEmgqAP{v?0f#VqD=ne&L3=9OJGD31B{R6=EL6joH2-Jv31sGyugs4WOJQ0jZ zh(ZAmIYN_)W Date: Thu, 31 Oct 2024 14:38:54 -0700 Subject: [PATCH 15/20] option of multiple prediction directories --- R/get_outputs.R | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/R/get_outputs.R b/R/get_outputs.R index 5278cdb7..8bba5f9b 100644 --- a/R/get_outputs.R +++ b/R/get_outputs.R @@ -92,14 +92,19 @@ e0.mcmc <- function(mcmc.set, chain.id=1) return (mcmc.set$mcmc.list[[chain.id]] e0.mcmc.list <- function(mcmc.set, chain.ids=NULL) return(bayesTFR::tfr.mcmc.list(mcmc.set=mcmc.set, chain.ids=chain.ids)) -has.e0.prediction <- function(mcmc=NULL, sim.dir=NULL) { +has.e0.prediction <- function(mcmc=NULL, sim.dir=NULL, subdir = "predictions") { if (!is.null(mcmc)) sim.dir <- if(is.character(mcmc)) mcmc else mcmc$meta$output.dir if (is.null(sim.dir)) stop('Either mcmc or directory must be given.') - if(file.exists(file.path(sim.dir, 'predictions', 'prediction.rda'))) return(TRUE) + if(file.exists(file.path(sim.dir, subdir, 'prediction.rda'))) return(TRUE) return(FALSE) } -get.e0.prediction <- function(mcmc=NULL, sim.dir=NULL, joint.male=FALSE, mcmc.dir=NULL) { +available.e0.predictions <- function(mcmc=NULL, sim.dir=NULL, full.names = FALSE){ + return(bayesTFR::available.tfr.predictions(mcmc=mcmc, sim.dir = sim.dir, full.names = full.names)) +} + +get.e0.prediction <- function(mcmc=NULL, sim.dir=NULL, joint.male=FALSE, mcmc.dir=NULL, + subdir = "predictions") { ############ # Returns an object of class bayesLife.prediction # Set mcmc.dir to NA, if the prediction object should not have a pointer @@ -108,11 +113,15 @@ get.e0.prediction <- function(mcmc=NULL, sim.dir=NULL, joint.male=FALSE, mcmc.di if (!is.null(mcmc)) sim.dir <- if(is.character(mcmc)) mcmc else mcmc$meta$output.dir if (is.null(sim.dir)) stop('Either mcmc or directory must be given.') - output.dir <- file.path(sim.dir, 'predictions') + output.dir <- file.path(sim.dir, subdir) pred.file <- file.path(output.dir, 'prediction.rda') if(!file.exists(pred.file)) { warning('File ', pred.file, ' does not exist.') - return(NULL) + if(length((alt.preds <- available.e0.predictions(sim.dir = sim.dir))) > 0){ + output.dir <- file.path(sim.dir, alt.preds[1]) + pred.file <- file.path(output.dir, 'prediction.rda') + warning('Extracting predictions from ', alt.preds[1]) + } else return(NULL) } load(file=pred.file) bayesLife.prediction$output.directory <- output.dir From bc4827fe2d4d9878aa4b8e5a4bfcfdc5d8f6e05b Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Thu, 31 Oct 2024 18:04:43 -0700 Subject: [PATCH 16/20] finished changed related to new subdir argument --- .Rbuildignore | 3 ++ ChangeLog | 7 ++-- DESCRIPTION | 16 +++++++-- NAMESPACE | 1 + R/project_subnat.R | 6 ++-- R/projection_fcns.R | 58 +++++++++++++++++---------------- man/convert.trajectories.Rd | 3 +- man/e0.median.set.Rd | 17 ++++++---- man/e0.predict.Rd | 7 ++-- man/e0.predict.extra.Rd | 3 +- man/e0.predict.subnat.Rd | 5 +-- man/get.e0.prediction.Rd | 19 ++++++++--- man/include.Rd | 2 ++ man/write.projection.summary.Rd | 3 +- tests/run_tests.R | 4 +-- 15 files changed, 98 insertions(+), 56 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 6a3eead2..ad5ee0dc 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,6 @@ ^README\.md$ ^.github$ ^data-raw +^tests/last.dump.rda +^tests/.clustersize +^tests/.proc diff --git a/ChangeLog b/ChangeLog index dc6da4ac..61d748a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -5.2-0.9xxx (09/26/2024) +5.2-0.9xxx (10/31/2024) ----- Added dataset include_2024. @@ -10,11 +10,14 @@ Fixed bug in setting time index when imputation is present in e0.predict.subnat( Added argument use.wpp.data to run.e0.mcmc(). -Added the mean variant into sumary output. +Added the mean variant into summary output. e0.trajectories.plot() got arguments to plot the means (show.mean), the medians (show.median), as well as selected trajectories (traj.index). +Added option of keeping multiple predictions directories in one simulation directory +(argument "subdir" added to various functions). + 5.2-0 (09/15/2023) ----- Annual subnational projections are now possible, via the argument "annual" diff --git a/DESCRIPTION b/DESCRIPTION index e7a08bc0..7e93381a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,22 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9011 -Date: 2024-09-26 +Version: 5.2-0.9012 +Date: 2024-10-31 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova +Authors@R: c(person(given = "Hana", + family = "Sevcikova", + role = c("cre", "aut"), + email = "hanas@uw.edu"), + person(given = "Adrian", + family = "Raftery", + role = "aut", + email = "raftery@uw.edu"), + person(given = "Jennifer", + family = "Chunn", + role = "aut") + ) Description: Making probabilistic projections of life expectancy for all countries of the world, using a Bayesian hierarchical model . Subnational projections are also supported. Depends: bayesTFR (>= 7.3-0), diff --git a/NAMESPACE b/NAMESPACE index ca2a8f9e..848f7e09 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -36,6 +36,7 @@ export( create.thinned.e0.mcmc, get.e0.prediction, has.e0.prediction, + available.e0.predictions, get.e0.jmale.prediction, has.e0.jmale.prediction, get.rege0.prediction, diff --git a/R/project_subnat.R b/R/project_subnat.R index a6091c63..20d547db 100644 --- a/R/project_subnat.R +++ b/R/project_subnat.R @@ -1,6 +1,6 @@ e0.predict.subnat <- function(countries, my.e0.file, sim.dir=file.path(getwd(), 'bayesLife.output'), method = c("ar1", "shift", "scale"), predict.jmale = FALSE, my.e0M.file = NULL, - end.year=2100, start.year=NULL, output.dir = NULL, annual = NULL, + end.year=2100, start.year=NULL, subdir = "predictions", output.dir = NULL, annual = NULL, nr.traj=NULL, seed = NULL, ar.pars = NULL, save.as.ascii = 0, verbose = TRUE, jmale.estimates = NULL, ...) { # Run subnational projections, using the Scale AR(1) model applied to a national bayesLife simulation @@ -30,7 +30,7 @@ e0.predict.subnat <- function(countries, my.e0.file, sim.dir=file.path(getwd(), return(compute.alpha.ar1(...)) method <- match.arg(method) - wpred <- get.e0.prediction(sim.dir) # contains national projections + wpred <- get.e0.prediction(sim.dir, subdir = subdir) # contains national projections wdata <- wpred$e0.matrix.reconstructed wmeta <- wpred$mcmc.set$meta if(!is.null(seed)) set.seed(seed) @@ -153,7 +153,7 @@ e0.predict.subnat <- function(countries, my.e0.file, sim.dir=file.path(getwd(), PIs_cqp <- array(NA, c(nr.reg, length(quantiles.to.keep), nrow(wtrajs)), dimnames=list(meta$regions$country_code, dimnames(wpred$quantiles)[[2]], dimnames(wtrajs)[[1]])) mean_sd <- array(NA, c(nr.reg, 2, nrow(wtrajs))) - meta$Tc.index <- .get.Tcindex(meta$e0.matrix, cnames = meta$regions$country_name) + meta$Tc.index <- .get.Tcindex(meta$e0.matrix, cnames = meta$regions$country_name, stop.if.less.than2 = FALSE) # allow just one data point country.char <- as.character(country.obj$code) e0reconstructed <- meta$e0.matrix diff --git a/R/projection_fcns.R b/R/projection_fcns.R index d39f9f59..431378e1 100644 --- a/R/projection_fcns.R +++ b/R/projection_fcns.R @@ -21,7 +21,8 @@ e0.predict <- function(mcmc.set = NULL, end.year = 2100, replace.output = FALSE, predict.jmale = TRUE, nr.traj = NULL, thin = NULL, burnin = 10000, use.diagnostics = FALSE, save.as.ascii = 0, start.year = NULL, - output.dir = NULL, low.memory = TRUE, ignore.last.observed = FALSE, + output.dir = NULL, subdir = "predictions", low.memory = TRUE, + ignore.last.observed = FALSE, seed = NULL, verbose = TRUE, ...){ if(!is.null(mcmc.set)) { if (!inherits(mcmc.set, 'bayesLife.mcmc.set')) { @@ -41,7 +42,7 @@ e0.predict <- function(mcmc.set = NULL, end.year = 2100, replace.output = replace.output, nr.traj = nr.traj, thin = thin, burnin = burnin, save.as.ascii = save.as.ascii, start.year = start.year, - output.dir = output.dir, ignore.last.observed = ignore.last.observed, + output.dir = output.dir, subdir = subdir, ignore.last.observed = ignore.last.observed, verbose = verbose) if(predict.jmale && mcmc.set$meta$sex == 'F') pred <- e0.jmale.predict(pred, ..., save.as.ascii = save.as.ascii, verbose = verbose) @@ -49,7 +50,7 @@ e0.predict <- function(mcmc.set = NULL, end.year = 2100, } e0.predict.extra <- function(sim.dir = file.path(getwd(), 'bayesLife.output'), - prediction.dir = sim.dir, + prediction.dir = sim.dir, subdir = "predictions", countries = NULL, save.as.ascii = 1000, verbose = TRUE, ...) { # Run prediction for given countries/regions (as codes). If they are not given it will be set to countries # for which there are MCMC results but no prediction. @@ -58,9 +59,9 @@ e0.predict.extra <- function(sim.dir = file.path(getwd(), 'bayesLife.output'), mcmc.set <- get.e0.mcmc(sim.dir) if(is.null(mcmc.set)) stop('Error in "sim.dir" argument.') - pred <- get.e0.prediction(sim.dir=prediction.dir) + pred <- get.e0.prediction(sim.dir=prediction.dir, subdir = subdir) if(is.null(pred)) - stop('Error in "prediction.dir" argument.') + stop('Error in "sim.dir", "prediction.dir" or/and "subdir" argument. Use available.e0.predictions() to check on valid predictions directories.') if(length(setdiff(pred$mcmc.set$meta$regions$country_code, mcmc.set$meta$regions$country_code)) > 0) stop('Prediction is inconsistent with the mcmc results. Use e0.predict.') if(is.null(countries)) { @@ -77,7 +78,7 @@ e0.predict.extra <- function(sim.dir = file.path(getwd(), 'bayesLife.output'), new.pred <- make.e0.prediction(mcmc.set, start.year=pred$start.year, end.year=pred$end.year, replace.output=FALSE, nr.traj=pred$nr.traj, burnin=pred$burnin, countries=countries.idx, save.as.ascii=0, output.dir=prediction.dir, - force.creating.thinned.mcmc=TRUE, + subdir = subdir, force.creating.thinned.mcmc=TRUE, write.summary.files=FALSE, ignore.last.observed = pred$ignore.last.observed, verbose=verbose) @@ -121,7 +122,7 @@ e0.predict.extra <- function(sim.dir = file.path(getwd(), 'bayesLife.output'), e0.prediction.setup <- function(...) { setup <- list(...) - mcmc.set <- start.year <- end.year <- burnin <- replace.output <- verbose <- countries <- NULL # to avoid R check note "no visible binding ..." + mcmc.set <- start.year <- end.year <- burnin <- replace.output <- verbose <- countries <- subdir <- NULL # to avoid R check note "no visible binding ..." if(is.null(setup$thin)) setup$thin <- NA # this is because thin is a method in coda and the naming clashes within the setup expression setup <- within(setup, { meta <- mcmc.set$meta @@ -151,10 +152,10 @@ e0.prediction.setup <- function(...) { #setup output directory if (!exists("output.dir") || is.null(output.dir)) output.dir <- meta$output.dir - outdir <- file.path(output.dir, 'predictions') + outdir <- file.path(output.dir, basename(subdir)) if(is.null(get0("countries"))) { - if(!replace.output && has.e0.prediction(sim.dir = output.dir)) + if(!replace.output && has.e0.prediction(sim.dir = output.dir, subdir = subdir)) stop('Prediction in ', outdir, ' already exists.\nSet replace.output=TRUE if you want to overwrite existing projections.') unlink(outdir, recursive=TRUE) @@ -359,11 +360,11 @@ get.friendly.variant.names.bayesLife.prediction <- function(pred, ...) return(c('median', 'lower 80', 'upper 80', 'lower 95', 'upper 95', 'mean', 'constant')) convert.e0.trajectories <- function(dir=file.path(getwd(), 'bayesLife.output'), - n=1000, output.dir=NULL, + n=1000, subdir = "predictions", output.dir=NULL, verbose=FALSE) { # Converts all trajectory rda files into UN ascii, selecting n trajectories by equal spacing. if(n <= 0) return() - pred <- get.e0.prediction(sim.dir=dir) + pred <- get.e0.prediction(sim.dir=dir, subdir = subdir) predsex <- pred$mcmc.set$meta$sex preds <- list() preds[[predsex]] <- pred @@ -376,15 +377,15 @@ convert.e0.trajectories <- function(dir=file.path(getwd(), 'bayesLife.output'), else outdir <- output.dir } if(!file.exists(outdir)) dir.create(outdir, recursive=TRUE) - cat('Converting ', list(M='Male', F='Female')[[sex]], ' trajectories from', dir, '\n') + cat('Converting ', list(M='Male', F='Female')[[sex]], ' trajectories from', file.path(dir, subdir), '\n') bayesTFR:::do.convert.trajectories(pred=preds[[sex]], n=n, output.dir=outdir, verbose=verbose) } } write.e0.projection.summary <- function(dir=file.path(getwd(), 'bayesLife.output'), - output.dir=NULL, revision=NULL, adjusted=FALSE) { + subdir = "predictions", output.dir=NULL, revision=NULL, adjusted=FALSE) { # Writes four prediction summary files, one in a user-friendly format, one in a UN-format, one for each sex. - pred <- get.e0.prediction(sim.dir=dir) + pred <- get.e0.prediction(sim.dir=dir, subdir = subdir) predsex <- pred$mcmc.set$meta$sex preds <- list() preds[[predsex]] <- pred @@ -429,40 +430,41 @@ get.e0.reconstructed <- function(data, meta) { } else store.bayesLife.prediction(new.pred) } -e0.median.reset <- function(sim.dir, countries = NULL, joint.male=FALSE) { +e0.median.reset <- function(sim.dir, countries = NULL, joint.male=FALSE, ...) { if(is.null(countries)) { - pred <- get.e0.prediction(sim.dir, joint.male = joint.male) + pred <- get.e0.prediction(sim.dir, joint.male = joint.male, ...) pred$median.shift <- NULL .e0.store.adjustment(pred, sim.dir, joint.male) cat('\nMedians for all countries reset.\n') } else - for(country in countries) pred <- e0.median.shift(sim.dir, country, reset=TRUE, joint.male=joint.male) + for(country in countries) pred <- e0.median.shift(sim.dir, country, reset=TRUE, joint.male=joint.male, ...) invisible(pred) } get.e0.shift <- function(country.code, pred) return(bayesTFR::get.tfr.shift(country.code, pred)) -e0.median.shift <- function(sim.dir, country, reset=FALSE, shift=0, from=NULL, to=NULL, joint.male=FALSE) { - pred <- get.e0.prediction(sim.dir, joint.male=joint.male) +e0.median.shift <- function(sim.dir, country, reset=FALSE, shift=0, from=NULL, to=NULL, joint.male=FALSE, ...) { + pred <- get.e0.prediction(sim.dir, joint.male=joint.male, ...) new.pred <- bayesTFR:::.bdem.median.shift(pred, type='e0', country=country, reset=reset, shift=shift, from=from, to=to) .e0.store.adjustment(new.pred, sim.dir, joint.male) invisible(new.pred) } -e0.median.set <- function(sim.dir, country, values, years=NULL, joint.male=FALSE) { - pred <- get.e0.prediction(sim.dir, joint.male=joint.male) +e0.median.set <- function(sim.dir, country, values, years=NULL, joint.male=FALSE, ...) { + pred <- get.e0.prediction(sim.dir, joint.male=joint.male, ...) new.pred <- bayesTFR:::.bdem.median.set(pred, type='e0', country=country, values=values, years=years) .e0.store.adjustment(new.pred, sim.dir, joint.male) invisible(new.pred) } -e0.median.adjust.jmale <- function(sim.dir, countries, factors = c(1.2, 1.1)) { - pred <- get.e0.prediction(sim.dir) - if (is.null(pred)) stop('No valid prediction in ', sim.dir) +e0.median.adjust.jmale <- function(sim.dir, countries, factors = c(1.2, 1.1), subdir = "predictions") { + pred <- get.e0.prediction(sim.dir, subdir = subdir) + if (is.null(pred)) stop('Prediction not found in ', file.path(sim.dir, subdir), + '. Check available.e0.predictions() and use the subdir argument to set non-standard prediction subdirectory.') joint.male <- get.e0.jmale.prediction(pred) - if (is.null(joint.male)) stop('No valid male prediction in ', sim.dir) + if (is.null(joint.male)) stop('No valid male prediction in ', file.path(sim.dir, subdir)) mcmc.set <- pred$mcmc.set if(is.null(countries)) { cat('\nNo countries given. Nothing to be done.\n') @@ -485,11 +487,11 @@ e0.median.adjust.jmale <- function(sim.dir, countries, factors = c(1.2, 1.1)) { new.meds[get.country.object(countries[icountry], mcmc.set$meta)$index,], joint.male = TRUE) } # reload adjusted prediction - invisible(get.e0.prediction(sim.dir, joint.male = TRUE)) + invisible(get.e0.prediction(sim.dir, joint.male = TRUE, subdir = subdir)) } -e0.shift.prediction.to.wpp <- function(sim.dir, joint.male = FALSE, ...){ - pred <- get.e0.prediction(sim.dir, joint.male = joint.male) +e0.shift.prediction.to.wpp <- function(sim.dir, joint.male = FALSE, subdir = "predictions", ...){ + pred <- get.e0.prediction(sim.dir, joint.male = joint.male, subdir = subdir) new.pred <- bayesTFR:::.do.shift.prediction.to.wpp(pred, wpp.dataset = if(joint.male) "e0Mproj" else "e0Fproj", ...) .e0.store.adjustment(new.pred, sim.dir, joint.male) diff --git a/man/convert.trajectories.Rd b/man/convert.trajectories.Rd index 78d69aaa..3fc82ec3 100644 --- a/man/convert.trajectories.Rd +++ b/man/convert.trajectories.Rd @@ -8,11 +8,12 @@ Converts trajectories of the life expectancy stored in a binary format into two } \usage{ convert.e0.trajectories(dir = file.path(getwd(), "bayesLife.output"), - n = 1000, output.dir = NULL, verbose = FALSE) + n = 1000, subdir = "predictions", output.dir = NULL, verbose = FALSE) } \arguments{ \item{dir}{Directory containing the prediction object. It should correspond to the \code{output.dir} argument of the \code{\link{e0.predict}} function.} \item{n}{Number of trajectories to be stored. It can be either a single number or the word \dQuote{all} in which case all available trajectories are converted.} + \item{subdir}{Name of subdirectory of \code{dir} containing the prediction.} \item{output.dir}{Directory in which the resulting files will be stored. If \code{NULL} the same directory is used as for the prediction. Otherwise, if the directory contains joint predictions for both sexes, the ouptuts are stored into subdirectories \file{F} and \file{M}.} \item{verbose}{Logical switching log messages on and off.} } diff --git a/man/e0.median.set.Rd b/man/e0.median.set.Rd index 2e380d1c..cf7c8730 100644 --- a/man/e0.median.set.Rd +++ b/man/e0.median.set.Rd @@ -12,16 +12,18 @@ Editing the Projection Medians These functions are to be used by expert analysts. They allow to change the projection medians either to specific values, including the WPP values, or shift the medians by a given constant or a factor. } \usage{ -e0.median.set(sim.dir, country, values, years = NULL, joint.male = FALSE) +e0.median.set(sim.dir, country, values, years = NULL, joint.male = FALSE, \dots) e0.median.shift(sim.dir, country, reset = FALSE, shift = 0, - from = NULL, to = NULL, joint.male = FALSE) + from = NULL, to = NULL, joint.male = FALSE, \dots) -e0.median.adjust.jmale(sim.dir, countries, factors = c(1.2, 1.1)) +e0.median.adjust.jmale(sim.dir, countries, factors = c(1.2, 1.1), + subdir = "predictions") -e0.median.reset(sim.dir, countries = NULL, joint.male = FALSE) +e0.median.reset(sim.dir, countries = NULL, joint.male = FALSE, \dots) -e0.shift.prediction.to.wpp(sim.dir, joint.male = FALSE, ...) +e0.shift.prediction.to.wpp(sim.dir, joint.male = FALSE, + subdir = "predictions", \dots) } \arguments{ \item{sim.dir}{Directory containing the prediction object.} @@ -36,12 +38,13 @@ e0.shift.prediction.to.wpp(sim.dir, joint.male = FALSE, ...) \item{from}{Year from which the offset/reset should start. By default, it starts at the first prediction period.} \item{to}{Year until which the offset/reset should be done. By default, it is set to the last prediction period.} \item{factors}{It should be a vector where each element corresponds to one time period. The adjustment of male medians is done as \code{e0m(t) = e0f(t) - gap(t)*factor(t)}.} - \item{\dots}{Additional arguments passed to the underlying adjustment function. It can be \code{verbose} to show/hide the progress of the adjustment and \code{wpp.year} to adjust it to if it differs from the wpp year of the simulation.} + \item{subdir}{Subdirectory of \code{sim.dir} containing the predictions.} + \item{\dots}{Additional arguments passed to the underlying adjustment function. For \code{e0.shift.prediction.to.wpp} it can be \code{stat} with values \dQuote{median} (default) or \dQuote{mean} to specify which statistics should be adjusted; \code{verbose} to show/hide the progress of the adjustment and \code{wpp.year} to adjust it to if it differs from the wpp year of the simulation. For the other functions it can be \code{subdir} to specify the location of the prediction.} } \details{ The function \code{e0.median.set} can be used to set the medians of the given country to specific values. Function \code{e0.median.shift} can be used to offset the medians by a specific constant, or to reset the medians to their original BHM values. Function \code{e0.median.adjust.jmale} adjusts male medians using factors that can expand or shrink the female-male gap. -Function\code{e0.shift.prediction.to.wpp} shifts the projected medians so that they correspond to the values found in the \code{e0Fproj} (\code{joint.male = FALSE}) or \code{e0Mproj} (\code{joint.male = TRUE}) datasets of the \pkg{wpp} package that either corresponds to the package used for the simulation itself or is given by the \code{wpp.year} argument. If using \pkg{wpp2022}, the dataset name is automatically adjusted depending if it is an annual or a 5-year simulation. +Function\code{e0.shift.prediction.to.wpp} shifts the projected medians or means (if \code{stat} is \dQuote{mean}) so that they correspond to the values found in the \code{e0Fproj} (\code{joint.male = FALSE}) or \code{e0Mproj} (\code{joint.male = TRUE}) datasets of the \pkg{wpp} package that either corresponds to the package used for the simulation itself or is given by the \code{wpp.year} argument. If using \pkg{wpp2022} or higher, the dataset name is automatically adjusted depending if it is an annual or a 5-year simulation. Note that regardless if it is an adjustment of the median or mean, the corresponding offset is always converted to a shift of the median. Function \code{e0.median.reset} resets medians of the given countries to the original values. By default it deletes adjustments for all countries. diff --git a/man/e0.predict.Rd b/man/e0.predict.Rd index b4aae13b..62390a21 100644 --- a/man/e0.predict.Rd +++ b/man/e0.predict.Rd @@ -13,8 +13,8 @@ e0.predict(mcmc.set = NULL, end.year = 2100, sim.dir = file.path(getwd(), "bayesLife.output"), replace.output = FALSE, predict.jmale = TRUE, nr.traj = NULL, thin = NULL, burnin = 10000, use.diagnostics = FALSE, save.as.ascii = 0, start.year = NULL, - output.dir = NULL, low.memory = TRUE, ignore.last.observed = FALSE, - seed = NULL, verbose = TRUE, \dots) + output.dir = NULL, subdir = "predictions", low.memory = TRUE, + ignore.last.observed = FALSE, seed = NULL, verbose = TRUE, \dots) } \arguments{ @@ -31,6 +31,7 @@ e0.predict(mcmc.set = NULL, end.year = 2100, \item{save.as.ascii}{Either a number determining how many trajectories should be converted into an ASCII file, or \dQuote{all} in which case all trajectories are converted. It should be set to 0, if no conversion is desired (default).} \item{start.year}{This argument should be only used if the start year of the prediction is before or at the present year of the MCMC run (see Details below). By default the prediction starts in the next time period after the present year (passed to \code{\link{run.e0.mcmc}}).} \item{output.dir}{Directory into which the resulting prediction object and the trajectories are stored. If it is \code{NULL}, it is set to either \code{sim.dir}, or to \code{output.dir} of \code{mcmc.set$meta} if \code{mcmc.set} is given.} + \item{subdir}{Subdirectory of \code{output.dir} to store the predictions. It is defined relative to \code{output.dir} and can only have one level.} \item{low.memory}{Logical indicating if the prediction should run in a low-memory mode. If it is \code{FALSE}, the whole traces of all parameters, including the burnin, are loaded into memory. Otherwise, burnins are discarded and parameters are loaded as they are needed and are not kept in the memory.} \item{ignore.last.observed}{Logical. By default, the prediction (or imputation) for each country starts one time period after the last observed data point for that country defined by the \dQuote{last.observed} column in the data. If this argument is set to \code{TRUE}, the prediction ignores that \dQuote{last.observed} value and starts at the last data point found in the data. This allows to exclude some time periods from the estimation, but include them in the prediction.} \item{seed}{Seed of the random number generator. If \code{NULL} no seed is set. It can be used to generate reproducible projections.} @@ -44,7 +45,7 @@ The projection is run for all missing values before the present year, if any. Me A special case is when the argument \code{start.year} is given that is smaller or equal the present year. In such a case, imputed missing values before present year are treated as ordinary predictions (trajectories are kept). All historical data between start year and present year are used as projections. -The resulting prediction object is saved into \file{\{output.dir\}/predictions}. Trajectories for all countries are saved into the same directory in a binary format, one file per country. At the end of the projection, if \code{save.as.ascii} is larger than 0, the function converts the given number of trajectories into a CSV file of a UN-specific format. They are selected by equal spacing (see function \code{\link{convert.e0.trajectories}} for more details on the conversion). In addition, two summary files are created: one in a user-friendly format, the other using a UN-specific coding of the variants and time (see \code{\link{write.e0.projection.summary}} for more details). +The resulting prediction object is saved into \file{\{output.dir\}/\{subdir\}}. Trajectories for all countries are saved into the same directory in a binary format, one file per country. At the end of the projection, if \code{save.as.ascii} is larger than 0, the function converts the given number of trajectories into a CSV file of a UN-specific format. They are selected by equal spacing (see function \code{\link{convert.e0.trajectories}} for more details on the conversion). In addition, two summary files are created: one in a user-friendly format, the other using a UN-specific coding of the variants and time (see \code{\link{write.e0.projection.summary}} for more details). } \value{ diff --git a/man/e0.predict.extra.Rd b/man/e0.predict.extra.Rd index ed8de2a0..b78b40c6 100644 --- a/man/e0.predict.extra.Rd +++ b/man/e0.predict.extra.Rd @@ -9,12 +9,13 @@ Using the posterior parameter samples the function generates posterior trajector } \usage{ e0.predict.extra(sim.dir = file.path(getwd(), 'bayesLife.output'), - prediction.dir = sim.dir, countries = NULL, + prediction.dir = sim.dir, subdir = "predictions", countries = NULL, save.as.ascii = 1000, verbose = TRUE, \dots) } \arguments{ \item{sim.dir}{Directory with the MCMC simulation results.} \item{prediction.dir}{Directory where the prediction object and the trajectories are stored.} + \item{subdir}{Subdirectory of \code{prediction.dir} containing the predictions.} \item{countries}{Vector of country codes for which the prediction should be made. If it is \code{NULL}, the prediction is run for all countries that are included in the MCMC object but for which no prediction was generated.} \item{save.as.ascii}{Either a number determining how many trajectories should be converted into an ascii file, or \dQuote{all} in which case all trajectories are converted. It should be set to 0, if no converions is desired. Note that the convertion is done on all countries.} \item{verbose}{Logical switching log messages on and off.} diff --git a/man/e0.predict.subnat.Rd b/man/e0.predict.subnat.Rd index 8056cb25..05fff657 100644 --- a/man/e0.predict.subnat.Rd +++ b/man/e0.predict.subnat.Rd @@ -14,8 +14,8 @@ e0.predict.subnat(countries, my.e0.file, sim.dir = file.path(getwd(), "bayesLife.output"), method = c("ar1", "shift", "scale"), predict.jmale = FALSE, my.e0M.file = NULL, - end.year = 2100, start.year = NULL, output.dir = NULL, - annual = NULL, nr.traj = NULL, seed = NULL, + end.year = 2100, start.year = NULL, subdir = "predictions", + output.dir = NULL, annual = NULL, nr.traj = NULL, seed = NULL, ar.pars = NULL, save.as.ascii = 0, verbose = TRUE, jmale.estimates = NULL, \dots) @@ -35,6 +35,7 @@ subnat.gap.estimates(annual = FALSE) \item{my.e0M.file}{Tab-separated ASCII file containing the subnational male e0 data.} \item{end.year}{End year of the projections.} \item{start.year}{Start year of the projections. By default, projections start at the same time point as the national projections.} + \item{subdir}{Subdirectory of \code{sim.dir} containing the national predictions.} \item{output.dir}{Directory into which the resulting prediction objects and the trajectories are stored. See below for details.} \item{annual}{Logical indicating if the subnational projection should be on an annual scale or a 5-year scale. By default, the scale is matched to the national simulation given by \code{sim.dir}. If given, the scale must match to the scale of the subnational data provided in \code{my.e0.file}. diff --git a/man/get.e0.prediction.Rd b/man/get.e0.prediction.Rd index a5bd7e53..b839b570 100644 --- a/man/get.e0.prediction.Rd +++ b/man/get.e0.prediction.Rd @@ -3,21 +3,25 @@ \alias{get.e0.jmale.prediction} \alias{has.e0.prediction} \alias{has.e0.jmale.prediction} +\alias{available.e0.predictions} \title{ Accessing a Prediction Object } \description{ -Function \code{get.e0.prediction} retrieves results of a prediction and creates an object of class \code{\link{bayesLife.prediction}}. Function \code{has.e0.prediction} checks an existence of such results. Analogously, functions \code{get.e0.jmale.prediction} and \code{has.e0.jmale.prediction} retrieve and check an existence of male predictions from a given female prediction object. +Function \code{get.e0.prediction} retrieves results of a prediction and creates an object of class \code{\link{bayesLife.prediction}}. Function \code{has.e0.prediction} checks an existence of such results. Analogously, functions \code{get.e0.jmale.prediction} and \code{has.e0.jmale.prediction} retrieve and check an existence of male predictions from a given female prediction object. Function \code{available.e0.predictions} lists predictions available in the given simulation directory. } \usage{ -get.e0.prediction(mcmc = NULL, sim.dir = NULL, joint.male = FALSE, mcmc.dir = NULL) +get.e0.prediction(mcmc = NULL, sim.dir = NULL, joint.male = FALSE, + mcmc.dir = NULL, subdir = "predictions") -has.e0.prediction(mcmc = NULL, sim.dir = NULL) +has.e0.prediction(mcmc = NULL, sim.dir = NULL, subdir = "predictions") get.e0.jmale.prediction(e0.pred) has.e0.jmale.prediction(e0.pred) + +available.e0.predictions(mcmc = NULL, sim.dir = NULL, full.names = FALSE) } \arguments{ @@ -25,9 +29,13 @@ has.e0.jmale.prediction(e0.pred) \item{sim.dir}{Directory where the prediction is stored. It should correspond to the value of the \code{output.dir} argument used in the \code{\link{e0.predict}} function. Only relevant if \code{mcmc} is \code{NULL}.} \item{joint.male}{Logical. If \code{TRUE}, the function is applied to a male prediction that was generated using the joint female-male model implemented in the function \code{\link{e0.jmale.predict}}.} \item{mcmc.dir}{Optional argument to be used only in a special case when the mcmc object contained in the prediction object was estimated in different directory than in the one to which it points to (for example due to moving or renaming the original directory). The argument causes that the mcmc is redirected to the given directory.} + \item{subdir}{Subdirectory of \code{sim.dir} for this particular prediction.} + \item{full.names}{Logical. If \code{TRUE}, the directory names are given as full paths, otherwise (default) only the base names.} \item{e0.pred}{Object of class \code{\link{bayesLife.prediction}}.} } \details{If \code{mcmc} is not \code{NULL}, the search directory is set to \code{mcmc$meta$output.dir}. This approach assumes that the prediction was stored in the same directory as the MCMC simulation, i.e. the \code{output.dir} argument of the \code{\link{e0.predict}} function was set to \code{NULL}. If it is not the case, the argument \code{mcmc.dir} should be used. + +Usually, all predictions are stored in the subdirectory \dQuote{predictions} of the simulation directory. If the subdirectory has a different name, the argument \code{subdir} should be used. This allows to keep multiple predictions in one (MCMC) simulation directory. The function \code{available.e0.predictions} can be used to view all available predictions in the simulation directory. Function \code{get.e0.jmale.prediction} extracts male projections from the \code{e0.pred} objects (which should be a female prediction object), if the male prediction was generated using the \code{\link{e0.jmale.predict}} function. \code{has.e0.jmale.prediction} checks if such male prediction was generated. } @@ -36,7 +44,10 @@ Function \code{get.e0.jmale.prediction} extracts male projections from the \code Functions \code{has.e0.prediction} and \code{has.e0.jmale.prediction} return a logical indicating if a prediction exists. Functions \code{get.e0.prediction} and \code{get.e0.jmale.prediction} return an -object of class \code{\link{bayesLife.prediction}}.} +object of class \code{\link{bayesLife.prediction}}. + + Function \code{available.e0.predictions} returns a vector of directory names containing e0 predictions. +} \author{ Hana Sevcikova diff --git a/man/include.Rd b/man/include.Rd index 40cc0789..3b010e1c 100644 --- a/man/include.Rd +++ b/man/include.Rd @@ -6,6 +6,7 @@ \alias{include_2010} \alias{include_2012} \alias{include_2022} +\alias{include_2024} \docType{data} \title{ @@ -15,6 +16,7 @@ Inclusion Codes Datasets containing codes that determine which countries are to be included into a simulation or/and projections. } \usage{ +data(include_2024) data(include_2022) data(include_2019) data(include_2017) diff --git a/man/write.projection.summary.Rd b/man/write.projection.summary.Rd index 02eac400..7d686123 100644 --- a/man/write.projection.summary.Rd +++ b/man/write.projection.summary.Rd @@ -8,10 +8,11 @@ The function creates two files containing projection summaries, such as the medi } \usage{ write.e0.projection.summary(dir = file.path(getwd(), "bayesLife.output"), - output.dir = NULL, revision = NULL, adjusted = FALSE) + subdir = "predictions", output.dir = NULL, revision = NULL, adjusted = FALSE) } \arguments{ \item{dir}{Directory containing the prediction object. It should correspond to the \code{output.dir} argument of the \code{\link{e0.predict}} function.} + \item{subdir}{Subdirectory of \code{dir} containing the predictions.} \item{output.dir}{Directory in which the resulting file will be stored. If \code{NULL} the same directory is used as for the prediction.} \item{revision}{UN revision number. If \code{NULL} it is determined from the corresponding WPP year: WPP 2008 corresponds to revision 13, every subsequent WPP increases the revision number by one. Used as a constant in the second file only.} \item{adjusted}{Logical. By default the function writes summary using the original BHM projections. If the projection medians are adjusted (using e.g. \code{\link{e0.median.set}}), setting this argument to \code{TRUE} causes writing the adjusted projections.} diff --git a/tests/run_tests.R b/tests/run_tests.R index 0658f204..04677eb2 100644 --- a/tests/run_tests.R +++ b/tests/run_tests.R @@ -26,10 +26,10 @@ if(!cran) { test.subnational.predictions() test.my.locations.extra() test.reproduce.simulation() - for (wpp in c(2019, 2022)){ + for (wpp in c(2019, 2024)){ test.estimate.mcmc(wpp.year = wpp) test.run.annual.simulation(wpp.year = wpp) } - for(wpp.year in c(2010, 2012, 2015, 2017, 2022)) + for(wpp.year in c(2010, 2012, 2015, 2017, 2022, 2024)) test.get.wpp.data(wpp.year) } From 94780a40847a319b81e3c4dd4a01fa3b58dd733e Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Fri, 1 Nov 2024 11:42:21 -0700 Subject: [PATCH 17/20] updated include_2024 --- ChangeLog | 2 +- DESCRIPTION | 4 +- data-raw/include_2024.txt | 580 +++++++++++++++++++------------------- data/include_2024.rda | Bin 815 -> 896 bytes 4 files changed, 293 insertions(+), 293 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61d748a1..c8170649 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -5.2-0.9xxx (10/31/2024) +5.3-0 (11/01/2024) ----- Added dataset include_2024. diff --git a/DESCRIPTION b/DESCRIPTION index 7e93381a..8e0ed461 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.2-0.9012 -Date: 2024-10-31 +Version: 5.3-0 +Date: 2024-11-01 Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn Maintainer: Hana Sevcikova Authors@R: c(person(given = "Hana", diff --git a/data-raw/include_2024.txt b/data-raw/include_2024.txt index 40f94ed2..2a3ebded 100644 --- a/data-raw/include_2024.txt +++ b/data-raw/include_2024.txt @@ -1,290 +1,290 @@ -name country_code include_code hiv_projection -World 900 0 0 -Sustainable Development Goal (SDG) regions 1828 0 0 -Sub-Saharan Africa 947 0 0 -Northern Africa and Western Asia 1833 0 0 -Central and Southern Asia 921 0 0 -Eastern and South-Eastern Asia 1832 0 0 -Latin America and the Caribbean 1830 0 0 -Australia/New Zealand 927 0 0 -Oceania (excluding Australia and New Zealand) 1835 0 0 -Europe and Northern America 1829 0 0 -Geographic regions 1840 0 0 -Africa 903 0 0 -Asia 935 0 0 -Europe 908 0 0 -Latin America and the Caribbean 904 0 0 -Northern America 905 0 0 -Oceania 909 0 0 -UN development groups 1803 0 0 -More developed regions 901 0 0 -Less developed regions 902 0 0 -Least developed countries 941 0 0 -"Less developed regions, excluding least developed countries" 934 0 0 -"Less developed regions, excluding China" 948 0 0 -Land-locked Developing Countries (LLDC) 1636 0 0 -Small Island Developing States (SIDS) 1637 0 0 -World Bank Income Groups 1802 0 0 -High-income countries 1503 0 0 -Middle-income countries 1517 0 0 -Upper-middle-income countries 1502 0 0 -Lower-middle-income countries 1501 0 0 -Low-income countries 1500 0 0 -No income group available 1518 0 0 -Eastern Africa 910 0 0 -Burundi 108 2 1 -Comoros 174 2 0 -Djibouti 262 2 1 -Eritrea 232 2 1 -Ethiopia 231 2 1 -Kenya 404 3 1 -Madagascar 450 2 0 -Malawi 454 3 1 -Mauritius 480 2 1 -Mayotte 175 2 0 -Mozambique 508 3 1 -Reunion 638 2 0 -Rwanda 646 3 1 -Seychelles 690 2 0 -Somalia 706 2 0 -South Sudan 728 2 1 -Uganda 800 3 1 -United Republic of Tanzania 834 3 1 -Zambia 894 3 1 -Zimbabwe 716 3 1 -Middle Africa 911 0 0 -Angola 24 2 1 -Cameroon 120 3 1 -Central African Republic 140 3 1 -Chad 148 2 1 -Congo 178 3 1 -Democratic Republic of the Congo 180 2 1 -Equatorial Guinea 226 3 1 -Gabon 266 3 1 -Sao Tome and Principe 678 2 0 -Southern Africa 913 0 0 -Botswana 72 3 1 -Eswatini 748 3 1 -Lesotho 426 3 1 -Namibia 516 3 1 -South Africa 710 3 1 -Western Africa 914 0 0 -Benin 204 2 1 -Burkina Faso 854 2 1 -Cabo Verde 132 2 1 -Cote d'Ivoire 384 3 1 -Gambia 270 2 1 -Ghana 288 2 1 -Guinea 324 2 1 -Guinea-Bissau 624 3 1 -Liberia 430 2 1 -Mali 466 2 1 -Mauritania 478 2 1 -Niger 562 2 0 -Nigeria 566 2 1 -Saint Helena 654 2 0 -Senegal 686 2 0 -Sierra Leone 694 2 1 -Togo 768 3 1 -Northern Africa 912 0 0 -Algeria 12 2 0 -Egypt 818 2 0 -Libya 434 2 0 -Morocco 504 2 0 -Sudan 729 2 0 -Tunisia 788 2 0 -Western Sahara 732 2 0 -Western Asia 922 0 0 -Armenia 51 2 0 -Azerbaijan 31 2 0 -Bahrain 48 2 0 -Cyprus 196 2 0 -Georgia 268 2 0 -Iraq 368 2 0 -Israel 376 2 0 -Jordan 400 2 0 -Kuwait 414 2 0 -Lebanon 422 2 0 -Oman 512 2 0 -Qatar 634 2 0 -Saudi Arabia 682 2 0 -State of Palestine 275 2 0 -Syrian Arab Republic 760 2 0 -Türkiye 792 2 0 -United Arab Emirates 784 2 0 -Yemen 887 2 0 -Central Asia 5500 0 0 -Kazakhstan 398 2 0 -Kyrgyzstan 417 2 0 -Tajikistan 762 2 0 -Turkmenistan 795 2 0 -Uzbekistan 860 2 0 -Southern Asia 5501 0 0 -Afghanistan 4 2 0 -Bangladesh 50 2 0 -Bhutan 64 2 0 -India 356 2 0 -Iran (Islamic Republic of) 364 2 0 -Maldives 462 2 0 -Nepal 524 2 0 -Pakistan 586 2 0 -Sri Lanka 144 2 0 -Eastern Asia 906 0 0 -China 156 2 0 -"China, Hong Kong SAR" 344 2 0 -"China, Macao SAR" 446 2 0 -"China, Taiwan Province of China" 158 2 0 -Dem. People's Republic of Korea 408 2 0 -Japan 392 2 0 -Mongolia 496 2 0 -Republic of Korea 410 2 0 -South-Eastern Asia 920 0 0 -Brunei Darussalam 96 2 0 -Cambodia 116 2 1 -Indonesia 360 2 0 -Lao People's Democratic Republic 418 2 0 -Malaysia 458 2 0 -Myanmar 104 2 1 -Philippines 608 2 0 -Singapore 702 2 0 -Thailand 764 2 1 -Timor-Leste 626 2 0 -Viet Nam 704 2 0 -Caribbean 915 0 0 -Anguilla 660 2 0 -Antigua and Barbuda 28 2 0 -Aruba 533 2 0 -Bahamas 44 2 1 -Barbados 52 2 1 -"Bonaire, Sint Eustatius and Saba" 535 2 0 -British Virgin Islands 92 2 0 -Cayman Islands 136 2 0 -Cuba 192 2 0 -Curacao 531 2 0 -Dominica 212 2 0 -Dominican Republic 214 2 1 -Grenada 308 2 0 -Guadeloupe 312 2 0 -Haiti 332 2 1 -Jamaica 388 2 1 -Martinique 474 2 0 -Montserrat 500 2 0 -Puerto Rico 630 2 0 -Saint Kitts and Nevis 659 2 0 -Saint Lucia 662 2 0 -Saint Vincent and the Grenadines 670 2 0 -Saint-Barthelemy 652 2 0 -Saint-Martin (French part) 663 2 0 -Sint Maarten (Dutch part) 534 2 0 -Trinidad and Tobago 780 2 1 -Turks and Caicos Islands 796 2 0 -United States Virgin Islands 850 2 0 -Central America 916 0 0 -Belize 84 2 1 -Costa Rica 188 2 0 -El Salvador 222 2 0 -Guatemala 320 2 0 -Honduras 340 2 1 -Mexico 484 2 0 -Nicaragua 558 2 0 -Panama 591 2 1 -South America 931 0 0 -Argentina 32 2 0 -Bolivia (Plurinational State of) 68 2 0 -Brazil 76 2 0 -Chile 152 2 0 -Colombia 170 2 0 -Ecuador 218 2 0 -Falkland Islands (Malvinas) 238 2 0 -French Guiana 254 2 0 -Guyana 328 2 1 -Paraguay 600 2 0 -Peru 604 2 0 -Suriname 740 2 1 -Uruguay 858 2 0 -Venezuela (Bolivarian Republic of) 862 2 0 -Australia 36 2 0 -New Zealand 554 2 0 -Melanesia 928 0 0 -Fiji 242 2 0 -New Caledonia 540 2 0 -Papua New Guinea 598 2 1 -Solomon Islands 90 2 0 -Vanuatu 548 2 0 -Micronesia 954 0 0 -Guam 316 2 0 -Kiribati 296 2 0 -Marshall Islands 584 2 0 -Micronesia (Fed. States of) 583 2 0 -Nauru 520 2 0 -Northern Mariana Islands 580 2 0 -Palau 585 2 0 -Polynesia 957 0 0 -American Samoa 16 2 0 -Cook Islands 184 2 0 -French Polynesia 258 2 0 -Niue 570 2 0 -Samoa 882 2 0 -Tokelau 772 2 0 -Tonga 776 2 0 -Tuvalu 798 2 0 -Wallis and Futuna Islands 876 2 0 -Eastern Europe 923 0 0 -Belarus 112 2 0 -Bulgaria 100 2 0 -Czechia 203 2 0 -Hungary 348 2 0 -Poland 616 2 0 -Republic of Moldova 498 2 0 -Romania 642 2 0 -Russian Federation 643 2 1 -Slovakia 703 2 0 -Ukraine 804 2 1 -Northern Europe 924 0 0 -Denmark 208 2 0 -Estonia 233 2 0 -Faroe Islands 234 2 0 -Finland 246 2 0 -Guernsey 831 2 0 -Iceland 352 2 0 -Ireland 372 2 0 -Isle of Man 833 2 0 -Jersey 832 2 0 -Latvia 428 2 0 -Lithuania 440 2 0 -Norway 578 2 0 -Sweden 752 2 0 -United Kingdom 826 2 0 -Southern Europe 925 0 0 -Albania 8 2 0 -Andorra 20 2 0 -Bosnia and Herzegovina 70 2 0 -Croatia 191 2 0 -Gibraltar 292 2 0 -Greece 300 2 0 -Holy See 336 2 0 -Italy 380 2 0 -Kosovo (under UNSC res. 1244) 412 2 0 -Malta 470 2 0 -Montenegro 499 2 0 -North Macedonia 807 2 0 -Portugal 620 2 0 -San Marino 674 2 0 -Serbia 688 2 0 -Slovenia 705 2 0 -Spain 724 2 0 -Western Europe 926 0 0 -Austria 40 2 0 -Belgium 56 2 0 -France 250 2 0 -Germany 276 2 0 -Liechtenstein 438 2 0 -Luxembourg 442 2 0 -Monaco 492 2 0 -Netherlands 528 2 0 -Switzerland 756 2 0 -Bermuda 60 2 0 -Canada 124 2 0 -Greenland 304 2 0 -Saint Pierre and Miquelon 666 2 0 -United States of America 840 2 0 +name country_code include_code hiv_projection +World 900 0 0 +Sustainable Development Goal (SDG) regions 1828 0 0 +Sub-Saharan Africa 947 0 0 +Northern Africa and Western Asia 1833 0 0 +Central and Southern Asia 921 0 0 +Eastern and South-Eastern Asia 1832 0 0 +Latin America and the Caribbean 1830 0 0 +Australia/New Zealand 927 0 0 +Oceania (excluding Australia and New Zealand) 1835 0 0 +Europe and Northern America 1829 0 0 +Geographic regions 1840 0 0 +Africa 903 0 0 +Asia 935 0 0 +Europe 908 0 0 +Latin America and the Caribbean 904 0 0 +Northern America 905 0 0 +Oceania 909 0 0 +UN development groups 1803 0 0 +More developed regions 901 0 0 +Less developed regions 902 0 0 +Least developed countries 941 0 0 +Less developed regions, excluding least developed countries 934 0 0 +Less developed regions, excluding China 948 0 0 +Land-locked Developing Countries (LLDC) 1636 0 0 +Small Island Developing States (SIDS) 1637 0 0 +World Bank Income Groups 1802 0 0 +High-income countries 1503 0 0 +Middle-income countries 1517 0 0 +Upper-middle-income countries 1502 0 0 +Lower-middle-income countries 1501 0 0 +Low-income countries 1500 0 0 +No income group available 1518 0 0 +Eastern Africa 910 0 0 +Burundi 108 2 1 +Comoros 174 2 0 +Djibouti 262 2 1 +Eritrea 232 2 1 +Ethiopia 231 2 1 +Kenya 404 3 1 +Madagascar 450 2 0 +Malawi 454 3 1 +Mauritius 480 2 1 +Mayotte 175 2 0 +Mozambique 508 3 1 +Reunion 638 2 0 +Rwanda 646 3 1 +Seychelles 690 2 0 +Somalia 706 2 0 +South Sudan 728 2 1 +Uganda 800 3 1 +United Republic of Tanzania 834 3 1 +Zambia 894 3 1 +Zimbabwe 716 3 1 +Middle Africa 911 0 0 +Angola 24 2 1 +Cameroon 120 3 1 +Central African Republic 140 3 1 +Chad 148 2 1 +Congo 178 3 1 +Democratic Republic of the Congo 180 2 1 +Equatorial Guinea 226 3 1 +Gabon 266 3 1 +Sao Tome and Principe 678 2 0 +Southern Africa 913 0 0 +Botswana 72 3 1 +Eswatini 748 3 1 +Lesotho 426 3 1 +Namibia 516 3 1 +South Africa 710 3 1 +Western Africa 914 0 0 +Benin 204 2 1 +Burkina Faso 854 2 1 +Cabo Verde 132 2 1 +Cote d'Ivoire 384 3 1 +Gambia 270 2 1 +Ghana 288 2 1 +Guinea 324 2 1 +Guinea-Bissau 624 3 1 +Liberia 430 2 1 +Mali 466 2 1 +Mauritania 478 2 1 +Niger 562 2 0 +Nigeria 566 2 1 +Saint Helena 654 1 0 +Senegal 686 2 0 +Sierra Leone 694 2 1 +Togo 768 3 1 +Northern Africa 912 0 0 +Algeria 12 2 0 +Egypt 818 2 0 +Libya 434 2 0 +Morocco 504 2 0 +Sudan 729 2 0 +Tunisia 788 2 0 +Western Sahara 732 2 0 +Western Asia 922 0 0 +Armenia 51 2 0 +Azerbaijan 31 2 0 +Bahrain 48 2 0 +Cyprus 196 2 0 +Georgia 268 2 0 +Iraq 368 2 0 +Israel 376 2 0 +Jordan 400 2 0 +Kuwait 414 2 0 +Lebanon 422 2 0 +Oman 512 2 0 +Qatar 634 2 0 +Saudi Arabia 682 2 0 +State of Palestine 275 2 0 +Syrian Arab Republic 760 2 0 +Türkiye 792 2 0 +United Arab Emirates 784 2 0 +Yemen 887 2 0 +Central Asia 5500 0 0 +Kazakhstan 398 2 0 +Kyrgyzstan 417 2 0 +Tajikistan 762 2 0 +Turkmenistan 795 2 0 +Uzbekistan 860 2 0 +Southern Asia 5501 0 0 +Afghanistan 4 2 0 +Bangladesh 50 2 0 +Bhutan 64 2 0 +India 356 2 0 +Iran (Islamic Republic of) 364 2 0 +Maldives 462 2 0 +Nepal 524 2 0 +Pakistan 586 2 0 +Sri Lanka 144 2 0 +Eastern Asia 906 0 0 +China 156 2 0 +China, Hong Kong SAR 344 2 0 +China, Macao SAR 446 2 0 +China, Taiwan Province of China 158 2 0 +Dem. People's Republic of Korea 408 2 0 +Japan 392 2 0 +Mongolia 496 2 0 +Republic of Korea 410 2 0 +South-Eastern Asia 920 0 0 +Brunei Darussalam 96 2 0 +Cambodia 116 2 1 +Indonesia 360 2 0 +Lao People's Democratic Republic 418 2 0 +Malaysia 458 2 0 +Myanmar 104 2 1 +Philippines 608 2 0 +Singapore 702 2 0 +Thailand 764 2 1 +Timor-Leste 626 2 0 +Viet Nam 704 2 0 +Caribbean 915 0 0 +Anguilla 660 1 0 +Antigua and Barbuda 28 2 0 +Aruba 533 2 0 +Bahamas 44 2 1 +Barbados 52 2 1 +Bonaire, Sint Eustatius and Saba 535 1 0 +British Virgin Islands 92 1 0 +Cayman Islands 136 1 0 +Cuba 192 2 0 +Curacao 531 2 0 +Dominica 212 1 0 +Dominican Republic 214 2 1 +Grenada 308 2 0 +Guadeloupe 312 2 0 +Haiti 332 2 1 +Jamaica 388 2 1 +Martinique 474 2 0 +Montserrat 500 1 0 +Puerto Rico 630 2 0 +Saint Kitts and Nevis 659 1 0 +Saint Lucia 662 2 0 +Saint Vincent and the Grenadines 670 2 0 +Saint-Barthelemy 652 1 0 +Saint-Martin (French part) 663 1 0 +Sint Maarten (Dutch part) 534 1 0 +Trinidad and Tobago 780 2 1 +Turks and Caicos Islands 796 1 0 +United States Virgin Islands 850 1 0 +Central America 916 0 0 +Belize 84 2 1 +Costa Rica 188 2 0 +El Salvador 222 2 0 +Guatemala 320 2 0 +Honduras 340 2 1 +Mexico 484 2 0 +Nicaragua 558 2 0 +Panama 591 2 1 +South America 931 0 0 +Argentina 32 2 0 +Bolivia (Plurinational State of) 68 2 0 +Brazil 76 2 0 +Chile 152 2 0 +Colombia 170 2 0 +Ecuador 218 2 0 +Falkland Islands (Malvinas) 238 1 0 +French Guiana 254 2 0 +Guyana 328 2 1 +Paraguay 600 2 0 +Peru 604 2 0 +Suriname 740 2 1 +Uruguay 858 2 0 +Venezuela (Bolivarian Republic of) 862 2 0 +Australia 36 2 0 +New Zealand 554 2 0 +Melanesia 928 0 0 +Fiji 242 2 0 +New Caledonia 540 2 0 +Papua New Guinea 598 2 1 +Solomon Islands 90 2 0 +Vanuatu 548 2 0 +Micronesia 954 0 0 +Guam 316 2 0 +Kiribati 296 2 0 +Marshall Islands 584 1 0 +Micronesia (Fed. States of) 583 2 0 +Nauru 520 1 0 +Northern Mariana Islands 580 1 0 +Palau 585 1 0 +Polynesia 957 0 0 +American Samoa 16 1 0 +Cook Islands 184 1 0 +French Polynesia 258 2 0 +Niue 570 1 0 +Samoa 882 2 0 +Tokelau 772 1 0 +Tonga 776 2 0 +Tuvalu 798 1 0 +Wallis and Futuna Islands 876 1 0 +Eastern Europe 923 0 0 +Belarus 112 2 0 +Bulgaria 100 2 0 +Czechia 203 2 0 +Hungary 348 2 0 +Poland 616 2 0 +Republic of Moldova 498 2 0 +Romania 642 2 0 +Russian Federation 643 2 1 +Slovakia 703 2 0 +Ukraine 804 2 1 +Northern Europe 924 0 0 +Denmark 208 2 0 +Estonia 233 2 0 +Faroe Islands 234 1 0 +Finland 246 2 0 +Guernsey 831 1 0 +Iceland 352 2 0 +Ireland 372 2 0 +Isle of Man 833 1 0 +Jersey 832 2 0 +Latvia 428 2 0 +Lithuania 440 2 0 +Norway 578 2 0 +Sweden 752 2 0 +United Kingdom 826 2 0 +Southern Europe 925 0 0 +Albania 8 2 0 +Andorra 20 1 0 +Bosnia and Herzegovina 70 2 0 +Croatia 191 2 0 +Gibraltar 292 1 0 +Greece 300 2 0 +Holy See 336 1 0 +Italy 380 2 0 +Kosovo (under UNSC res. 1244) 412 2 0 +Malta 470 2 0 +Montenegro 499 2 0 +North Macedonia 807 2 0 +Portugal 620 2 0 +San Marino 674 1 0 +Serbia 688 2 0 +Slovenia 705 2 0 +Spain 724 2 0 +Western Europe 926 0 0 +Austria 40 2 0 +Belgium 56 2 0 +France 250 2 0 +Germany 276 2 0 +Liechtenstein 438 1 0 +Luxembourg 442 2 0 +Monaco 492 1 0 +Netherlands 528 2 0 +Switzerland 756 2 0 +Bermuda 60 1 0 +Canada 124 2 0 +Greenland 304 1 0 +Saint Pierre and Miquelon 666 1 0 +United States of America 840 2 0 diff --git a/data/include_2024.rda b/data/include_2024.rda index 5fed3bf2f1990e7f4834b9777fd47c7ddb88979f..a80e9966fb725d10271ed237a13dc1d08cc641b7 100644 GIT binary patch delta 872 zcmV-u1DE`-27m_+LRx4!F+o`-Q&}cC8jnzEy(1wEo>0$HdY+~l zpQ>gNJp}zptsLeD8JvA^iLA<2&+NPeT=|-QTPs*5zc#5B@ zZA_EY$$}aKLq-4)Vlo>mCJBM3s6nGfOoL4gG|(~{27?gO z34fr|Mg#yf28}e(WDJHQBSs@eBSRp0#6JQ7g zCJ819B?vYlHVvo}C^R7m@#@QKEz3+y1b-o(6JQCvLr{bfgUm3Tvrw2Ls(t9M%DINH zj!Y&MvurvX^(&SRT!TGh&`8(;#ryQ)zbYGVe-Bc z9lqX5Ap#J9K6>*u)6t{f?SYlox!b-&W?IqG73Zlr{Pt?>7Pk2sHcZvE-tJAGy?<>L zIuu-j%QjR(w@q%rWij&GbUNzS+1#Aa00bZn!GJXWb?BzQT&qb-umCkAJeoy4wfXv2}ij^C3wc=WZm^8NY1mmo(kI$=}kH z4l&e7-eyk;7l{|cRT>`?e;Qlg@<~im0uncIq}pq;G}>rN=37!!B-U-QrrPWYqzTZ{ zX~DWkO~HdrAZQu}k_N#b1b_jvMHCZA6`|NRn^brLX*5WaRtY+&lK8Ctc7Ik%wQ9!b zbx5izsR)21KtN3t zAc^L&DHNo`q6{S|jrX<)F2@Ojkb75O_}7#e1{@MA5Lv0KCBRJF+br_3ny?KLvzqI! z3$WSM-LUi-GACznb!NINJS(FNTi-Zs+W>cWJr}ns)`VhQarbz000^Q000<*ccKmak;J#H`dY?}vuM&yg;^n)d zKtLe~I|=~`8G!Nr%bJ~c!9?ne(xFu5Vkkef8EJU*tKSL7j(8~#;o(EQ+SnMlO@Gd7 zGp9V%`X3R8IJO(&ppi_;^r})mbdUfL5R?cY0um36Y4;(hHgU>w9#NCsgNDA1+6Gmf zJ?0Ft>Ky6hX`KA5gc9i@Cb2_)RU?VnX4A>v*sp<<1%GY~3%{3Uz`9M*O zMHr$`IBFXv88ZkOGlVw{vKT`M2H=1K7~!#r18KH218FD_2!Ik0Ko)3hx1p&K2yG3J UAp(G#{R{ps Date: Fri, 1 Nov 2024 18:16:35 -0700 Subject: [PATCH 18/20] redundant fields removed --- DESCRIPTION | 2 -- 1 file changed, 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8e0ed461..d7f230bd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,8 +3,6 @@ Type: Package Title: Bayesian Projection of Life Expectancy Version: 5.3-0 Date: 2024-11-01 -Author: Hana Sevcikova, Adrian Raftery, Jennifer Chunn -Maintainer: Hana Sevcikova Authors@R: c(person(given = "Hana", family = "Sevcikova", role = c("cre", "aut"), From 2c6306625d553ef9532e755f53fb97396b39055c Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Wed, 4 Dec 2024 16:46:37 -0800 Subject: [PATCH 19/20] add use.wpp.data to meta if missing --- DESCRIPTION | 4 ++-- R/get_outputs.R | 1 + man/convert.trajectories.Rd | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d7f230bd..aaf286e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.3-0 -Date: 2024-11-01 +Version: 5.3-0.9001 +Date: 2024-12-04 Authors@R: c(person(given = "Hana", family = "Sevcikova", role = c("cre", "aut"), diff --git a/R/get_outputs.R b/R/get_outputs.R index 8bba5f9b..d9235761 100644 --- a/R/get_outputs.R +++ b/R/get_outputs.R @@ -12,6 +12,7 @@ get.e0.mcmc <- function(sim.dir = file.path(getwd(), 'bayesLife.output'), load(file = mcmc.file.path) bayesLife.mcmc.meta$output.dir <- normalizePath(sim.dir) if(is.null(bayesLife.mcmc.meta$annual.simulation)) bayesLife.mcmc.meta$annual.simulation <- FALSE + if(is.null(bayesLife.mcmc.meta$use.wpp.data)) bayesLife.mcmc.meta$use.wpp.data <- TRUE if(is.null(bayesLife.mcmc.meta$mcmc.options)) { bayesLife.mcmc.meta <- .convert.meta.from.legacy.form(bayesLife.mcmc.meta) } diff --git a/man/convert.trajectories.Rd b/man/convert.trajectories.Rd index 3fc82ec3..b97f1f44 100644 --- a/man/convert.trajectories.Rd +++ b/man/convert.trajectories.Rd @@ -19,7 +19,7 @@ convert.e0.trajectories(dir = file.path(getwd(), "bayesLife.output"), } \details{ The function creates two files per sex. One is called \dQuote{ascii_trajectories.csv}, it is a comma-separated table with the following columns: -\itemize{\item{\dQuote{LocID}: }{country code} +\describe{\item{\dQuote{LocID}: }{country code} \item{\dQuote{Period}: }{prediction interval, e.g. 2015-2020} \item{\dQuote{Year}: }{middle year of the prediction interval} \item{\dQuote{Trajectory}: }{identifier of the trajectory} From 1aa8af66a10bb47d1d9ad1b7f4d84b658b51ea91 Mon Sep 17 00:00:00 2001 From: Hana Sevcikova Date: Thu, 5 Dec 2024 12:24:59 -0800 Subject: [PATCH 20/20] help files fixed --- ChangeLog | 2 +- DESCRIPTION | 4 ++-- man/write.projection.summary.Rd | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8170649..2ebea33c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -5.3-0 (11/01/2024) +5.3-0/1 (11/05/2024) ----- Added dataset include_2024. diff --git a/DESCRIPTION b/DESCRIPTION index aaf286e7..b0a9d763 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesLife Type: Package Title: Bayesian Projection of Life Expectancy -Version: 5.3-0.9001 -Date: 2024-12-04 +Version: 5.3-1 +Date: 2024-12-05 Authors@R: c(person(given = "Hana", family = "Sevcikova", role = c("cre", "aut"), diff --git a/man/write.projection.summary.Rd b/man/write.projection.summary.Rd index 7d686123..55043745 100644 --- a/man/write.projection.summary.Rd +++ b/man/write.projection.summary.Rd @@ -19,7 +19,7 @@ write.e0.projection.summary(dir = file.path(getwd(), "bayesLife.output"), } \details{ The first file that the function creates is called \file{projection_summary_user_friendly.csv}, it is a comma-separated table with the following columns: -\itemize{\item{\dQuote{country_name}: }{country name} +\describe{\item{\dQuote{country_name}: }{country name} \item{\dQuote{country_code}: }{country code} \item{\dQuote{variant}: }{name of the variant, such as \dQuote{median}, \dQuote{lower 80}, \dQuote{upper 80}, \dQuote{lower 95}, \dQuote{upper 95}, \dQuote{constant}} \item{period1: }{e.g. \dQuote{2010-2015}: life expectancy for the first time period} @@ -28,7 +28,7 @@ The first file that the function creates is called \file{projection_summary_user } The second file, called \file{projection_summary.csv}, also comma-separated table, contains the same information as above in a UN-specific format: -\itemize{\item{\dQuote{RevID}: }{revision number, passed to the function as an argument;} +\describe{\item{\dQuote{RevID}: }{revision number, passed to the function as an argument;} \item{\dQuote{VarID}: }{variant identifier, extracted from the \code{\link[bayesTFR]{UN_variants}} dataset in the \pkg{bayesTFR} package;} \item{\dQuote{LocID}: }{country code;} \item{\dQuote{TimeID}: }{time identifier, extracted from the \code{\link[bayesTFR]{UN_time}} dataset in the \pkg{bayesTFR} package;}