Statistics · Siblings

The spread of data is measured by the average squared distance of the data from their mean. The variance of the data divides the sum of the squared distances by the number $n$ of data points, which describes the data themselves. The sample variance divides by $n - 1$ instead, which gives an unbiased estimate of the variance of the population that the data were sampled from.

Definitions

variance

High school

Consider data $x_1, \dots, x_n$ with mean $\bar{x}$. The variance of the data is the mean of the squared distances from the mean:

\[\operatorname{Var} = \frac{1}{n} \sum_{i = 1}^{n} (x_i - \bar{x})^2.\]
Undergraduate

Consider a random variable $X$ with expected value $\mu = \mathbb{E}[X]$. The variance of $X$ is

\[\operatorname{Var}(X) = \mathbb{E}[(X - \mu)^2].\]
Worked examples
  • Value:

    $\frac{74}{9} \approx 8.22$

    $\frac{(2 - \frac{16}{3})^2 + (5 - \frac{16}{3})^2 + (9 - \frac{16}{3})^2}{3} = \frac{74}{9}$
  • Value:

    $\operatorname{Var}(X) = \mathbb{E}[X^2] - 3.5^2 = \frac{91}{6} - \frac{49}{4} = \frac{35}{12} \approx 2.92$

  • Value:

    $\sigma^2 = 1/150 \approx 0.0067$ m$^2$

    The variance of the heights $1.6$, $1.7$, and $1.8$ m is the average of the squared differences from the mean $1.7$ m: \[\sigma^2 = \frac{(-0.1)^2 + 0^2 + 0.1^2}{3} = \frac{0.02}{3} = \frac{1}{150} \approx 0.0067 \ \mathrm{m}^2.\] The variance is in square meters, because the differences are squared.
  • Value:

    $\frac{(1.5)^2 + (0.5)^2 + (0.5)^2 + (1.5)^2}{4} = \frac{5}{4} = 1.25$

    The variance of the data $1, 2, 3, 4$ divides the sum $5$ of the squared distances from the mean $2.5$ by the number of data points, $4$.
  • Value:

    $0$

    The variance of the single data point $5$ is $0$, because the data point equals its mean.
Properties
  • The variance is in squared units: if $X$ is in meters, $\operatorname{Var}(X)$ is in square meters.
  • The high-school formula, which divides by $n$, gives the variance of the data themselves, such as the variance of a whole population. If the data are a random sample from a larger population, then the sample variance, which divides by $n - 1$ instead of $n$, gives a better estimate of the population variance.

sample variance

High school

Consider data $x_1, \dots, x_n$ that are a random sample from a larger population, with sample mean $\bar{x}$. The sample variance of the data is the sum of the squared distances from the mean divided by $n - 1$:

\[s^2 = \frac{1}{n - 1} \sum_{i = 1}^{n} (x_i - \bar{x})^2.\]

The sample variance estimates the variance of the whole population.

Undergraduate (statistics)

Consider independent random variables $X_1, \dots, X_n$ that have the same distribution, with sample mean $\bar{X} = \frac{1}{n} \sum_{i = 1}^{n} X_i$, such that $n \geq 2$. The sample variance is the random variable

\[S^2 = \frac{1}{n - 1} \sum_{i = 1}^{n} (X_i - \bar{X})^2.\]
Worked examples
  • Value:

    $\frac{(1.5)^2 + (0.5)^2 + (0.5)^2 + (1.5)^2}{3} = \frac{5}{3} \approx 1.67$

    The sample variance of the data $1, 2, 3, 4$ divides the sum $5$ of the squared distances from the mean $2.5$ by $4 - 1 = 3$.
  • Value:

    Undefined

    The sample variance of the single data point $5$ is undefined, because the formula divides $0$ by $1 - 1 = 0$; one measurement says nothing about how spread out the population is.
Properties
  • The sample variance is an unbiased estimator of the variance $\sigma^2$ of each $X_i$: $\mathbb{E}[S^2] = \sigma^2$.
  • The data are closer, on average, to their own sample mean $\bar{x}$ than to the population mean $\mu$, because $\bar{x}$ is the number that minimizes the sum of squared distances to the data. Dividing by $n$ would therefore underestimate the variance on average, and dividing by $n - 1$ instead (Bessel’s correction) exactly compensates.
  • The sample variance of a single data point is undefined, because one data point carries no information about the spread of the population.

Examples

Example variance sample variance Why
The data $1, 2, 3, 4$ $\frac{(1.5)^2 + (0.5)^2 + (0.5)^2 + (1.5)^2}{4} = \frac{5}{4} = 1.25$$\frac{(1.5)^2 + (0.5)^2 + (0.5)^2 + (1.5)^2}{3} = \frac{5}{3} \approx 1.67$ For the data $1, 2, 3, 4$, the sample variance exceeds the variance by the factor $\frac{4}{3}$, because the sample variance divides by $3$ instead of $4$.
The single data point $5$ $0$Undefined For the single data point $5$, the variance is $0$, but the sample variance is undefined, because one data point gives no estimate of the spread of a population.

Why the denominators differ

The denominator depends on the question being asked.

  • Describing the data themselves. If the data are the whole population, such as the test scores of every student in a class, then the variance is the average squared distance from the mean, so the sum is divided by the number $n$ of data points.
  • Estimating the spread of a larger population. If the data are a random sample, then the goal is to estimate the population variance

    \[\sigma^2 = \mathbb{E}[(X - \mu)^2],\]

    which measures distances from the population mean $\mu$. The population mean $\mu$ is unknown, so the formula uses the sample mean $\bar{x}$ in place of $\mu$. The sample mean is computed from the same data, so the sample mean is pulled toward the data: $\bar{x}$ is the number $c$ that minimizes $\sum_{i} (x_i - c)^2$. Therefore, the squared distances from $\bar{x}$ are smaller, on average, than the squared distances from $\mu$, and dividing their sum by $n$ underestimates $\sigma^2$.

How much smaller the squared distances are follows from the identity

\[\sum_{i = 1}^{n} (x_i - \mu)^2 = \sum_{i = 1}^{n} (x_i - \bar{x})^2 + n (\bar{x} - \mu)^2.\]

For independent samples, the expected value of the left side is $n \sigma^2$, and the expected value of $n (\bar{x} - \mu)^2$ is $n \cdot \frac{\sigma^2}{n} = \sigma^2$, so

\[\mathbb{E}\left[\sum_{i = 1}^{n} (x_i - \bar{x})^2\right] = (n - 1) \sigma^2.\]

Dividing by $n - 1$ instead of $n$ (Bessel’s correction) therefore gives an estimate whose expected value is exactly $\sigma^2$.

Another way to see the $n - 1$ is to count degrees of freedom: the deviations $x_i - \bar{x}$ add up to $0$, so only $n - 1$ of the deviations can vary freely, and the last deviation is determined by the others. If the population mean $\mu$ is known, then no degree of freedom is used up, and $\frac{1}{n} \sum_{i} (x_i - \mu)^2$ is already an unbiased estimate of $\sigma^2$.

Notes

  • The difference between dividing by $n$ and dividing by $n - 1$ is small for large $n$.
  • Calculators and software disagree about the default: NumPy’s var divides by $n$, and R’s var and Excel’s VAR.S divide by $n - 1$.

See also

All distinctions · All definitions · Notation