Classical geometric mean

geomean(x, na.rm = TRUE, naValue = NA, offset = 0, ...)

Arguments

x

numeric vector containing only positive values

na.rm

logical indicating whether to ignore NA values. Note that NA values are removed prior to log-transformation, to avoid negative numbers being dropped completely. To drop negative numbers, do so prior to calling geomean().

offset

numeric value added to input x prior to log transformation, intended only when values between 0 and 1 should be retained. Note that the offset makes the result slightly different than classical geometric mean.

...

additional parameters are ignored.

Value

numeric value representing the geometric mean of input values

Details

This function calculates the classical geometric mean.

The classical geometric mean is defined as the exponentiated mean of log-transformed values. Said another way, it is the nth root of the product of n numeric values. This formula is analogous to geometric distance. The formula does not allow negative values, however, and if any value is zero the result is also zero.

See also

Other jam numeric functions: jamGeomean()

Examples

x <- c(2, 4); geomean(x);
#> [1] 2.828427
x <- c(-2, 2, 4); geomean(x);
#> Warning: NaNs produced
#> [1] NaN
x <- c(0, 4000, 200000); geomean(x);
#> [1] 0