Modified geometric mean for positive and negative values
jamGeomean(x, na.rm = TRUE, ...)
x | numeric vector which may contain positive and negative values. |
---|---|
na.rm | logical indicating whether to ignore |
... | additional parameters are ignored. |
numeric value representing the modified geometric mean of input values.
This function calculates a geometric mean using a formula which tolerates positive and negative values. It also tolerates zeros without resulting in zero. The intent is to provide a mean summary value which closely models the classical geometric mean, while retaining information present in vectors that contain either zeros or negative values.
The classical geometric mean is defined as
the exponentiated mean of log-transformed values. Said another
way, it is the n
th 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.
There are several proposed alternatives to address negative numbers, or zeros. This function makes the following adjustments:
Add 1
to absolute value of the input, so the numeric sign
is not flipped during log transformation: i <- log2(1+ abs(x))
Multiply that vector by the sign(x)
to retain the original
positive and negative directionality: j <- i * sign(x)
Take the mean: k <- mean(j)
Exponentiate the absolute value: m <- 2^(abs(k))
Multiply by the sign:
n <- m * sign(k)
Subtract 1
: o <- n - 1;
The properties of the calculation:
Symmetry around zero, for example jamGeomean(x) = -jamGeomean(-x)
Results are slightly different than classical geometric mean values,
as a result of adding 1
prior to log transformation. The difference
is larger with increasing range(x)
and is most noticeable when one
input value in x
is zero.
Other jam numeric functions:
geomean()
#> [1] 8.66204#> [1] 7.368063#> [1] 0#> [1] 1.779622