chain {piar}R Documentation

Chain and rebase a price index

Description

Chain a period-over-period index by taking the cumulative product of its values to turn it into a fixed-base (direct) index.

Unchain a fixed-base index by dividing its values for successive periods to get a period-over-period index.

Rebase a fixed-base index by dividing its values with the value of the index in the new base period.

Usage

chain(x, ...)

## Default S3 method:
chain(x, ...)

## S3 method for class 'chainable_piar_index'
chain(x, link = rep(1, nlevels(x)), ...)

unchain(x, ...)

## Default S3 method:
unchain(x, ...)

## S3 method for class 'direct_piar_index'
unchain(x, ...)

rebase(x, ...)

## Default S3 method:
rebase(x, ...)

## S3 method for class 'direct_piar_index'
rebase(x, base = rep(1, nlevels(x)), ...)

Arguments

x

A price index, as made by, e.g., elemental_index().

...

Further arguments passed to or used by methods.

link

A numeric vector, or something that can coerced into one, of link values for each level in x. The default is a vector of 1s so that no linking is done.

base

A numeric vector, or something that can coerced into one, of base-period index values for each level in x. The default is a vector of 1s so that the base period remains the same.

Details

The default methods attempt to coerce x into an index with as_index() prior to chaining/unchaining/rebasing.

Chaining an index takes the cumulative product of the index values for each level; this is roughly the same as t(apply(as.matrix(x), 1, cumprod)) * link. Unchaining does the opposite, so these are inverse operations. Note that unchaining a period-over-period index does nothing, as does chaining a fixed-base index.

Rebasing a fixed-base index divides the values for each level of this index by the corresponding values for each level in the new base period. It's roughly the same as as.matrix(x) / base. Like unchaining, rebasing a period-over-period index does nothing.

Percent-change contributions are removed when chaining/unchaining/rebasing an index, as it's not usually possible to update them correctly.

Value

chain() and rebase() return a fixed-base index that inherits from direct_piar_index.

unchain() returns a period-over-period index that inherits from chainable_piar_index.

See Also

Other index methods: [.piar_index(), aggregate.piar_index(), as.data.frame.piar_index(), contrib(), head.piar_index(), is.na.piar_index(), levels.piar_index(), mean.piar_index(), merge.piar_index(), split.piar_index(), stack.piar_index(), time.piar_index(), vcov.aggregate_piar_index()

Examples

index <- as_index(matrix(1:9, 3))

# Make period 0 the fixed base period

chain(index)

# Chaining and unchaining reverse each other

all.equal(index, unchain(chain(index)))

# Change the base period to period 2 (note the
# loss of information for period 0)

index <- chain(index)
rebase(index, index[, 2])


[Package piar version 0.7.0 Index]