interp: Interpolate between two population age distributions.

Description Usage Arguments Details Value

View source: R/utils.R

Description

The interpolation is done by age using a linear, exponential, or power function. This comes from the PAS spreadsheet called AGEINT. Be aware that this is not cohort-component interpolation.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
interp(
  popmat,
  datesIn,
  datesOut,
  method = c("linear", "exponential", "power"),
  power = 2,
  extrap = FALSE,
  negatives = FALSE,
  ...
)

Arguments

popmat

numeric. An age-period matrix of data to interpolate over. Age in rows, time in columns.

datesIn

vector of dates. The exact dates in each column. See details for ways to express it.

datesOut

vector of dates. The desired dates to interpolate to. See details for ways to express it.

method

string. The method to use for the interpolation, either "linear", "exponential", or "power". Default "linear".

power

numeric power to interpolate by, if method = "power". Default 2.

extrap

logical. In case datesOut is out of range of datesIn, do extrapolation using slope in extreme pairwise. Default FALSE.

negatives

logical. In case negative output are accepted, set to TRUE. Default FALSE.

...

arguments passed to stats::approx. For example, rule, which controls extrapolation behavior.

Details

The age group structure of the output is the same as that of the input. Ideally, datesOut should be within the range of datesIn. If not, the left-side and right-side output are held constant outside the range if rule = 2 is passed in, otherwise NA is returned (see examples). Dates can be given in three ways 1) a Date class object, 2) an unambiguous character string in the format "YYYY-MM-DD", or 3) as a decimal date consisting in the year plus the fraction of the year passed as of the given date.

For methods "exponential" and "power", calculations are carried out using linear interpolation through log(popmat), or popmat^(1/power) respectively, then back-transformed. If the data contain 0s, method = "exponential" will fail, but "power" would still generally work.

Value

numeric matrix (age-period) (or vector if length(datesOut) == 1 of the interpolated data for the requested dates.


hhmacedo/dmtls documentation built on Dec. 20, 2021, 3:49 p.m.