e0.predict {bayesLife} | R Documentation |
Generating Posterior Trajectories of the Life Expectancy
Description
Using the posterior parameter samples simulated by run.e0.mcmc
the function generates posterior trajectories for the life expectancy for all countries of the world.
Usage
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, ...)
Arguments
mcmc.set |
Object of class |
end.year |
End year of the prediction. |
sim.dir |
Directory with the MCMC simulation results. It should equal to the |
replace.output |
Logical. If |
predict.jmale |
Logical controlling if a joint female-male prediciton should be performed. This is done only if the underlying mcmcs in |
nr.traj |
Number of trajectories to be generated. If |
thin |
Thinning interval used for determining the number of trajectories. Only relevant, if |
burnin |
Number of iterations to be discarded from the beginning of the parameter traces. |
use.diagnostics |
Logical determining if an existing convergence diagnostics should be used for choosing the values of |
save.as.ascii |
Either a number determining how many trajectories should be converted into an ASCII file, or “all” in which case all trajectories are converted. It should be set to 0, if no conversion is desired (default). |
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 |
output.dir |
Directory into which the resulting prediction object and the trajectories are stored. If it is |
low.memory |
Logical indicating if the prediction should run in a low-memory mode. If it is |
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 “last.observed” column in the data. If this argument is set to |
seed |
Seed of the random number generator. If |
verbose |
Logical switching log messages on and off. |
... |
Additional arguments passed to the |
Details
The trajectories are generated using the double logistic function (Chunn et al. 2013). Parameter samples simulated via run.e0.mcmc
are used from all chains, from which the given burnin was discarded. They are evenly thinned to match nr.traj
or using the thin
argument. Such thinned parameter traces, collapsed into one chain, if they do not already exist, are stored on disk into the sub-directory ‘thinned_mcmc_t_b’ where t is the value of thin
and b the value of burnin
(see create.thinned.e0.mcmc
).
The projection is run for all missing values before the present year, if any. Medians over the trajectories are used as imputed values and the trajectories are discarded. The process then continues by projecting the future values where all generated trajectories are kept.
A special case is when the argument 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 ‘{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 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 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 write.e0.projection.summary
for more details).
Value
Object of class bayesLife.prediction
which is a list containing components:
quantiles |
A |
traj.mean.sd |
A |
nr.traj |
Number of trajectories. |
e0.matrix.reconstructed |
Matrix containing imputed e0 values on spots where the original e0 matrix has missing values, i.e. between the last observed data point and the present year. |
output.directory |
Directory where trajectories corresponding to this prediction are stored. |
nr.projections |
Number of projections. |
burnin |
Burnin used for this prediction. |
end.year |
The end year of this prediction. |
start.year |
The |
mcmc.set |
Object of class |
joint.male |
If |
Author(s)
Hana Sevcikova, using code from Jennifer Chunn
References
J. L. Chunn, A. E. Raftery, P. Gerland, H. Sevcikova (2013): Bayesian Probabilistic Projections of Life Expectancy for All Countries. Demography 50(3):777-801. <doi:10.1007/s13524-012-0193-x>
See Also
run.e0.mcmc
, e0.jmale.predict
, create.thinned.e0.mcmc
, convert.e0.trajectories
,
get.e0.prediction
, summary.bayesLife.prediction
Examples
## Not run:
m <- run.e0.mcmc(nr.chains = 1, iter = 50, thin = 1, verbose = TRUE)
pred <- e0.predict(m, burnin = 25, verbose = TRUE)
summary(pred, country = "Portugal")
# names and codes of countries included
head(get.countries.table(pred, iso = TRUE))
## End(Not run)