| geometric_mean | R Documentation |
The Geometric mean is the nth-root of the product of n input values.
Common uses include:
Compound Annual Growth Rate (CAGR) & Financial Returns: Averaging investment yields over multiple periods. The arithmetic mean overstates performance when volatility is present (e.g., a +50% gain followed by a -50% loss leaves you with a 25% loss, even though the arithmetic average is 0%; the geometric mean correctly yields -29.29% per period, totaling -25%).
Utilitarian evaluation of value. For example, the geometric mean utility of c(1, 2, 10) is
(1 * 2 * 10)^\frac{1}{3}
= 2.7 not the arithmetic mean: 4.3.
Proportional Scaling: Proportional growth of organisms and log-normally distributed physical phenomena.
Normalizing metrics measured on different scales: e.g., computer hardware so no single benchmark disproportionately skews the score.
geometric_mean(x, na.rm = c(TRUE, FALSE))
x |
A vector of values. |
na.rm |
Remove NAs (default = TRUE). If FALSE, NA input returns NA (like |
The geometric mean is defined as the n-th root of the product of n numbers:
G = \left( \prod_{i=1}^{n} x_i \right)^{\frac{1}{n}} = \sqrt[n]{x_1 x_2 \cdots x_n}
In practice, to prevent numerical overflow or underflow with large vectors, it is calculated via the logarithmic transform:
\ln G = \frac{1}{n} \sum_{i=1}^{n} \ln(x_i) \implies G = \exp\left( \frac{1}{n} \sum_{i=1}^{n} \ln(x_i) \right)
Geometric mean of x
https://en.wikipedia.org/wiki/Geometric_mean
harmonic_mean(), mean()
Other Miscellaneous Stats Functions:
FishersMethod(),
SE_from_p(),
harmonic_mean(),
oddsratio(),
reliability(),
umx,
umxCov2cor(),
umxHetCor(),
umxParan(),
umxWeightedAIC(),
umx_apply(),
umx_cor(),
umx_means(),
umx_r_test(),
umx_round(),
umx_scale(),
umx_var()
geometric_mean(c(1.02, 1.03, 1.1))
# = 1.049
# For a given sum, geometric mean is maximised when all values are equal:
geometric_mean(c(75,75))
geometric_mean(c(50, 100))
v = c(1, 149, 500); round(c(geometric_mean(v), mean(v), median(v)), 0)
# 42 217 149
# Alternate form using mean of the logs
exp(mean(log(c(50, 100))))
# Underlying logic
sqrt(50 * 100)
# Reciprocal duality
1/geometric_mean(c(100, 50))
geometric_mean(c(1/100, 1/50))
# Missing data are dropped by default (na.rm = TRUE)
geometric_mean(c(50, 100, NA)) # 70.7
# With na.rm = FALSE, NA input gives NA, like mean()
geometric_mean(c(50, 100, NA), na.rm = FALSE) # NA
## Not run:
# Non-positive input is an error, even alongside NAs
geometric_mean(c(50, -100))
geometric_mean(c(50, -100, NA))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.