Statistics
Sample variance
stats.sample-varianceAlso called sample variance, variance, var, unbiased variance
where
Unbiased estimate of a population's variance from a sample: squared deviations from the sample mean, divided by n − 1 (Bessel's correction).
Notation
observations
x ∈ ℝn
number of observations
Size, at least 2
Result: the sample variance
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
≈ 4.57142857143
Given
Result
≈ 1.66666666667
Given
Result
≈ 0.0233333333333
Common mistakes
Divides by n instead of n − 1
This is the population variance (NumPy's default, ddof=0); the result is (n − 1)/n times the sample variance.
Fix: Divide the sum of squared deviations by n − 1, or call np.var(x, ddof=1).
Returns the standard deviation
The result is the square root of the sample variance.
Fix: Drop the final square root.
Sources
NIST/SEMATECH e-Handbook, §1.3.5.6
NIST/SEMATECH e-Handbook of Statistical Methods. https://www.itl.nist.gov/div898/handbook/ Last updated 2022-04-27. doi:10.18434/M32189
Casella and Berger 2002
Casella, George; Berger, Roger L. Statistical Inference. 2nd ed. Duxbury, 2002.