Concept map / Variance and standard deviation
Share
Variance and standard deviation
Compare sample and population variance by changing how the same squared deviations are averaged.
1Five scores, their distances and their squares
Two groups of five students both average 12 on a quiz. One group scored 8, 10, 12, 14 and 16; the other scored 11, 12, 12, 12 and 13. The mean cannot tell them apart. The variance can: it is the average squared distance from the mean. Its square root, the standard deviation, is back in points.
Each dot below is a score, each line its distance from the mean, and each square that distance squared. Squaring makes a distance below the mean count as much as one above it. After the center, spread is the next thing to describe about a distribution.
- Sum of squared distances
- 40
- Population variance (÷ 5)
- 8.00 points²
- Sample variance (÷ 4)
- 10.00 points²
- Population standard deviation
- 2.83 points
The scores 8, 10, 12, 14, 16 have mean 12. Their squared distances from the mean add to 40. Treated as the whole population, divided by N = 5, that gives a population variance of 8.00 points² and a standard deviation of 2.83 points, back in the units of the scores.
2Double every distance from the mean
The scores 8, 10, 12, 14, 16 have mean 12 and population variance 8. Push every score twice as far from the mean, giving 4, 8, 12, 16, 20. What happens to the variance?
3Add the squares, then divide by N or n − 1
For a whole population, divide the sum of squared distances by its size N. For a sample used to estimate a larger population, divide by n − 1. Point at a part of the formula to light it up in the lab.
σ² = (16 + 4 + 0 + 4 + 16) / 5 = 40 / 5 = 8.00 points², and σ = √8.00 = 2.83 points.
Why a sample divides by n − 1
A sample's own mean sits closer to its scores than the population mean does, so squared distances from it come out too small on average. Dividing by 4 instead of 5 makes the sample variance 5/4 of the population figure, which makes up the shortfall. The R code below checks this on 20,000 samples of five.
Variance is in squared points. A variance of 8 points² does not mean scores sit 8 points from the mean. For a distance you can read in points, take the square root: 2.83 points.
4Check yourself
The tasks use the sliders and divisor buttons in section 1 and tick themselves when you meet them.
- Using the whole-population divisor, set the variance to exactly 18 points².Now: Population divisor, variance 8.00 points²
- Move the mean to 16 or higher while the variance you see stays at 8 points².Now: Mean 12, variance 8.00 points²
- Switch to the sample divisor and find the spread at which it gives a variance 8 points² larger than the population divisor.Now: Population divisor, sample minus population variance 2.00 points²
5Population and sample variance in R
R’s var() and sd() divide by n − 1, so the snippet computes the population versions by hand. The last lines draw 20,000 samples of five scores from a normal population with variance 8. Dividing by n averages 6.45, below the true value, while var() averages 8.07.
Population and sample variance in RShow the code
# The page's default scores: mean 12, spread 2
scores <- c(8, 10, 12, 14, 16)
n <- length(scores)
ss <- sum((scores - mean(scores))^2)
c(mean = mean(scores), sum_of_squares = ss)
# var() and sd() divide by n - 1; divide by n yourself
# for the whole-population formula
c(population = ss / n, sample = var(scores))
round(c(population_sd = sqrt(ss / n), sample_sd = sd(scores)), 3)
# Why n - 1: draw many samples of 5 from a population
# whose variance is 8, and average each estimator
set.seed(1)
est <- replicate(20000, {
x <- rnorm(5, mean = 12, sd = sqrt(8))
c(divide_by_n = sum((x - mean(x))^2) / 5, var = var(x))
})
round(rowMeans(est), 2)Uses base R only.
What variance measures
- Each score adds the square of its distance from the mean, so far scores count much more than near ones, whichever side they are on.
- Adding the same number to every score moves the mean and leaves every distance, and so the variance, unchanged.
- Doubling every distance multiplies the variance by four and the standard deviation by two.
- Divide by N when the scores are the whole population. Divide by n − 1 when they are a random sample, because dividing by n underestimates the population variance on average.
- Analysis of variance splits sums of squares by source, and classical test theory splits score variance into true-score and error parts, which gives reliability.
Recommended reading
- Introductory Statistics 2eBarbara Illowsky and Susan Dean§2.7, sample and population variance and standard deviation