The functions above accept an argument expression
which should define a population measure, i.e. a quantity that can be computed from population projections, observed population data or vital events. Such an expression is a collection of basic components connected via usual arithmetic operators, such as +
, -
, *
, /
, ^
, %%
, %/%
, and combined using parentheses. In addition, standard R functions or predefined functions (see below) can be used within expressions.
A basic component is a character string constituted of four parts, two of which are optional. They must be in the following order:
Measure identification. One of the folowing upper-case characters:
‘P’ - population,
‘D’ - deaths,
‘B’ - births,
‘S’ - survival ratio,
‘F’ - fertility rate,
‘R’ - percent age-specific fertility,
‘M’ - mortality rate,
‘Q’ - probability of dying,
‘G’ - net migration.
All but the ‘P’ and ‘G’ indicators are available only if the pop.predict
function was run with keep.vital.events=TRUE
.
Country part. One of the following:
Sex part (optional): The country part can be followed by either “_F” (for female) or “_M” (for male).
Age part (optional): If used, the basic component is concluded by an age index given as an array. Such array is embraced by either brackets (“[” and “]”) or curly braces (“{” and “}”). The former invokes a summation of counts over given ages, the latter is used when no summation is desired. Note that if this part is missing, counts are automatically summed over all ages. To use all ages without summing, empty curly braces can be used. Age index one corresponds to age 0-4, index two corresponds to age 5-9 etc. Indicators ‘S’, ‘M’ and ‘Q’ allow an index -1 which corresponds to age 0-1 and index 0 which corresponds to age 1-4. Use the pre-defined function age.index01(…)
and age.index05(…)
(see below) to define the right indices.
Not all combinations of the four parts above make sense. For example, ‘F’ and ‘R’ can be only combined with female sex, ‘B’, ‘F’ and ‘R’ can be only combined with a subset of the age groups, namely child-bearing ages (indices 4 to 10). Or, there is no point in summing the rate indicators over sexes, i.e. using without the sex part, or over multiple age groups, i.e. using brackets.
Examples of basic components are “P276”, “D50_F[4:10]”, “PXXX{14:27}”, “SCZE_M{}”, “QIE_M[-1]”.
When the expression is evaluated on a prediction object, each basic component is substituted by an array of four dimensions (using the get.pop
function):
Country dimension: Equals to one if a specific country code is given, or it equals the number of countries in the prediction object if a wildcard is used.
Age dimension: Equals to one if the third component above is missing or the age is defined within square brackets. If the age is defined within curly braces, this dimension corresponds to the length of the age array.
Time dimension: Depending on the time context of the expression, this dimension corresponds to either the number of projection periods or the number of observation periods.
Trajectory dimension: Corresponds to the number of trajectories in the prediction object, or one if the component is evaluated on observed data.
Depending on the context from which the expression is called, the trajectory dimension of the result of the expression can be reduced by computing given quantiles, and if only one country is evaluated, the first dimension is removed. In addition, with an exception of functions pop.byage.plot
, pop.byage.table
, cohorts
, and pop.cohorts.plot
, the expression should be constructed in a way that the age dimension is eliminated. This can be done for example by using brackets to define age, by using the apply
function or one of the pre-defined functions described below. When using within pop.byage.plot
, pop.byage.table
, cohorts
, or pop.cohorts.plot
, the expression MUST include curly braces.