% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/geomean.R
\name{geomean}
\alias{geomean}
\title{Geometric Mean}
\usage{
geomean(x, w = NULL, na.rm = TRUE)
}
\arguments{
\item{x}{A numeric vector. Zeros produce a result of \code{0}.
Negative values produce \code{NaN} with a warning, since the
geometric mean is undefined for negative numbers.}

\item{w}{Optional numeric vector of weights, the same length as
\code{x}. Must be non-negative. If \code{NULL} (default), the unweighted
geometric mean is returned.}

\item{na.rm}{Logical. Should missing values in \code{x} (and \code{w}, if
provided) be removed before computation? Default \code{TRUE}.}
}
\value{
A numeric scalar. Returns \code{NA_real_} when the input is
empty, when it is entirely \code{NA}, or when \code{na.rm = FALSE} and
any element is \code{NA}. Returns \code{NaN} with a warning when \code{x}
contains negative values, or when all weights are zero.
}
\description{
Computes the geometric mean of a numeric vector, with optional
weights. Useful for aggregating multiplicative quantities such as
ratio-based health indicators (e.g. UHC service-coverage tracers,
where the composite index is the geometric mean of component
coverage values).
}
\details{
Pass \code{w} to compute a weighted geometric mean, defined as
\code{exp(weighted.mean(log(x), w))}.
}
\examples{
# Unweighted
geomean(c(1, 4, 16))                # 4
geomean(c(0.6, 0.8, 0.95))          # ~0.772 — typical UHC tracer aggregation
geomean(c(1, NA, 4))                # 2
geomean(c(1, NA, 4), na.rm = FALSE) # NA_real_
geomean(c(1, 0, 4))                 # 0

# Weighted
geomean(c(1, 4, 16), w = c(1, 1, 1))     # 4 (equal weights = unweighted)
geomean(c(1, 4, 16), w = c(1, 2, 1))     # weighted toward 4
geomean(c(0.6, 0.8, 0.95), w = c(2, 1, 1))
}
