var() — Variance

Average squared distance from the mean — dividing by n−1 or n.

var(x, sample = TRUE)

Key idea

n or n − 1: which divisor?

  1. Find the mean, then add up every squared distance from it — that total is the same for both versions.
  2. Whole population (you have every member, e.g. all 30 students in the class): divide by n → the POPULATION variance σ².
  3. A sample (your data is a subset used to estimate a bigger group): divide by n − 1 → the SAMPLE variance s². This is the default in R and on most calculators (numpy needs ddof=1).
  4. Dividing by n − 1 (Bessel’s correction) nudges the estimate up a little, because a sample’s points hug their own mean and would otherwise under-state the true spread.

Definition

each value
the mean
how many values
sample variance (÷ n−1)
population variance (÷ n)

Where you'd use it

Frequently asked questions

Why is the variance so large?
It’s in squared units. Take the square root (SD) for data units.
Does var use n or n − 1?
n − 1 — the sample variance.