pop.write.projection.summary: Writing Projection Summary and Trajectory Files

write.pop.projection.summaryR Documentation

Writing Projection Summary and Trajectory Files

Description

Functions for creating ASCII files containing projection summaries, such as the median, the lower and upper bound of the 80 and 95% probability intervals, respectively, as well as containing individual trajectories.

Usage

write.pop.projection.summary(pop.pred, what = NULL, expression = NULL, 
    output.dir = NULL, ...)
    
write.pop.trajectories(pop.pred, expression = "PXXX", 
    output.file = "pop_trajectories.csv", byage = FALSE, 
    observed = FALSE,  wide = FALSE, digits = NULL,
    include.name = FALSE, sep = ",", na.rm = TRUE, ...)

Arguments

pop.pred

Object of class bayesPop.prediction.

what

A character vector specifying what kind of projection to write. Total population is specified by “pop”. Vital events are specified by “births”, “deaths”, “sr” (survival rate), “fertility” and “pfertility” (percent fertility). Each of these strings can (some must) have a suffix “sex” and/or “age” if sex- and/or age-specific measure is desired. For example, “popage”, “birthssexage”, “deaths”, “deathssex”, are all valid values. Note that for survival, only “srsexage” is allowed. For percent fertility, only “pfertilityage” is allowed. Suffix “sex” cannot be used in combination with “fertility”. Moreover, “fertility” (without age) corresponds to the total fertility rate. If the argument is NULL, all valid combinations are used. The argument is not used if expression is given. Note that vital events can be only used if the prediction object contains vital events, i.e. if it was generated with the keep.vital.events argument being TRUE (see pop.predict).

expression

Expression defining the measure to be written. If it is not NULL, argument what is ignored. For expression syntax see pop.expressions. The country components of the expression should be given as “XXX”.

output.dir

Directory in which the resulting files will be stored. If NULL pop.pred$output.directory is used.

output.file

File name to write the trajectories into.

byage

Logical indicating if the expression is defined by age, i.e. if it includes curly braces (TRUE), of if it is defined by time (FALSE), see pop.expressions for more detail on the expression syntax.

observed

Logical indicating if observed data should be written (TRUE) or projected trajectories (FALSE).

wide

Logical indicating if the data format should be wide. By default, trajectories are written in long format.

digits

To how many decimal digits should the indicator be rounded. By default no rounding takes place.

include.name

Logical indicating if country names should be included in the dataset.

sep

The field separator string.

na.rm

Logical indicating if records with NA values should be included in the dataset.

...

For write.pop.projection.summary, these are:

  • if expression is given, then one can use here file.suffix (defines the file suffix) and/or expression.label which defaults to the actual expression and is put as the first line in the resulting file;

  • logical include.observed determines if observed data should be included;

  • integer digits defines the number of decimal places in the resulting file;

  • for 5-year projections, logical end.time.only determines if the time columns should be in form of time periods (as XXXX-YYYY) or just the end years (YYYY);

  • logical adjust determines if the numbers should be adjusted; in such a case, adj.to.file and allow.negative.adj give the file name to which to adjust and a switch if negatives are allowed for the adjustments, respectively.

For write.pop.trajectories, these are arguments passed to get.pop.ex (if byage is FALSE) or get.pop.exba (if byage is TRUE).

Details

The write.pop.projection.summary function creates one file per value of what, or expression, called ‘projection_summary_suffix.csv’, where suffix is either what or, if an expression is given, the value of file.suffix. It is a comma-separated table with the following columns:

  • “country_name”: country name

  • “country_code”: country code

  • “variant”: name of the variant, such as “median”, “lower 80”, “upper 80”, “lower 95”, “upper 95”

  • period1: e.g. “2005-2010”, or “2010”: Given population measure for the first time period

  • period2: e.g. “2010-2015”, or “2015”: Given population measure for the second time period

  • ... further time period columns

If expression is given, expression.label (by default the full expression) is written as the first line of the file starting with #. The file contains one line per country, and possibly sex and age.

Function write.pop.trajectories writes out all trajectories, either in long format (default) or, if wide = TRUE in wide format (years become columns).

Note

If the expression argument is used, the same applies as for pop.map in terms of Performance and Caching.

Author(s)

Hana Sevcikova

See Also

pop.predict, pop.map, pop.expressions

Examples

outdir <- tempfile()
dir.create(outdir)
sim.dir <- file.path(find.package("bayesPop"), "ex-data", "Pop")
pred <- get.pop.prediction(sim.dir=sim.dir, write.to.cache=FALSE)

# proportion of 65+ years old to the whole population
write.pop.projection.summary(pred, expression="PXXX[14:27] / PXXX", file.suffix="age65plus", 
    output.dir=outdir, include.observed=TRUE, digits=2)
    
# various measures
write.pop.projection.summary(pred, what=c("pop", "popsexage", "popsex"),
    output.dir=outdir)

unlink(outdir, recursive=TRUE)

bayesPop documentation built on Aug. 10, 2023, 1:10 a.m.