Learn R Programming

bayesTFR (version 1.2-0)

tfr.predict: Generating Posterior Trajectories of the Total Fertility Rate

Description

Using the posterior parameter samples simulated by run.tfr.mcmc the function generates posterior trajectories for the total fertility rate for all countries of the world.

Usage

tfr.predict(mcmc.set = NULL, end.year = 2100, 
    sim.dir = file.path(getwd(), "bayesTFR.output"), 
    replace.output = FALSE, nr.traj = NULL, thin = NULL,
    burnin = 2000, use.diagnostics = FALSE,
    save.as.ascii = 1000, output.dir = NULL,  
    low.memory = TRUE, 
    mu = 2.1, rho = 0.9057, sigmaAR1 = 0.0922,
    seed = NULL, verbose = TRUE)

Arguments

Value

Object of class bayesTFR.prediction which is a list containing components:quantilesA $n \times q \times p$ array of quantile values computed on all trajectories. $n$ is the number of countries, $q$ is the number of quantile bounds and $p$ is the number of projections.traj.mean.sdA $n \times 2 \times p$ array holding the mean of all trajectories in the first column and the standard deviation in the second column. $n$ and $p$ are the number of countries and number of projections, respectively.nr.trajNumber of trajectories.trf_matrix_reconstructedMatrix containing imputed TFR values on spots where the original TFR matrix has missing values, i.e. between the last observed data point and the present year.output.directoryDirectory where trajectories corresponding to this prediction are stored.nr.projectionsNumber of projections.burninBurnin used for this prediction.end.yearThe end year of this prediction.mu, rho, sigma_t, sigmaAR1Parameters of the AR(1) process. sigma_t is a vector of actual values of the standard deviation $s$ used for each projection.na.indexIndex of trajectories for which at least one country got NA values.mcmc.setObject of class bayesTFR.mcmc.set used for this prediction, i.e. the burned, thinned, and collapsed MCMC chain.

Rdversion

1.1

Details

The trajectories are generated using the double logistic function (cite) and the AR(1) process. Parameter samples simulated using run.tfr.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.tfr.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.

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.tfr.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.projection.summary for more details).

References

L. Alkema, A. E. Raftery, P. Gerland, S. J. Clark, F. Pelletier, T. Buettner: Probabilistic projections of the total fertility rate for all countries. Working Paper nr. 97, Center for Statistics and the Social Sciences, University of Washington. http://www.csss.washington.edu/Papers

See Also

run.tfr.mcmc, create.thinned.tfr.mcmc, convert.tfr.trajectories, write.projection.summary, get.tfr.prediction, summary.bayesTFR.prediction

Examples

Run this code
m <- run.tfr.mcmc(nr.chains=1, iter=10, verbose=TRUE)
pred <- tfr.predict(m, burnin=0, verbose=TRUE)
summary(pred, country='Iceland')

Run the code above in your browser using DataLab