Skip to content

geometricMean

geometricMean(x): number

Defined in: src/geometric_mean.js:35

The Geometric Mean is a mean function that is more useful for numbers in different ranges.

This is the nth root of the input numbers multiplied by each other.

The geometric mean is often useful for proportional growth: given growth rates for multiple years, like 80%, 16.66% and 42.85%, a simple mean will incorrectly estimate an average growth rate, whereas a geometric mean will correctly estimate a growth rate that, over those years, will yield the same end value.

This runs in O(n), linear time, with respect to the length of the array.

number[]

sample of one or more data points

number

geometric mean

if x is empty

if x contains a negative number

var growthRates = [1.80, 1.166666, 1.428571];
var averageGrowth = ss.geometricMean(growthRates);
var averageGrowthRates = [averageGrowth, averageGrowth, averageGrowth];
var startingValue = 10;
var startingValueMean = 10;
growthRates.forEach(function(rate) {
startingValue *= rate;
});
averageGrowthRates.forEach(function(rate) {
startingValueMean *= rate;
});
startingValueMean === startingValue;