Last updated
What Is Standard Deviation?
Standard deviation measures how spread out values are from the mean (average). A low standard deviation means values cluster close to the mean; a high standard deviation means values are spread over a wider range. It's one of the most important statistics in data analysis, quality control, and scientific research.
Population vs Sample Standard Deviation
There are two formulas depending on whether your data is the entire population or a sample:
Population σ = √[ Σ(xᵢ - μ)² / N ]
Sample s = √[ Σ(xᵢ - x̄)² / (N-1) ]
Where:
xᵢ = each value
μ = population mean
x̄ = sample mean
N = count of values
N-1 = Bessel's correction (reduces bias in sample estimates)
Step-by-Step Example
| Step | Calculation | Result |
|---|---|---|
| Data | [4, 7, 13, 2] | — |
| Mean | (4+7+13+2) / 4 | 6.5 |
| Deviations² | (4-6.5)², (7-6.5)², (13-6.5)², (2-6.5)² | 6.25, 0.25, 42.25, 20.25 |
| Variance (pop) | 69 / 4 | 17.25 |
| Std Dev (pop) | √17.25 | 4.153 |
| Variance (sample) | 69 / 3 | 23.0 |
| Std Dev (sample) | √23.0 | 4.796 |
JavaScript Implementation
function stdDev(values, population = false) {
const n = values.length;
const mean = values.reduce((a, b) => a + b, 0) / n;
const variance = values.reduce((sum, x) => sum + Math.pow(x - mean, 2), 0)
/ (population ? n : n - 1);
return {
mean: mean.toFixed(4),
variance: variance.toFixed(4),
stdDev: Math.sqrt(variance).toFixed(4)
};
}
console.log(stdDev([4, 7, 13, 2]));
// { mean: '6.5000', variance: '23.0000', stdDev: '4.7958' }