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

convert.e0.trajectoriesR Documentation

Converting Trajectories of Life Expectancy into ACSII Files


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


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



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


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.


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’.


Logical switching log messages on and off.


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

  • “LocID”: country code

  • “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.


This function is automatically called from the e0.predict function, therefore in standard cases it will not be needed to call it directly. However, it can be useful for example, if different number of trajectories are to be converted, without having to re-run the prediction.


Hana Sevcikova

See Also

write.e0.projection.summary, e0.predict


## Not run: 
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, = 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 

## End(Not run)

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