23  Variance and standard deviation

Spread of the data

Almost everyone has calculated an average grade, yet checking the variance of those grades is rarely considered. While calculating the mean is well understood, the formulas for variance and standard deviation are often forgotten.

When conducting statistical tests, analyzing variance becomes necessary—often without a clear understanding of why. Concepts such as homogeneity of variance or homoscedasticity can seem overly complex, largely because variance is routinely ignored in everyday calculations.

Due to the familiarity and utility of the mean, comparing two single numbers is easy, which often leads to the implicit assumption that the underlying distributions are identical. However, a single mean does not fully describe a distribution, as demonstrated below by three distinct distributions sharing the exact same mean.

Conversely, no one would conclude that equal variances imply identical distributions. Comparing distributions effectively is often achieved through a parsimonious approach that examines both the mean and the variance1. The mean indicates the central tendency, whereas the variance measures the dispersion. For well-behaved distributions—particularly those that are unimodal and symmetrical—these two metrics serve as the primary criteria for comparison.

Formal

In descriptive statistics, the equation for variance is:

\[ \text{Var}(X) = \frac{1}{n} \sum_{i=1}^{n} (X_i - \bar{X})^2 \tag{23.1}\]

This formula is similar to the mean, except that \(X_i\) is replaced by \((X_i - \bar{X})^2\), which represents the squared distance of each observation from the mean. Variance is therefore the average squared distance from the mean.

Through algebraic manipulation, the equation can also be expressed as:

\[ \text{Var}(X) = \frac{1}{n} \sum_{i=1}^{n} X_i^2 - \bar{X}^2 \tag{23.2}\]

This alternative formula is often simpler for manual calculations, though both methods require minimal computational effort.

The standard deviation is the square root of the variance:

\[ \sigma = \sqrt{\text{Var}(X)} \tag{23.3}\]

Examples

  • For a trivial dataset \(X = \{1, 1, 1, 1\}\), the mean is \(\mu = 1\).

    The variance is:

    \[ \begin{align*} \sigma^2 & = \frac{1}{4}\left((1 - \mu)^2 + (1 - \mu)^2 + (1 - \mu)^2 + (1 - \mu)^2\right) \\ & = \frac{1}{4} (0) \times 4 = 0 \end{align*} \] This result is intutitive: because all values are identical, there is no dispersion, and the variance (and standard deviation) is zero.

  • Following the previous calculation of the mean (Chapter 21): The mean was:

    \[\mu = \frac{1}{6} 5 + \frac{1}{6} 7 + \frac{2}{6} 10 + \frac{1}{6} 12 + \frac{1}{6} 14 = 9.67\]

    The variance is calculated as:

    \[ \begin{align*} \sigma^2 = &\frac{1}{6}(5 - \mu)^2 + \frac{1}{6}(7 - \mu)^2 + \frac{2}{6}(10 - \mu)^2 + \\ & \frac{1}{6}(12 - \mu)^2 + \frac{1}{6}(14 - \mu)^2 \\ = & 8.56 \end{align*} \]

  • Consider two schools: in the first, all 20 students scored 10/20. In the second, half of the students scored 0/20 and the other half scored 20/20. Although both schools share an identical mean of 10/20, the first school has a variance of 0, whereas the second has a variance of 100. Evaluating the variance reveals differences between the two performance at the school that the mean alone fails to capture.

Tips and warnings

  • Calculating the mean of a single number is pointless, as is calculating the variance of only two numbers.

  • Because variance relies on squared values, taking the square root yields a more interpretable metric. For instance, a grade variance of 100 is difficult to interpret on a 0 to 20 scale. Taking the standard deviation (\(\sigma = \sqrt{100} = 10\)) returns the measure of dispersion to the original scale of the data.

  • In the formal definition shown in Equation 23.1, variance involves the squared distance from the mean, known as the second moment. Raising values to higher powers, such as \(X^3\), yields higher moments that describe additional geometric features of the distribution.

  • A normal distribution is fully characterized by two parameters: the mean and the variance. For distributions that are approximately normal, comparing these two metrics is sufficient to compare the entire underlying distributions.

  • Variance can be calculated using two main formulas: one in which the sum of squared deviations is divided by \(n\) (Equation 23.1), and another in which it is divided by \(n - 1\). Standard functions in R compute variance using the \(n - 1\) denominator. Division by \(n\) defines the population variance (Chapter 15), which represents complete population data (likely unknown). Division by \(n - 1\) defines the sample variance, providing an estimate of the unknown (true) population variance. Consequently, the \(n - 1\) formulation is the standard approach in empirical analysis.


  1. comparing the cumulative distributions is more rigorous↩︎