% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/update_weights.R
\name{update_weights}
\alias{update_weights}
\title{Update weights}
\usage{
update_weights(x, weights = NULL, order = 1)
}
\arguments{
\item{x}{\verb{[numeric > 0]} A strictly positive numeric vector.}

\item{weights}{\verb{[numeric >= 0]} A positive numeric vector of weights, the
same length as \code{x}. The default is to equally weight each element of \code{x}.}

\item{order}{\verb{[numeric(1)]} A finite number giving the order (or exponent) of
the generalized mean. The default calculates an arithmetic mean.}
}
\value{
A numeric vector the same length as \code{x}.
}
\description{
Factor weights to turn the generalized mean of a product into the product
of generalized means. Useful for price-updating the weights in a
generalized-mean index.
}
\details{
This function generalizes the result in section C.5 of Chapter 9 of the PPI
Manual for chaining the Young index, and gives a way to chain
generalized-mean price indexes over time. It returns a value such that

\preformatted{gmean(x * y, w) ==
    gmean(x, w) * gmean(y, update_weights(x, w))}

Factoring weights returns a value that is the same length as \code{x},
so any missing values in \code{x} or \code{weights} will return \code{NA}.
Unless all values are \code{NA}, however, the result will still satisfy
the above identity when \code{na.rm = TRUE}.
}
\examples{
x <- 1:3
y <- 4:6
w <- 3:1

# Factor the arithmetic mean by chaining the calculation.
gmean(x * y, w)
gmean(x, w) * gmean(y, update_weights(x, w))

# In cases where x and y have the same order, Chebyshev's
# inequality implies that the chained calculation is too small.
gmean(x * y, w) > gmean(x, w) * gmean(y, w)
}
\references{
ILO, IMF, OECD, UNECE, and World Bank. (2004).
\emph{Producer Price Index Manual: Theory and Practice}.
International Monetary Fund.
}
\seealso{
Other math functions:
\code{\link[=emean]{emean()}},
\code{\link[=gmean]{gmean()}},
\code{\link[=nested_gmean]{nested_gmean()}},
\code{\link[=scale_weights]{scale_weights()}},
\code{\link[=transmute_weights]{transmute_weights()}},
\code{\link[=transmute_weights2]{transmute_weights2()}}
}
\concept{math functions}
