extrapolate {dembase} | R Documentation

## Add extrapolated values to demographic array.

### Description

Given assumptions about the type and amount of change, extend a demographic array along a specified dimension.

### Usage

    extrapolate(
      object,
      along = NULL,
      labels,
      growth = 0,
      type = c("exponential", "linear", "missing")
    )

    ## S4 method for signature 'DemographicArray'
    extrapolate(
      object,
      along = NULL,
      labels,
      growth = 0,
      type = c("exponential", "linear", "missing")
    )

### Arguments

`object` | An object of class `DemographicArray`.
`along` | Name or index of dimension along which values are extrapolated. If `along` is omitted, `extrapolate` looks for a dimension with `dimtype` `"time"`, `"age"`, or `"cohort"` (in that order).
`labels` | Labels for the new elements to be added to dimension `along`.
`growth` | A single number, or a `DemographicArray` object specifying growth rates or increments.
`type` | The type of growth assumed: `"exponential"`, `"linear"`, or `"missing"`. Can be abbreviated. Defaults to `"exponential"`. See below for details.

### Details

The `along` dimension must have `dimscale` `"Intervals"` or `"Points"`, which means that it must have `dimtype` `"age"`, `"cohort"`, or `"time"`. The intervals or points do not need to be evenly spaced.

Values may be extrapolated forward, from the end of the `along` dimension, or backward, from the start. See below for examples.

If `growth` is a demographic array, it will typically have been created by a call to `growth`. Use of a demographic array object allows growth rates or increments to differ within classifying variables: see `growth` for details.

If `type` is `"exponential"`, then extrapolated values are generated using the formula y[n] = y[1] (1 + g)^(t[n] - t[1]), and if `type` is `"linear"`, values are generated using y[n] = y[1] + (t[n] - t[1]) g, where g is `growth`. If `type` is `"missing"` the extra cells are filled with `NA`s.

### Value

An object of the same class as `object`.

### See Also

`growth`

### Examples

    ## prepare data
    library(datasets)
    spend <- USPersonalExpenditure
    names(dimnames(spend)) <- c("category", "year")
    spend <- Values(spend)

    ## extrapolate assuming expenditure in all
    ## categories grows at 1% per annum
    ## (note that 'type' defaults to "exponential")
    extrapolate(spend, labels = c(1965, 1970), growth = 0.01)

    ## linear increase of $1 per annum
    extrapolate(spend, labels = c(1965, 1970), growth = 1, type = "linear")
    extrapolate(spend, labels = c(1965, 1970), growth = 1, type = "l")

    ## grows at historial growth rate - same rate for all categories
    gr <- growth(spend)
    extrapolate(spend, labels = c(1965, 1970), growth = gr)

    ## grows at historical growth rates - rate specific to each category
    gr <- growth(spend, within = "category")
    extrapolate(spend, labels = c(1965, 1970), growth = gr)

    ## irregularly-spaced times
    extrapolate(spend, labels = c(1972.25, 2001), growth = 0.01)

    ## backward extrapolation
    extrapolate(spend, labels = c(1930, 1935), growth = 0.01)

    ## fill extra years with NAs
    extrapolate(spend, labels = c(1965, 1970), type = "missing")

    ## example of extrapolation over age intervals
    library(demdata)
    deaths <- Values(VADeaths2)
    gr <- growth(deaths, along = "age", within = c("sex", "residence"))
    extrapolate(deaths, along = "age", labels = c("75-79", "80+"), growth = gr)

[Package dembase version 0.0.0.119 Index]