% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/transmute_weights.R
\name{transmute_weights2}
\alias{transmute_weights2}
\title{Transmute weights for a nested generalized mean}
\usage{
transmute_weights2(
  x,
  weights = list(NULL, NULL),
  order = c(1, -1),
  outer_weights = NULL,
  outer_order = 0,
  to = 1,
  pivot = outer_order
)
}
\arguments{
\item{x}{\verb{[numeric > 0]} A strictly positive numeric vector.}

\item{weights}{\verb{[list]} A list of positive numeric vector of
weights, each
the same length as \code{x}, for both of the inner generalized means. \code{NULL}
elements of \code{weights} equally weight each element of \code{x}. The default
uses equal weights for both inner generalized mean.}

\item{order}{\verb{[numeric(2)]} A finite numeric vector giving the order of each
of the inner
generalized means. The default computes an arithmetic mean and a harmonic
mean.}

\item{outer_weights}{\verb{[numeric(2)]} A strictly positive numeric vector
weights for each of
the inner generalized means as used in the outer generalized mean. The
default weights each inner generalized mean equally.}

\item{outer_order}{\verb{[numeric(1)]} A finite number giving the order of the
outer generalized mean. The default uses a geometric mean.}

\item{to}{A finite number giving the order of the target generalized mean for
the transmuted weights. The default constructs weights for an arithmetic
mean.}

\item{pivot}{A finite number giving the pivot value for the transmuted
weights. The default uses the order of the outer generalized mean,
otherwise \code{to} is common alternative.}
}
\value{
A numeric vector, the same length as \code{x}, that sums to 1.
}
\description{
Transmute weights to turn a nested generalized mean of a given order into a
generalized mean of any order. Useful for calculating additive and
multiplicative decompositions for an index made
of nested generalized means (e.g., Fisher index).
See \code{vignette("decomposing-indexes")} for details.
}
\details{
This function generalizes the additive and multiplicative decompositions
for the Fisher index by Balk (2008, Chapter 4). It returns
a value such that

\preformatted{nested_gmean(x, list(w1, w2), c(r1, r2)) ==
    gmean(x, transmute_weights2(x, list(w1, w2), c(r1, r2), to = s), s)}

Transmuting 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
w1 <- 3:1
w2 <- c(1, 2, 1)

# Calculate the geometric mean of the arithmetic and harmonic means
# as an arithmetic mean.
nested_gmean(x, list(w1, w2))
gmean(x, transmute_weights2(x, list(w1, w2), to = 1))
}
\references{
Balk, B. M. (2008). \emph{Price and Quantity Index Numbers}.
Cambridge University Press.
}
\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[=update_weights]{update_weights()}}
}
\concept{math functions}
