% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mean.piar_index.R
\name{mean.piar_index}
\alias{mean.piar_index}
\alias{mean.chainable_piar_index}
\alias{mean.direct_piar_index}
\title{Aggregate a price index over subperiods}
\usage{
\method{mean}{chainable_piar_index}(
  x,
  ...,
  weights = NULL,
  window = NULL,
  na.rm = FALSE,
  contrib = TRUE,
  r = 1,
  duplicate_contrib = c("sum", "make.unique")
)

\method{mean}{direct_piar_index}(
  x,
  ...,
  weights = NULL,
  window = NULL,
  na.rm = FALSE,
  contrib = TRUE,
  r = 1,
  duplicate_contrib = c("sum", "make.unique")
)
}
\arguments{
\item{x}{A price index, as made by, e.g., \code{\link[=elementary_index]{elementary_index()}}.}

\item{...}{Not currently used.}

\item{weights}{A numeric vector of weights for the index values in \code{x}, or
something that can be coerced into one. The
default is equal weights. It is usually easiest to specify these weights as
a matrix with a row for each index value in \code{x} and a column for each
time period.}

\item{window}{A positive integer giving the size of the window used to
average index values across subperiods. The default averages over all
periods in \code{x}. Non-integers are truncated towards 0.}

\item{na.rm}{Should missing values be removed? By default, missing values
are not removed. Setting \code{na.rm = TRUE} is equivalent to overall mean
imputation.}

\item{contrib}{Aggregate percent-change contributions in \code{x}? By default
contributions are aggregated.}

\item{r}{Order of the generalized mean to aggregate index values. 0 for a
geometric index (the default for making elementary indexes), 1 for an
arithmetic index (the default for aggregating elementary indexes and
averaging indexes over subperiods), or -1 for a harmonic index (usually for
a Paasche index). Other values are possible; see
\code{\link[gpindex:generalized_mean]{gpindex::generalized_mean()}} for details.}

\item{duplicate_contrib}{The method to deal with duplicate product
contributions. Either \code{"make.unique"} to make duplicate product names
unique with \code{\link[=make.unique]{make.unique()}} or \code{"sum"} to add contributions for the same
products across subperiods (the default).}
}
\value{
A price index, averaged over subperiods, that inherits from the same
class as \code{x}.
}
\description{
Aggregate an index over subperiods by taking the (usually arithmetic) mean
of index values over consecutive windows of subperiods.
}
\details{
The \code{mean()} method constructs a set of non-overlapping windows of
length \code{window}, starting in the first period of the index, and takes
the mean of each index value in these windows for each level of the index.
The last window is discarded if it is incomplete (with a warning), so that
index values are
always averaged over \code{window} periods. The names for the first time
period in each window form the new names for the aggregated time periods.

Percent-change contributions are aggregated if \code{contrib = TRUE} following the
same approach as \code{\link[=aggregate.piar_index]{aggregate()}}.

An optional vector of weights can be specified when aggregating index values
over subperiods, which is often useful when aggregating a Paasche index; see
section 4.3 of Balk (2008) for details.
}
\examples{
index <- as_index(matrix(c(1:12, 12:1), 2, byrow = TRUE), chainable = FALSE)

# Turn a monthly index into a quarterly index
mean(index, window = 3)

}
\references{
Balk, B. M. (2008). \emph{Price and Quantity Index Numbers}.
Cambridge University Press.
}
\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{chain}()},
\code{\link{contrib}()},
\code{\link{head.piar_index}()},
\code{\link{is.na.piar_index}()},
\code{\link{levels.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}
