Modified geometric mean for positive and negative values
Details
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 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.
There are several proposed alternatives to address negative numbers, or zeros. This function makes the following adjustments:
Add
1to 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
1prior to log transformation. The difference is larger with increasingrange(x)and is most noticeable when one input value inxis zero.
See also
Other Internal utility functions:
combineGRcoverage(),
compressPolygonM(),
df2colorSub(),
dfWide2segments(),
escapeWhitespaceRegexp(),
factor2label(),
geomean(),
intercalate(),
internal_junc_score(),
list2im(),
shrinkMatrix(),
simplifyXY(),
stackJunctions(),
strsplitOrdered()