write.pop.projection.summary | R Documentation |
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.
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, ...)
pop.pred |
Object of class |
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 |
expression |
Expression defining the measure to be written. If it is not |
output.dir |
Directory in which the resulting files will be stored. If |
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 ( |
observed |
Logical indicating if observed data should be written ( |
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 |
... |
For
For |
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).
If the expression
argument is used, the same applies as for pop.map
in terms of Performance and Caching.
Hana Sevcikova
pop.predict
, pop.map
, pop.expressions
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.