Learn R Programming

bayesLife (version 5.3-1)

convert.e0.trajectories: Converting Trajectories of Life Expectancy into ACSII Files

Description

Converts trajectories of the life expectancy stored in a binary format into two CSV files of a UN-specific format.

Usage

convert.e0.trajectories(dir = file.path(getwd(), "bayesLife.output"), 
    n = 1000, subdir = "predictions", output.dir = NULL, verbose = FALSE)

Arguments

dir

Directory containing the prediction object. It should correspond to the output.dir argument of the e0.predict function.

n

Number of trajectories to be stored. It can be either a single number or the word “all” in which case all available trajectories are converted.

subdir

Name of subdirectory of dir containing the prediction.

output.dir

Directory in which the resulting files will be stored. If 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 F and M.

verbose

Logical switching log messages on and off.

Author

Hana Sevcikova

Details

The function creates two files per sex. One is called “ascii_trajectories.csv”, it is a comma-separated table with the following columns:

“Period”:

prediction interval, e.g. 2015-2020

“Year”:

middle year of the prediction interval

“Trajectory”:

identifier of the trajectory

“e0”:

life expectancy

The second file is called “ascii_trajectories_wide.csv”, it is also a comma-separated table and it contains the same information as above but in a ‘transposed’ format. I.e. the data for one country are ordered in columns, thus, there is one column per country. The country columns are ordered alphabetically.

If n is smaller than the total number of trajectories, the trajectories are selected using equal spacing.

See Also

write.e0.projection.summary, e0.predict

Examples

Run this code
if (FALSE) {
sim.dir <- file.path(find.package("bayesLife"), "ex-data", "bayesLife.output")
pred.dir <- file.path(getwd(), "exampleLEpred")

# stores 10 trajectories out of 30 (60-30) into 
# exampleLEpred/predictions/ascii_trajectories.csv (for female)
# and exampleLEpred/predictions/joint_male/ascii_trajectories.csv (for male)
e0.predict(sim.dir = sim.dir, output.dir = pred.dir, 
            burnin = 30, save.as.ascii = 10, verbose = TRUE)
            
# stores all 30 trajectories into the current directory
convert.e0.trajectories(dir = pred.dir, n = "all", output.dir = ".", verbose = TRUE)

# Note: If the output.dir argument in e0.predict is omitted, 
# call convert.e0.trajectories with dir = sim.dir 
}

Run the code above in your browser using DataLab