optimal-std-dev
v1.0.4
Published
Calculate mean, standard deviation, and variance in one loop
Downloads
2
Readme
Optimal Standard Deviation Calculation
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.
Usage
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
}