Skip to main content
Module

x/simplestatistics/index.js>geometricMean

simple statistics for node & browser javascript
Go to Latest
function geometricMean
import { geometricMean } from "https://deno.land/x/simplestatistics@v7.7.5/index.js";

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.

Examples

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;

Parameters

x

sample of one or more data points