e0.trajectories.plot: Posterior Distribution of Trajectories of Life Expectancy

View source: R/plot_functions.R

e0.trajectories.plotR Documentation

Posterior Distribution of Trajectories of Life Expectancy


The functions plot/tabulate the posterior distribution of trajectories of the life expectancy for a given country, or for all countries, including their median and given probability intervals.


e0.trajectories.plot(e0.pred, country, pi = c(80, 95), both.sexes = FALSE,
    nr.traj = NULL, adjusted.only = TRUE, typical.trajectory = 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'),
    col2 = c('gray39', 'greenyellow', 'hotpink', 'hotpink', '#00000020'),
    pch = c(1, 2), show.legend = TRUE, add = FALSE, ...)
    output.dir = file.path(getwd(), 'e0trajectories'),
    output.type = "png", verbose = FALSE, ...)
e0.trajectories.table(e0.pred, country, pi = c(80, 95), 
    both.sexes = FALSE, ...)



Object of class bayesLife.prediction.


Name or numerical code of a country. It can also be given as ISO-2 or ISO-3 characters.


Probability interval. It can be a single number or an array. If both.sexes is TRUE the default is 95.


Logical or the character “A”. If TRUE the distribution of both sexes is plotted into one graphics (or tabulated), provided the e0.pred is a female prediction and contains a joint male prediction as a result of running the function e0.jmale.predict. For “A” it plots/tabulates the distribution of the average life expectancy over both sexes.


Number of trajectories to be plotted. If NULL, all trajectories are plotted, otherwise they are thinned evenly. If both.sexes is TRUE the default is zero.


Logical. By default, if the projection median is adjusted using e.g. e0.median.set, the function plots the adjusted median. If adjusted.only=FALSE the original (non-adjusted) median is plotted as well.


Logical. If TRUE one trajectory is shown for which the median absolute deviation from the median e0 projection is the median among all the trajectories.

xlim, ylim, type, xlab, ylab, main

Graphical parameters passed to the plot function.

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. col2 is only used if both.sexes is TRUE. In such a case, col2 is used for female lines and col is used for male lines, which in this case defaults to c('black', 'green', 'darkgreen', 'darkgreen', 'gray').


Vector of two elements specifying plotting symbols for the observed and imputed data, respectively. It is not used if type is not one of “b”, “p” or “o”.


Logical controlling whether the legend should be drawn.


Logical controlling whether the trajectories should be plotted into a new graphic device (FALSE) or into an existing device (TRUE). One can use this argument to plot trajectories from multiple countries into one graphics.


Additional graphical parameters. In addition, for e0.trajectories.plot.all, ... contains any of the arguments of e0.trajectories.plot, and for e0.trajectories.table, ... contains the pi and country arguments.


Directory into which resulting graphs are stored.


Type of the resulting files. It can be “png”, “pdf”, “jpeg”, “bmp”, “tiff”, or “postscript”.


Logical switching log messages on and off.


e0.trajectories.plot plots posterior distribution of trajectories of life expectancy for a given country. e0.trajectories.table gives the same output in a tabular format.
e0.trajectories.plot.all creates a set of such graphs (one per country) that are stored in output.dir.

The median and given probability intervals are computed using all available trajectories. Thus, nr.traj does not influence those values - it is used only to control the number of trajectories plotted.


Hana Sevcikova

See Also



sim.dir <- file.path(find.package("bayesLife"), "ex-data", "bayesLife.output")
pred <- get.e0.prediction(sim.dir)
e0.trajectories.table(pred, country = "Japan", pi = c(80, 95))
e0.trajectories.plot(pred, country = "Japan", pi = c(80, 95))

# plot multiple countries into one plot
e0.trajectories.plot(pred, "JP", col = rep("green", 5), nr.traj = 0,
         pi = c(80), show.legend = FALSE, main = "")
e0.trajectories.plot(pred, "USA", col = rep("blue", 5),  
        add = TRUE, nr.traj = 0, pi = c(80), show.legend = FALSE)
legend("topleft", legend = c("Japan", "USA"), col = c("green", "blue"), 
        lty = 1, bty = "n")

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