All formulas

Statistics

Population variance

stats.population-varianceAlso called population variance, pvariance, pvar, var_pop

σ2=1n∑i=1n(xi−μ)2\sigma^2 = \frac{1}{n}\sum_{i=1}^{n} (x_i - \mu)^2

whereμ=1n∑j=1nxj\mu = \frac{1}{n}\sum_{j=1}^{n} x_j

Mean squared deviation from the mean, dividing by n. This is the variance of the observations themselves; NumPy's var uses it by default (ddof=0).

Notation

xx

observations

x ∈ ℝn

nn

number of observations

Size, at least 2

σ2\sigma^2

Result: the variance

scalar

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    x=[2,4,4,4,5,5,7,9]x = [2, 4, 4, 4, 5, 5, 7, 9]

    Result

    σ2=4\displaystyle \sigma^2 = 4
  2. Given

    x=[1,2,3,4]x = [1, 2, 3, 4]

    Result

    σ2=54\displaystyle \sigma^2 = \frac{5}{4}

    ≈ 1.25

  3. Given

    x=[0.1,0.2,0.4]x = [0.1, 0.2, 0.4]

    Result

    σ2=7450\displaystyle \sigma^2 = \frac{7}{450}

    ≈ 0.0155555555556

Common mistakes

  • Divides by n − 1

    This is the sample variance, which divides by n − 1; the result is n/(n − 1) times too large.

    Fix: Divide the sum of squared deviations by n.

Source

  • 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

    doi.org