Skip to content

Calculate mean, standard deviation, and variance in one loop

Notifications You must be signed in to change notification settings

wrgoto/optimal-std-dev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}

The Calculation

screen shot 2017-02-14 at 10 40 37 am

About

Calculate mean, standard deviation, and variance in one loop

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published