Skip to main content
Module

x/statistics/src/standard_deviation.ts

Deno basic statistics module.
Latest
File
import { variance } from "./variance.ts";
/** * 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 {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 */export function standardDeviation(x: number[]): number { if (x.length === 1) { return 0; }
const v = variance(x); return Math.sqrt(v);}