% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/chain.R
\name{chain}
\alias{chain}
\alias{chain.default}
\alias{chain.chainable_piar_index}
\alias{unchain}
\alias{unchain.default}
\alias{unchain.direct_piar_index}
\alias{rebase}
\alias{rebase.default}
\alias{rebase.direct_piar_index}
\title{Chain and rebase a price index}
\usage{
chain(x, ...)

\method{chain}{default}(x, ...)

\method{chain}{chainable_piar_index}(x, ..., link = NULL)

unchain(x, ...)

\method{unchain}{default}(x, ...)

\method{unchain}{direct_piar_index}(x, ..., base = NULL)

rebase(x, ...)

\method{rebase}{default}(x, ...)

\method{rebase}{direct_piar_index}(x, ..., base = NULL)
}
\arguments{
\item{x}{A price index, as made by, e.g., \code{\link[=elementary_index]{elementary_index()}}.}

\item{...}{Further arguments passed to or used by methods.}

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

\item{base}{A numeric vector, or something that can coerced into one, of
base-period index values for each level in \code{x}. The default is a equivalent
to a vector
of 1s so that the base period remains the same. If \code{base} is a length-one
character vector giving a time period of \code{x} then the index values for this
time period are used as the base-period values.}
}
\value{
\code{chain()} and \code{rebase()} return a fixed-base index that inherits
from \code{\link{direct_piar_index}}.

\code{unchain()} returns a period-over-period index that inherits from
\code{\link{chainable_piar_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.
}
\details{
The default methods attempt to coerce \code{x} into an index with
\code{\link[=as_index]{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
\code{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 \code{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.
}
\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, base = index[, 2])

}
\seealso{
Other index methods: 
\code{\link{[.piar_index}()},
\code{\link{aggregate.piar_index}},
\code{\link{as.data.frame.piar_index}()},
\code{\link{as.ts.piar_index}()},
\code{\link{contrib}()},
\code{\link{head.piar_index}()},
\code{\link{is.na.piar_index}()},
\code{\link{levels.piar_index}()},
\code{\link{mean.piar_index}},
\code{\link{merge.piar_index}()},
\code{\link{split.piar_index}()},
\code{\link{stack.piar_index}()},
\code{\link{time.piar_index}()},
\code{\link{window.piar_index}()}
}
\concept{index methods}
