Calculates the mean, standard deviation, and variance of an array in one loop. This is based on Mark Hoemmen's work, Computing the standard deviation efficiently published August 25, 2007.
Install:
npm install --save optimal-std-dev
Import:
var calcStdDev = require('optimal-std-dev');
Use with a normal array:
var calcValues = calcStdDev([1, 2, 3, 10]);
Use with an accessor provided as a string:
var calcValues = calcStdDev([{ n: 1 }, { n: 2 }], 'n');
Use with an accessor provided as a function:
var calcValues = calcStdDev([{ n: 1 }, { n: 2 }], function (n) { return n + 1; });
Returns an object with the following properties:
{
sum: 16,
mean: 4,
popStdDev: 3.5355339059327378,
popVariance: 12.5,
sampleStdDev: 4.08248290463863,
sampleVariance: 16.666666666666668
}