% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/geks_index.R
\name{geks_index}
\alias{geks_index}
\title{GEKS index}
\usage{
geks_index(
  price,
  quantity,
  period,
  product,
  index_formula = function(p1, p0, q1, q0) {
     nested_gmean(p1/p0, list(p0 * q0, p1 *
    q1), na.rm = TRUE)
 },
  window = nlevels(period),
  n = window - 1L,
  order = 0,
  match_method = c("all", "back-price")
)
}
\arguments{
\item{price}{\verb{[numeric > 0]} A numeric vector of prices, the same length
as \code{quantity}.}

\item{quantity}{\verb{[numeric >= 0]} A numeric vector of quantities, the same
length as \code{price}.}

\item{period}{\verb{[factor]} A factor, or something that can be coerced into one,
that gives the corresponding time period for each element in \code{price} and
\code{quantity}. The ordering of time periods follows the levels of \code{period}
to agree with \code{\link[=cut.Date]{cut()}}.}

\item{product}{\verb{[factor]} A factor, or something that can be coerced into
one, that
gives the corresponding product identifier for each element in \code{price} and
\code{quantity}.}

\item{index_formula}{\verb{[function]} A function giving the index-number formula
in the GEKS
index. Usually a Törnqvist, Fisher (the default), or Walsh index.
It must have arguments \code{p1}, \code{p0}, \code{q1}, and \code{q0}, and satisfy the
time-reversal test. See \code{vignette("index-number-formulas")} for details.}

\item{window}{\verb{[integer(1) > 0]} A positive integer giving the length of the
rolling window.
The default is a window that encompasses all periods in \code{period}.
Non-integers are truncated towards zero.}

\item{n}{\verb{[integer(1) > 0]} A positive integer giving the length of the index
series for each
window, starting from the end of the window. For example, if there are 13
periods in \code{window}, setting \code{n = 1} gives the index for period 13. The
default gives an index for each period in \code{window}. Non-integers are
truncated towards zero.}

\item{order}{\verb{[numeric(1)]} A finite number giving the order of the
generalized mean used to
average price indexes over the rolling window. The default uses a
geometric mean.}

\item{match_method}{\verb{[character(1)]} Either \code{"all"} to match all products
against each other
(the default) or \code{"back-price"} to match only back prices. The later can be
faster when there is lots of product imbalanced.}
}
\value{
A list with a named numeric vector giving the value of the respective
period-over-period GEKS index for each window.
}
\description{
Calculate a generalized inter-temporal GEKS price index over a rolling
window.
}
\note{
Like \code{\link[=back_period]{back_period()}}, if multiple prices
correspond to a period-product pair, then the back price at a point in time
is always the first price for that product in the previous period. Unlike a
bilateral index, however, duplicated period-product pairs can have more
subtle implications for a multilateral index.
}
\examples{
price <- 1:10
quantity <- 10:1
period <- rep(1:5, 2)
product <- rep(letters[1:2], each = 5)

cumprod(geks_index(price, quantity, period, product)[[1]])

# Calculate the index over a rolling window.
(geks <- geks_index(price, quantity, period, product, window = 3))

# Use a movement splice to combine the indexes in each window.
splice_index(geks, 2)

# ... or use a mean splice.
splice_index(geks)

# Make a Jevons GEKS index.
geks_index(
  price,
  quantity,
  period,
  product,
  index_formula = \(p1, p0, ...) gmean(p1 / p0, na.rm = TRUE, order = 0)
)
}
\references{
Balk, B. M. (2008). \emph{Price and Quantity Index Numbers}.
Cambridge University Press.

IMF, ILO, Eurostat, UNECE, OECD, and World Bank. (2020).
\emph{Consumer Price Index Manual: Concepts and Methods}.
International Monetary Fund.

Ivancic, L., Diewert, W. E., and Fox, K. J. (2011). Scanner data, time
aggregation and the construction of price indexes.
\emph{Journal of Econometrics}, 161(1): 24--35.
}
\seealso{
\code{\link[=splice_index]{splice_index()}} to splice the rolling-window indexes together.

\code{GEKSIndex()} in the \pkg{IndexNumR} package for an implementation of the
GEKS index with more options.

The \pkg{rsmatrix} package for multilateral repeat-sales indexes.
}
