Skip to main content
Module

x/simplestatistics/src/standard_deviation.js

simple statistics for node & browser javascript
Go to Latest
File
import variance from "./variance.js";
/** * The [standard deviation](http://en.wikipedia.org/wiki/Standard_deviation) * is the square root of the variance. This is also known as the population * standard deviation. It's useful for measuring the amount * of variation or dispersion in a set of values. * * Standard deviation is only appropriate for full-population knowledge: for * samples of a population, {@link sampleStandardDeviation} is * more appropriate. * * @param {Array<number>} x input * @returns {number} standard deviation * @example * variance([2, 4, 4, 4, 5, 5, 7, 9]); // => 4 * standardDeviation([2, 4, 4, 4, 5, 5, 7, 9]); // => 2 */function standardDeviation(x) { if (x.length === 1) { return 0; } const v = variance(x); return Math.sqrt(v);}
export default standardDeviation;