Monocurl Essays
Series Download

Standard error: how 1,000 people speak for a country

A random sample's accuracy depends on its own size, not on the population's. We prove the square-root law for the standard error and see its limits.

20 min·High school and early college·

AssumesThe central limit theorem: why bell curves are everywhereExpected value and the surprising power of adding averages

A simulation of 200 separate polls of the same population, in which 42% would say yes. Each dot is the result of one poll of 1000 randomly chosen people. The polls disagree, but they pile up in a bell around the truth, and nearly all of them land within about 3 percentage points of it.
Monocurl source
let N_POLLS = 200
let SHARES = map(range(0, N_POLLS), |t| poll(t, 1000, 1, P_TRUE))
let LO = 0.3525
let BINW = 0.003
let NB = 45
let X0 = -3.15
let DX = 0.14
let Y0 = -1.3
let R = 0.055
let SE = sqrt(P_TRUE * (1 - P_TRUE) / 1000)
let INSIDE = count(SHARES, |s| abs(s - P_TRUE) <= 2 * SE)
let xof = |v| X0 + (v - LO) / BINW * DX
let Pile = |k| {
    let kk = to_int(floor(k + 0.0001))
    var h = map(range(0, NB), |i| 0)
    var parts = []
    for (i in range(0, kk)) {
        let b = to_int(floor((SHARES[i] - LO) / BINW))
        if (b >= 0 and b < NB) {
            parts .= Pt([X0 + (b + 0.5) * DX, Y0 + R + 0.03 + h[b] * 2 * R, 0], AZURE, R)
            h[b] = h[b] + 1
        }
    }
    parts .= center{[-2.45, 0.95, 0]} scale{1.35} color{INK} Number(kk, 0)
    return parts
}
mesh axis = [
    Seg([X0, Y0, 0], [X0 + NB * DX, Y0, 0], SLATE, 2.5),
    map([36, 38, 40, 42, 44, 46, 48], |v| [
        Seg([xof(v / 100), Y0 - 0.08, 0], [xof(v / 100), Y0 + 0.08, 0], SLATE, 2),
        center{[xof(v / 100), Y0 - 0.32, 0]} Math(str_join([to_string(v), "\%%"]), 0.72, SLATE)
    ]),
    center{[0, Y0 - 0.7, 0]} Note("share saying yes in the poll", 0.74),
    center{[-2.45, 1.45, 0]} Cap("polls taken", 0.78, INK),
    center{[2.45, 1.45, 0]} Note("each dot: one poll", 0.74),
    center{[2.45, 1.13, 0]} Note("of 1000 people", 0.74)
]
mesh truth = [
    stroke{LEAF, 3} dashed{[0.14, 0.09]} Line([xof(P_TRUE), Y0, 0], [xof(P_TRUE), 1.68, 0]),
    center{[xof(P_TRUE), 1.92, 0]} Cap("truth: 42%%", 0.8, LEAF)
]
mesh pile = Pile(k: 0)
mesh band = []

slide "polls"
    play Wait(0.5)
    pile.k = N_POLLS
    play Lerp(7, [&pile], linear)
    band = [
        Seg([xof(P_TRUE - 2 * SE), Y0, 0], [xof(P_TRUE - 2 * SE), 0.75, 0], PLUM, 3),
        Seg([xof(P_TRUE + 2 * SE), Y0, 0], [xof(P_TRUE + 2 * SE), 0.75, 0], PLUM, 3),
        center{[2.55, 0.45, 0]} Cap("between the lines:", 0.76, PLUM),
        center{[2.55, 0.05, 0]} Math(str_join([to_string(INSIDE), "\text{ of }", to_string(N_POLLS)]), 0.95, PLUM)
    ]
    play Fade(0.7, [&band])
    play Wait(1.8)

Uses the shared definitions for this lesson's figures.

A national opinion poll typically questions about a thousand people. A large country has a couple of hundred million adults, so the poll hears from roughly one adult in two hundred thousand, and the newspapers report the result as accurate to within three percentage points.

That sounds impossible, and the natural repair makes it worse. Surely a poll should sample a decent fraction of the population, say one percent? One percent of a town of 5,000 is 50 people, and one percent of a country of 200 million is two million. The first poll would be nearly worthless and the second absurdly wasteful. The truth is that a random sample of a thousand does essentially the same job for a city, a country, or a planet. This lesson explains why, proves the formula behind the “three points”, and then looks at what that formula does not protect you from.

One population, many possible polls

To see how a poll behaves we need a population whose truth we know. Take a population in which exactly 42% would answer yes to some question. A poll questions $n$ people chosen at random and reports the share of them who say yes. Call that share $\hat p$ (read “p-hat”), to distinguish it from the true share $p = 0.42$.

The essential point is that $\hat p$ depends on who happened to be chosen. A different draw gives a different answer.

A population of 1500 people, of whom exactly 42% (blue) would say yes. Six different random samples of 100 people are drawn in turn. The share saying yes in the sample changes from one sample to the next, while the population stays the same.
Monocurl source
let NPOP = 1500
let COLS = 60
let GAP = 0.11
let YES = 630
let PERM = shuffle(NPOP, 1, 11)
let SAMPLES = map(range(0, 6), |s| take(shuffle(NPOP, s + 2, 12), 100))
let YES_IN = map(SAMPLES, |smp| count(smp, |i| PERM[i] < YES))
let cell = |i| [-3.245 + mod(i, COLS) * GAP, 1.98 - (i // COLS) * GAP, 0]
let Draw = |m| {
    let s = to_int(floor(m + 0.0001))
    return [
        map(SAMPLES[s], |i| center{cell(i)} fill{[EMBER, AZURE][PERM[i] < YES]} stroke{INK, 1.5} Rect([0.115, 0.115])),
        center{[-0.2, -1.25, 0]} scale{1.35} color{INK} Number(YES_IN[s], 0),
        center{[2.6, -1.25, 0]} scale{1.25} color{SLATE} Number(s + 1, 0)
    ]
}
mesh pop = map(range(0, NPOP), |i| center{cell(i)} fill{[tint(EMBER, 0.3), tint(AZURE, 0.35)][PERM[i] < YES]} stroke{alpha{0} PAPER, 0} Rect([0.085, 0.085]))
mesh labels = [
    center{[-2.0, -1.25, 0]} Cap("yes in this sample:", 0.8, INK),
    center{[0.55, -1.25, 0]} Cap("of 100", 0.8, INK),
    center{[1.95, -1.25, 0]} Note("sample", 0.76),
    center{[0, -1.85, 0]} Cap(str_join(["whole population: ", to_string(YES), " of ", to_string(NPOP), " say yes (42%%)"]), 0.76, AZURE)
]
mesh draw = Draw(m: 0)

slide "samples"
    play Wait(1.3)
    draw.m = 5.6
    play Lerp(8.5, [&draw], linear)
    play Wait(1.5)

Uses the shared definitions for this lesson's figures.

Each sample misses the truth by some amount, called its sampling error. In practice we take one poll and never learn its error, because we do not know $p$. What we can study is the whole collection of results that polls of this kind produce. That collection is called the sampling distribution of $\hat p$. The figure at the top shows it for polls of 1000: results pile up symmetrically around 0.42, with most of them within two or three points. If we can say how wide that pile is, then we know how far a single poll is likely to be from the truth.

The smallest poll, by hand

Take $n = 2$. Two people are chosen independently, each saying yes with probability 0.42.

Pause and try

List the possible values of $\hat p$ for a poll of two people and find their probabilities. Then compute the mean and the variance of $\hat p$. Recall that the variance of a random variable is the expected squared deviation from its mean.

Show answerHide answer

Both say no with probability $0.58^2 = 0.3364$, giving $\hat p = 0$. Exactly one says yes with probability $2 \times 0.42 \times 0.58 = 0.4872$, giving $\hat p = \frac12$. Both say yes with probability $0.42^2 = 0.1764$, giving $\hat p = 1$. The mean is $\frac12(0.4872) + 1(0.1764) = 0.42$. The variance is $E[\hat p^2] - 0.42^2 = \frac14(0.4872) + 0.1764 - 0.1764 = 0.1218$.

Two things in that answer are worth a second look. The mean of $\hat p$ is exactly the true share, 0.42: the poll is right on average. And its variance, 0.1218, is exactly half of $0.42 \times 0.58 = 0.2436$, which is the variance of a single person’s answer scored as 1 for yes and 0 for no. (One answer has mean $p$ and variance $p(1 - p)^2 + (1-p)p^2 = p(1-p)$.) With two people, the variance was divided by two. We should suspect that with $n$ people it is divided by $n$.

The spread depends on the sample size

  1. Polls of 100 people scatter widely: their results have a standard deviation of about 5 percentage points.
  2. Polls of 400 people, four times as many, scatter about half as much.
  3. Polls of 1600 people, four times as many again, halve the spread again, to a little over 1 point.
A simulation of polls of three sizes from the same population, 150 polls of each size. Every dot is one poll’s result, and the purple bar reaches one standard deviation either side of the average result. Each time the sample size is multiplied by four, the spread of the results is cut in half.
Monocurl source
let NS3 = [100, 400, 1600]
let VALS = map(range(0, 3), |k| map(range(0, 150), |t| poll(t, NS3[k], 20 + k, P_TRUE)))
let X0 = -2.3
let U = 4.8 / 28
let YS = [1.2, 0.15, -0.9]
let Row = |k| [
    Strip(VALS[k], X0, U, 28, YS[k], 0.5, 0.05, alpha{0.7} AZURE, 40 + k),
    Seg([X0 + (100 * (mean(VALS[k]) - std_dev(VALS[k])) - 28) * U, YS[k] - 0.42, 0], [X0 + (100 * (mean(VALS[k]) + std_dev(VALS[k])) - 28) * U, YS[k] - 0.42, 0], PLUM, 5),
    center{[3.2, YS[k] + 0.14, 0]} Math(to_string(100 * std_dev(VALS[k]), 1), 1.0, PLUM),
    center{[3.2, YS[k] - 0.2, 0]} Note("points", 0.72)
]
mesh axis = PctAxis(X0, U, 28, 56, 4, -1.42, "share saying yes in the poll")
mesh truth = [
    stroke{LEAF, 3} dashed{[0.14, 0.09]} Line([X0 + 14 * U, -1.42, 0], [X0 + 14 * U, 1.7, 0]),
    center{[X0 + 14 * U, 1.95, 0]} Cap("truth: 42%%", 0.78, LEAF),
    center{[3.2, 1.95, 0]} Cap("spread", 0.78, PLUM),
    map(range(0, 3), |k| [
        center{[-3.2, YS[k] + 0.14, 0]} Cap(to_string(NS3[k]), 0.9, INK),
        center{[-3.2, YS[k] - 0.2, 0]} Note("people", 0.72)
    ])
]
mesh r0 = []
mesh r1 = []
mesh r2 = []

slide "Polls of 100 people scatter widely: their results have a standard deviation of about 5 percentage points."
    r0 = Row(0)
    play Fade(0.7)

slide "Polls of 400 people, four times as many, scatter about half as much."
    r1 = Row(1)
    play Fade(0.7)

slide "Polls of 1600 people, four times as many again, halve the spread again, to a little over 1 point."
    r2 = Row(2)
    play Fade(0.7)

Uses the shared definitions for this lesson's figures.

The simulated spreads are 5.3, 2.6 and 1.2 points. Sixteen times the people bought four times the precision. That is what division of the variance by $n$ would predict: variance is squared spread, so dividing the variance by 16 divides the standard deviation by 4. Now we prove it.

Why the variance of a mean is $\sigma^2/n$

The proof needs the vocabulary of the lesson on expected value. A random variable $X$ is a function on a sample space; its expected value $E[X]$ is the probability-weighted average of its values; and expectation is linear, meaning $E[X + Y] = E[X] + E[Y]$ and $E[aX] = aE[X]$ for a constant $a$, whether or not $X$ and $Y$ have anything to do with each other. The variance is $\operatorname{Var}(X) = E[(X - \mu)^2]$ where $\mu = E[X]$. Two random variables $X$ and $Y$ are independent if $P(X = x \text{ and } Y = y) = P(X = x)\,P(Y = y)$ for all values $x$ and $y$.

Variance is not linear. The variance of a sum involves a square of a sum, and a square of a sum has a cross term:

$$ \bigl((X - \mu_X) + (Y - \mu_Y)\bigr)^2 = (X - \mu_X)^2 + 2(X - \mu_X)(Y - \mu_Y) + (Y - \mu_Y)^2. $$

Everything depends on what the cross term does on average. Here it is for two dice, where each deviation from 3.5 is one of $\pm 0.5, \pm 1.5, \pm 2.5$.

The cross term for two independent dice. Each cell holds the product of the two dice's deviations from 3.5, blue where the product is positive and orange where it is negative. The four blocks have totals of 20.25 with alternating signs, so the 36 equally likely products average exactly zero. With no cross term, the variance of the sum is the sum of the two variances, \frac{35}{12} + \frac{35}{12} = \frac{35}{6}.
The cross term for two independent dice. Each cell holds the product of the two dice’s deviations from 3.5, blue where the product is positive and orange where it is negative. The four blocks have totals of 20.25 with alternating signs, so the 36 equally likely products average exactly zero. With no cross term, the variance of the sum is the sum of the two variances, $\frac{35}{12} + \frac{35}{12} = \frac{35}{6}$.
Monocurl source
let CELL = 0.42
let GX = -3.25
let GY = -1.3
let dev = |a| a - 3.5
let pos = |a, b| [GX + (b - 0.5) * CELL, GY + (6.5 - a) * CELL, 0]
let TOTAL = sum(flatten(map(range(1, 7), |a| map(range(1, 7), |b| dev(a) * dev(b)))))
# variances as exact fractions: twelve times the variance of one die, and six times that of the sum
let V12 = 2 * sum(map(range(1, 7), |a| dev(a) ^ 2))
let V6 = sum(flatten(map(range(1, 7), |a| map(range(1, 7), |b| (dev(a) + dev(b)) ^ 2)))) / 6
let quad = |ra, rb| sum(flatten(map(ra, |a| map(rb, |b| dev(a) * dev(b)))))
let sgn = |v| {
    if (v > 0) {
        return str_join(["+", to_string(v, 2)])
    }
    return to_string(v, 2)
}
mesh grid = [
    map(range(1, 7), |a| map(range(1, 7), |b| center{pos(a, b)} fill{tint([EMBER, AZURE][dev(a) * dev(b) > 0], 0.12 + 0.11 * abs(dev(a) * dev(b)))} stroke{PAPER, 2} Rect([CELL, CELL]))),
    map(range(1, 7), |a| center{[GX - 0.36, GY + (6.5 - a) * CELL, 0]} Math(to_string(dev(a), 1), 0.7, SLATE)),
    map(range(1, 7), |b| center{[GX + (b - 0.5) * CELL, GY + 6 * CELL + 0.25, 0]} rotate{PI / 2} Math(to_string(dev(b), 1), 0.7, SLATE)),
    Outline([[GX, GY, 0], [GX + 6 * CELL, GY, 0], [GX + 6 * CELL, GY + 6 * CELL, 0], [GX, GY + 6 * CELL, 0]], SLATE, 2),
    Seg([GX + 3 * CELL, GY, 0], [GX + 3 * CELL, GY + 6 * CELL, 0], SLATE, 2),
    Seg([GX, GY + 3 * CELL, 0], [GX + 6 * CELL, GY + 3 * CELL, 0], SLATE, 2),
    center{pos(2, 2)} Math(sgn(quad([1, 2, 3], [1, 2, 3])), 0.8, INK),
    center{pos(2, 5)} Math(sgn(quad([1, 2, 3], [4, 5, 6])), 0.8, INK),
    center{pos(5, 2)} Math(sgn(quad([4, 5, 6], [1, 2, 3])), 0.8, INK),
    center{pos(5, 5)} Math(sgn(quad([4, 5, 6], [4, 5, 6])), 0.8, INK),
    center{[GX + 3 * CELL, GY - 0.35, 0]} Note("products of deviations", 0.72)
]
mesh sums = [
    center{[1.75, 1.5, 0]} Note("average of the 36 products", 0.74),
    center{[1.75, 1.0, 0]} Math(str_join(["\frac{", to_string(TOTAL, 0), "}{36} = 0"]), 1.0, INK),
    center{[1.75, 0.05, 0]} Note("average squared deviation", 0.74),
    center{[1.75, -0.28, 0]} Note("of the sum of the dice", 0.74),
    center{[1.75, -0.95, 0]} Math(str_join(["\frac{", to_string(V12, 0), "}{12} + 0 + \frac{", to_string(V12, 0), "}{12} = \frac{", to_string(V6, 0), "}{6}"]), 0.95, LEAF)
]

Uses the shared definitions for this lesson's figures.

For independent variables the cross term always averages to zero, for the reason the grid shows: whatever the first deviation is, the second is as likely to be on either side of its own mean, in exact balance. Here is the argument in general.

Independence is used exactly once, to kill the cross term. Without it the cross term can be positive or negative, and the theorem is false: if $Y = X$ then $\operatorname{Var}(X + Y) = \operatorname{Var}(2X) = 4\operatorname{Var}(X)$, which is twice what the theorem would give.

The two factors of $n$ have different origins. Adding $n$ independent quantities multiplies the variance by $n$: the sum is more variable than any one term. Dividing by $n$ to form the average divides the variance by $n^2$. The net effect is one factor of $n$ in the denominator.

For our polls, $\sqrt{0.42 \times 0.58} \approx 0.494$, so the standard error is $0.494/\sqrt n$: 4.9 points at $n = 100$, 2.5 at 400, 1.2 at 1600. The simulated 5.3, 2.6 and 1.2 agree with these to within the scatter expected of a standard deviation estimated from only 150 polls, which is about 6% of its value. The standard error and the standard deviation are easy to confuse. The standard deviation $\sigma$ describes how much individuals differ from one another, and collecting more data does not change it. The standard error describes how much the average would differ from one sample to another, and it shrinks as the sample grows.

The spread of poll results against sample size. The dots are standard deviations of 400 simulated polls at each size, and the curve is the standard error \sqrt{p(1-p)/n}. The curve falls steeply at first and then flattens: the gain from 100 to 400 people is 2.5 points, and from 400 to 1600 only 1.2.
The spread of poll results against sample size. The dots are standard deviations of 400 simulated polls at each size, and the curve is the standard error $\sqrt{p(1-p)/n}$. The curve falls steeply at first and then flattens: the gain from 100 to 400 people is 2.5 points, and from 400 to 1600 only 1.2.
Monocurl source
let NS5 = [25, 50, 100, 200, 400, 800, 1600]
let SDS = map(range(0, 7), |k| 100 * std_dev(map(range(0, 400), |t| poll(t, NS5[k], 50 + k, P_TRUE))))
let se = |n| 100 * sqrt(P_TRUE * (1 - P_TRUE) / n)
let fs = Frame(0, 1700, 0, 11, [-0.05, 0.1, 0], 6.2, 2.9)
mesh frame = [
    GridLines(fs, [400, 800, 1200, 1600], [2, 4, 6, 8, 10]),
    Axes(fs),
    XTicks(fs, [400, 800, 1200, 1600]),
    YTicks(fs, [2, 4, 6, 8, 10]),
    center{[fx(fs, 850), fy(fs, 0) - 0.68, 0]} Note("sample size n", 0.74),
    center{[fx(fs, 0) + 1.9, fy(fs, 11) + 0.42, 0]} Note("spread of results (percentage points)", 0.74)
]
mesh guides = map([100, 400, 1600], |n| [
    stroke{LEAF, 2.5} dashed{[0.1, 0.07]} Line(at(fs, n, 0), at(fs, n, se(n))),
    center{at(fs, n, se(n)) + [0.42, 0.34, 0]} Math(to_string(se(n), 1), 0.9, LEAF)
])
mesh curve = Path(map(sample(20.2, 1700, 200), |n| at(fs, n, se(n))), EMBER, 4)
mesh dots = map(range(0, 7), |k| Pt(at(fs, NS5[k], SDS[k]), AZURE, 0.1))
mesh labels = [
    center{at(fs, 1050, 8.6)} Math("\text{standard error} = \sqrt{\frac{p(1-p)}{n}}", 0.9, EMBER),
    center{at(fs, 1050, 5.9)} Cap("dots: simulated polls", 0.76, AZURE)
]

Uses the shared definitions for this lesson's figures.

The population size is not in the formula

Look at $\sigma/\sqrt n$ again. There is no symbol in it for the size of the population. The proof never mentioned it. All that was assumed is that each draw is independent of the others and has the population’s mean and variance, which is what happens if each person is picked at random with replacement, so that the same person could in principle be picked twice.

Pause and try

A poll of 1000 people is taken in a city of one million, and another poll of 1000 in a country of 250 million. In both, 42% of the population would say yes. Which poll has the smaller standard error?

Show answerHide answer

Neither, to any accuracy that matters. Both have standard error $\sqrt{0.42 \times 0.58 / 1000} \approx 0.0156$, or 1.56 percentage points. The polls differ in the fraction of the population they reach, by a factor of 250, and that fraction is irrelevant.

A cook tasting soup is the standard comparison. If the pot is well stirred, one spoonful tells you how salty it is, whether the pot holds two liters or two hundred. What matters is that the spoonful is a fair sample, and how big the spoon is.

Real polls do not question anyone twice, so they sample without replacement, and then the draws are very slightly dependent. The effect is known exactly. For a simple random sample of $n$ from a population of $N$, the variance of the sample mean is $\frac{\sigma^2}{n}$ multiplied by the finite population correction $\frac{N - n}{N - 1}$. (The last problem derives it.) The correction is essentially 1 when the sample is a small part of the population, and it reaches 0 when $n = N$, since then the “sample” is a census and has no sampling error at all.

The exact standard error of a poll of 1000 people, with the finite population correction, plotted against the size of the population on a logarithmic scale. It is zero for a population of 1000 (everyone is asked), climbs quickly, and is flat at 1.56 points from about a hundred thousand upward.
The exact standard error of a poll of 1000 people, with the finite population correction, plotted against the size of the population on a logarithmic scale. It is zero for a population of 1000 (everyone is asked), climbs quickly, and is flat at 1.56 points from about a hundred thousand upward.
Monocurl source
let se_N = |L| 100 * sqrt(P_TRUE * (1 - P_TRUE) / 1000 * (10 ^ L - 1000) / (10 ^ L - 1))
let fn = Frame(3, 8.7, 0, 2.1, [0.05, 0.1, 0], 6.2, 2.9)
mesh frame = [
    GridLines(fn, [4, 5, 6, 7, 8], [0.5, 1, 1.5, 2]),
    Seg(at(fn, 3, 0), at(fn, 8.7, 0), SLATE, 2.5),
    Seg(at(fn, 3, 0), at(fn, 3, 2.1), SLATE, 2.5),
    map([3, 4, 5, 6, 7, 8], |L| center{[fx(fn, L), fy(fn, 0) - 0.32, 0]} Math(str_join(["10^", to_string(L)]), 0.76, SLATE)),
    map([0.5, 1, 1.5, 2], |v| center{[fx(fn, 3) - 0.4, fy(fn, v), 0]} Math(to_string(v, 1), 0.72, SLATE)),
    center{[fx(fn, 5.85), fy(fn, 0) - 0.72, 0]} Note("population size N (people)", 0.74),
    center{[fx(fn, 3) + 1.9, fy(fn, 2.1) + 0.32, 0]} Note("standard error of the poll (points)", 0.74)
]
mesh curve = Path(map(sample(3.0001, 8.7, 240), |L| at(fn, L, se_N(L))), EMBER, 4.5)
mesh marks = [
    Pt(at(fn, log10(2000), se_N(log10(2000))), AZURE, 0.1),
    center{at(fn, 4.45, 0.92)} Cap(str_join(["town of 2000: ", to_string(se_N(log10(2000)), 2)]), 0.76, AZURE),
    Pt(at(fn, 6, se_N(6)), AZURE, 0.1),
    center{at(fn, 5.75, 1.88)} Cap(str_join(["1 million: ", to_string(se_N(6), 2)]), 0.76, AZURE),
    Pt(at(fn, log10(250000000), se_N(log10(250000000))), AZURE, 0.1),
    center{at(fn, 7.85, 1.88)} Cap(str_join(["250 million: ", to_string(se_N(log10(250000000)), 2)]), 0.76, AZURE)
]

Uses the shared definitions for this lesson's figures.

From standard error to margin of error

The standard error is a standard deviation, and the central limit theorem says what shape goes with it: for large $n$, the sample mean is approximately normal around $\mu$. By the 68-95-99.7 rule, about 95% of samples give a mean within two standard errors of the truth. Pollsters call two standard errors (more exactly 1.96) the margin of error, and the next lesson turns it into a confidence interval.

For a poll of 1000 with $p$ near one half, the standard error is $\sqrt{0.5 \times 0.5/1000} \approx 0.0158$, and twice that is 3.2 points. That is the origin of the “plus or minus three points” attached to polls of about a thousand people. In the simulation at the top of the page, 189 of the 200 polls, 94.5%, landed within two standard errors of 42%.

One practical difficulty remains. The formula uses $\sigma$, or $p$, which are properties of the population and are exactly what we do not know. In practice they are replaced by estimates from the sample itself: $\hat p$ in place of $p$, and the sample standard deviation $s$ from the first lesson in place of $\sigma$. For samples of decent size this substitution changes little, because $\sqrt{p(1-p)}$ moves slowly: it is 0.494 at $p = 0.42$ and 0.500 at $p = 0.5$.

Worked examples

What the formula does not cover

Everything above assumed a random sample: each person equally likely to be chosen, and each chosen person answering. The standard error measures the error due to the luck of the draw and nothing else.

In 1936 the magazine Literary Digest mailed questionnaires to ten million Americans, drawn from telephone directories and car registrations, and about 2.4 million replied. From this enormous sample it predicted that Alf Landon would beat Franklin Roosevelt with about 57% of the vote. Landon received about 37%.

Pause and try

Use the formula to compute the standard error of a sample proportion with $n = 2{,}400{,}000$ and $p$ near one half. What does the size of the Digest’s actual error tell you?

Show answerHide answer

$\sqrt{0.25/2{,}400{,}000} \approx 0.00032$, about three hundredths of a percentage point. The actual error was about 20 points, more than six hundred standard errors. Chance cannot produce that. The sample was not a random one: people with telephones and cars in 1936 were richer than average, and those who chose to reply differed again from those who did not.

A systematic difference between the sample and the population is called bias. The sampling error shrinks like $1/\sqrt n$. Bias does not shrink at all.

A simulation of two kinds of poll of a population in which 42% say yes. Random samples of 1000 scatter around the truth. In the other polls, people decide for themselves whether to answer, and those who say yes are one and a half times as likely to respond. With 4000 responses each, those polls agree closely with one another and are all about ten points too high.
A simulation of two kinds of poll of a population in which 42% say yes. Random samples of 1000 scatter around the truth. In the other polls, people decide for themselves whether to answer, and those who say yes are one and a half times as likely to respond. With 4000 responses each, those polls agree closely with one another and are all about ten points too high.
Monocurl source
let RESP = P_TRUE * 0.9 / (P_TRUE * 0.9 + (1 - P_TRUE) * 0.6)
let FAIR = map(range(0, 150), |t| poll(t, 1000, 30, P_TRUE))
let SKEW = map(range(0, 150), |t| poll(t, 4000, 31, RESP))
let X0 = -3.3
let U = 0.33
mesh axis = PctAxis(X0, U, 36, 56, 2, -1.3, "share saying yes in the poll")
mesh truth = [
    stroke{LEAF, 3} dashed{[0.14, 0.09]} Line([X0 + 6 * U, -1.3, 0], [X0 + 6 * U, 1.7, 0]),
    center{[X0 + 6 * U, 1.95, 0]} Cap("truth: 42%%", 0.78, LEAF)
]
mesh rows = [
    Strip(FAIR, X0, U, 36, 0.95, 0.55, 0.055, alpha{0.7} AZURE, 60),
    center{[1.95, 1.15, 0]} Cap("1000 chosen at random", 0.76, AZURE),
    center{[1.95, 0.75, 0]} Math(str_join(["\text{average } ", to_string(100 * mean(FAIR), 1), "\%%"]), 0.85, AZURE),
    Strip(SKEW, X0, U, 36, -0.45, 0.55, 0.055, alpha{0.7} ROSE, 61),
    center{[0.05, -0.25, 0]} Cap("4000 who volunteered", 0.76, ROSE),
    center{[0.05, -0.65, 0]} Math(str_join(["\text{average } ", to_string(100 * mean(SKEW), 1), "\%%"]), 0.85, ROSE)
]

Uses the shared definitions for this lesson's figures.

A large biased sample is worse than a small one in one respect: its results are tightly clustered, which looks like precision. In the same 1936 election George Gallup used a sample of about 50,000, chosen to resemble the electorate, and called the winner correctly.

Two more cautions belong here. If the draws are not independent, for instance because whole households or whole classrooms are sampled together, the cross terms in the proof do not vanish, and the standard error is larger than $\sigma/\sqrt n$. And if the population has no finite variance, as with the flashlight distribution of the last lesson, there is no $\sigma$ to divide.

Stepping back

The paradox at the start came from thinking of a sample as a piece of the population, which ought to be a respectable fraction of it. A random sample is better thought of as $n$ independent measurements of the same unknown number, each one noisy. Averaging independent noisy measurements cancels the noise at the rate $1/\sqrt n$, because the variances add while the average divides by $n$, and nothing in that argument asks how many measurements were available in principle. The same argument runs under every use of averaging in science, from repeated weighings to clinical trials.

The square root cuts both ways. It is why a thousand people suffice, and it is also why the next decimal place of accuracy costs a hundred times as much. And it describes only the error that randomness creates. Whether the sample was fair is a separate question that no formula answers.

Check yourself

A random sample of 400 households gives a mean weekly grocery bill of $150, and the standard deviation of the bills is $60. A second survey will use 1600 households. What happens to the standard error of the mean?

Problems

The first three apply the formula. The next three test what it does and does not assume. The last two are proofs.

Problem 1

In a random sample of 400 students, 120 say they walk to school. Estimate the proportion who walk, and give the standard error and the margin of error.

Show solutionHide solution

$\hat p = \frac{120}{400} = 0.30$. The standard error is $\sqrt{0.30 \times 0.70/400} = \sqrt{0.000525} \approx 0.0229$, or 2.3 points. The margin of error is about $2 \times 2.3 = 4.6$ points: “30%, give or take about 5”.

Problem 2

A random sample of 64 light bulbs has a mean lifetime of 1010 hours and a sample standard deviation of 120 hours. Find the standard error of the mean, and the range within two standard errors of the sample mean.

Show solutionHide solution

Using $s = 120$ in place of $\sigma$, the standard error is $\frac{120}{\sqrt{64}} = 15$ hours. Two standard errors either side of 1010 is the range from 980 to 1040 hours.

Problem 3

A poll of 600 people has a certain margin of error. How many people are needed to halve it? To cut it to a third?

Show solutionHide solution

The margin is proportional to $1/\sqrt n$. To halve it, $\sqrt n$ must double, so $n$ must be multiplied by 4: 2400 people. To cut it to a third, $n$ must be multiplied by 9: 5400 people.

Problem 4

A population consists of three equally likely values, 1, 2 and 6. (a) Find its mean $\mu$ and variance $\sigma^2$. (b) List all nine equally likely samples of size 2 drawn with replacement, and the mean of each. (c) Verify directly that the nine sample means have mean $\mu$ and variance $\sigma^2/2$.

Show solutionHide solution

(a) $\mu = \frac{1 + 2 + 6}{3} = 3$. The squared deviations are $4, 1, 9$, so $\sigma^2 = \frac{14}{3}$. (b) The samples and their means: $(1,1) \to 1$; $(1,2)$ and $(2,1) \to 1.5$; $(1,6)$ and $(6,1) \to 3.5$; $(2,2) \to 2$; $(2,6)$ and $(6,2) \to 4$; $(6,6) \to 6$. (c) The nine means add up to $1 + 1.5 + 1.5 + 3.5 + 3.5 + 2 + 4 + 4 + 6 = 27$, so their mean is 3. Their squared deviations from 3 are $4$, $2.25$, $2.25$, $0.25$, $0.25$, $1$, $1$, $1$, $9$, which total 21. The variance is $\frac{21}{9} = \frac73$, and $\frac{\sigma^2}{2} = \frac{14}{6} = \frac73$.

Problem 5

Country A has 5 million adults and country B has 500 million. A random sample of 1500 adults is taken in each. (a) Compare the standard errors of the two polls, assuming the same true proportion. (b) A village of 3000 adults is also polled, with 1500 chosen at random without replacement. By what factor does the finite population correction reduce its standard error?

Show solutionHide solution

(a) They are the same for all practical purposes: $\sqrt{p(1-p)/1500}$ in both. The correction factors $\sqrt{\frac{N - n}{N - 1}}$ are 0.99985 for A and 0.9999985 for B. (b) $\sqrt{\frac{3000 - 1500}{3000 - 1}} = \sqrt{\frac{1500}{2999}} \approx 0.707$. Asking half the village reduces the standard error by about 29% compared with independent draws.

Problem 6

A pollster interviews both adults in each of 500 randomly chosen two-adult households, for 1000 interviews in all. Suppose the two adults in a household always give the same answer, and different households are independent. Find the standard error of the sample proportion, and compare it with that of 1000 independent interviews. Which step of the lesson’s proof fails?

Show solutionHide solution

Each household contributes two identical answers, so the proportion among the 1000 interviews equals the proportion among the 500 households. The households are independent, so the standard error is $\sqrt{p(1-p)/500}$. That is $\sqrt 2 \approx 1.41$ times the value $\sqrt{p(1-p)/1000}$ for independent interviews: the second interview in each household adds no information. In the proof, the cross term $E[A_iA_j]$ for two adults in the same household is not zero. It equals $E[A_i^2] = \sigma^2$, since $A_j = A_i$. There are 500 such pairs, each counted twice, adding $1000\sigma^2$ to the variance of the sum and doubling it.

Problem 7

Two independent polls of 1000 people each are taken a month apart. A candidate’s support is 45% in the first and 48% in the second. (a) Show that for independent $X$ and $Y$, $\operatorname{Var}(X - Y) = \operatorname{Var}(X) + \operatorname{Var}(Y)$. (b) Find the standard error of the difference between the two polls, taking $p(1-p) \approx \frac14$. (c) Is a rise of 3 points strong evidence that support has changed?

Show solutionHide solution

(a) $X - Y = X + (-Y)$. The variable $-Y$ is independent of $X$, and $\operatorname{Var}(-Y) = (-1)^2\operatorname{Var}(Y) = \operatorname{Var}(Y)$. So by the addition theorem $\operatorname{Var}(X - Y) = \operatorname{Var}(X) + \operatorname{Var}(Y)$. Variances add even when the variables are subtracted. (b) Each poll has variance $\frac{0.25}{1000}$, so the difference has variance $\frac{0.5}{1000}$ and standard error $\sqrt{0.0005} \approx 0.0224$, about 2.2 points. (c) The observed change is $3/2.2 \approx 1.3$ standard errors. A difference that size or larger arises by chance fairly often when nothing has changed (between a third and a twentieth of the time, by the 68-95 rule), so it is weak evidence. A difference between two polls is noisier than either poll alone.

Problem 8

(The finite population correction.) A population has $N$ members with values $v_1, \dots, v_N$, mean $\mu$ and variance $\sigma^2$. Draw $n$ members at random without replacement and let $X_1, \dots, X_n$ be their values. Each $X_i$ has mean $\mu$ and variance $\sigma^2$, and by symmetry every pair has the same value $c = E[(X_i - \mu)(X_j - \mu)]$ for $i \ne j$. (a) By considering $n = N$, show that $c = -\frac{\sigma^2}{N - 1}$. (b) Deduce that $\operatorname{Var}(\bar X) = \frac{\sigma^2}{n} \cdot \frac{N - n}{N - 1}$.

Show solutionHide solution

Write $A_i = X_i - \mu$. As in the lesson’s proof, squaring $A_1 + \dots + A_n$ and taking expectations gives $n$ squares, each with expectation $\sigma^2$, and $n(n-1)$ ordered pairs $i \ne j$, each with expectation $c$:

$$ \operatorname{Var}(X_1 + \dots + X_n) = n\sigma^2 + n(n-1)c. $$

(a) When $n = N$ the sample is the whole population, so $X_1 + \dots + X_N = v_1 + \dots + v_N$ whatever the order of drawing. A constant has variance 0, so $N\sigma^2 + N(N-1)c = 0$, which gives $c = -\frac{\sigma^2}{N-1}$. The value of $c$ does not depend on how many draws we go on to make, so it is the same for every $n$. It is negative because drawing a high value leaves slightly lower values behind.

(b) Substituting,

$$ \operatorname{Var}(X_1 + \dots + X_n) = n\sigma^2 - \frac{n(n-1)\sigma^2}{N - 1} = n\sigma^2 \cdot \frac{(N - 1) - (n - 1)}{N - 1} = n\sigma^2 \cdot \frac{N - n}{N - 1}. $$

Dividing by $n^2$ gives $\operatorname{Var}(\bar X) = \frac{\sigma^2}{n} \cdot \frac{N - n}{N - 1}$. For $N = 250{,}000{,}000$ and $n = 1000$ the factor is 0.999996, and for $n = N$ it is 0.

Shared definitions used by this lesson's figures
# house kit: prepended to every essay figure after the std imports

# palette. AZURE and EMBER are the two actors, LEAF marks an answer, ROSE a problem
let PAPER = [1, 1, 1, 1]
let INK = [0.08, 0.09, 0.11, 1]
let SLATE = [0.40, 0.44, 0.50, 1]
let MIST = [0.85, 0.86, 0.88, 1]
let AZURE = [0.13, 0.42, 0.68, 1]
let EMBER = [0.89, 0.42, 0.12, 1]
let LEAF = [0.13, 0.55, 0.36, 1]
let ROSE = [0.78, 0.22, 0.24, 1]
let PLUM = [0.47, 0.30, 0.66, 1]
let GOLD = [0.85, 0.62, 0.08, 1]

background = PAPER

# an opaque pastel of col; use for fills so overlaps do not darken
let tint = |col, amount = 0.18| [
    1 - (1 - col[0]) * amount,
    1 - (1 - col[1]) * amount,
    1 - (1 - col[2]) * amount,
    1
]

# text: Cap for labels, Note for quiet labels, Math for typeset maths
let Cap = |txt, size = 0.75, col = INK| color{col} Text(txt, size, "Charter")
let Note = |txt, size = 0.65| color{SLATE} Text(txt, size, "Charter")
let Math = |tex, size = 0.9, col = INK| color{col} Tex(tex, size)

# a paper rectangle to sit behind text that crosses lines
let Plate = |pos, size| center{pos} fill{PAPER} stroke{alpha{0} PAPER, 0} Rect(size)

# shapes with fill and stroke both set, so no stray black appears
let Pt = |pos, col = INK, r = 0.075| center{pos} fill{col} stroke{col, 1} Circle(r, 48)
let Ring = |pos, col = INK, r = 0.1, w = 3| center{pos} fill{PAPER} stroke{col, w} Circle(r, 48)
let Seg = |a, b, col = INK, w = 3| stroke{col, w} Line(a, b)
let Path = |pts, col = INK, w = 3| stroke{col, w} Polyline(pts)
let Region = |pts, col| fill{col} stroke{alpha{0} col, 0} Polygon(pts)
let Outline = |pts, col = INK, w = 3| fill{alpha{0} PAPER} stroke{col, w} Polygon(pts)
let Shape = |pts, col, amount = 0.18, w = 3| fill{tint(col, amount)} stroke{col, w} Polygon(pts)
let Disc = |pos, r, col, amount = 0.18, w = 3| center{pos} fill{tint(col, amount)} stroke{col, w} Circle(r, 96)
let Box = |pos, size, col, amount = 0.18, w = 3| center{pos} fill{tint(col, amount)} stroke{col, w} Rect(size)
# a line from a to b ending in a small solid arrowhead
let Tip = |a, b, col = INK, w = 3, head = 0.17| {
    let d = normalize([b[0] - a[0], b[1] - a[1], 0])
    let n = [-d[1], d[0], 0]
    let base = [b[0] - d[0] * head, b[1] - d[1] * head, 0]
    return [
        stroke{col, w} Line(a, base),
        fill{col} stroke{col, 1} Polygon([
            b,
            [base[0] + n[0] * head * 0.42, base[1] + n[1] * head * 0.42, 0],
            [base[0] - n[0] * head * 0.42, base[1] - n[1] * head * 0.42, 0]
        ])
    ]
}

# plots. a frame is [x0, x1, y0, y1, centre, width, height]: a data window and the scene box it fills
let Frame = |x0, x1, y0, y1, c = [0, 0, 0], w = 6.4, h = 3.6| [x0, x1, y0, y1, c, w, h]
let fx = |fr, x| fr[4][0] + (x - (fr[0] + fr[1]) / 2) * fr[5] / (fr[1] - fr[0])
let fy = |fr, y| fr[4][1] + (y - (fr[2] + fr[3]) / 2) * fr[6] / (fr[3] - fr[2])
let at = |fr, x, y| [fx(fr, x), fy(fr, y), 0]

# axes through the data origin (or the nearest edge of the window), with optional names
let Axes = |fr, x_name = "", y_name = "", col = SLATE| {
    let ox = clamp(fr[0], 0, fr[1])
    let oy = clamp(fr[2], 0, fr[3])
    var parts = [
        Tip(at(fr, fr[0], oy), [fx(fr, fr[1]) + 0.25, fy(fr, oy), 0], col, 2.5, 0.15),
        Tip(at(fr, ox, fr[2]), [fx(fr, ox), fy(fr, fr[3]) + 0.25, 0], col, 2.5, 0.15)
    ]
    if (x_name != "") {
        parts .= center{[fx(fr, fr[1]) + 0.5, fy(fr, oy), 0]} Math(x_name, 0.8, col)
    }
    if (y_name != "") {
        parts .= center{[fx(fr, ox), fy(fr, fr[3]) + 0.5, 0]} Math(y_name, 0.8, col)
    }
    return parts
}

# tick marks with numbers at the listed data values
let XTicks = |fr, xs, col = SLATE, places = 0| block {
    let oy = fy(fr, clamp(fr[2], 0, fr[3]))
    for (x in xs) {
        . Seg([fx(fr, x), oy - 0.07, 0], [fx(fr, x), oy + 0.07, 0], col, 2)
        . center{[fx(fr, x), oy - 0.33, 0]} Math(to_string(x, places), 0.72, col)
    }
}
let YTicks = |fr, ys, col = SLATE, places = 0| block {
    let ox = fx(fr, clamp(fr[0], 0, fr[1]))
    for (y in ys) {
        . Seg([ox - 0.07, fy(fr, y), 0], [ox + 0.07, fy(fr, y), 0], col, 2)
        . center{[ox - 0.36, fy(fr, y), 0]} Math(to_string(y, places), 0.72, col)
    }
}

# faint grid lines at the listed data values
let GridLines = |fr, xs, ys, col = MIST| block {
    for (x in xs) {
        . Seg(at(fr, x, fr[2]), at(fr, x, fr[3]), col, 1.5)
    }
    for (y in ys) {
        . Seg(at(fr, fr[0], y), at(fr, fr[1], y), col, 1.5)
    }
}

# the graph of f over [a, b], drawn in the frame. values are clamped to the window
let Graph = |fr, f, a, b, col = AZURE, w = 4, n = 160|
    stroke{col, w} Polyline(map(sample(a, b, n), |x| at(fr, x, clamp(fr[2], f(x), fr[3]))))

# the region between the graph of f and the x axis over [a, b]
let AreaUnder = |fr, f, a, b, col = AZURE, amount = 0.2, n = 80| {
    var pts = [at(fr, a, 0)]
    for (x in sample(a, b, n)) {
        pts .= at(fr, x, clamp(fr[2], f(x), fr[3]))
    }
    pts .= at(fr, b, 0)
    return fill{tint(col, amount)} stroke{alpha{0} col, 0} Polygon(pts)
}

# a double sine hash: std seeded_random makes these polls a few percent too variable
let frac = |x| mod(mod(x, 1) + 1, 1)
let rnd = |i, salt| frac(sin(i * 39.3468 + salt * 11.135 + frac(sin(i * 12.9898 + salt * 78.233) * 43758.5453) * 6.2831853) * 24634.6345)
# the running example: 42 percent of the population would say yes
let P_TRUE = 0.42
# the share saying yes in poll number t of n independent people, each yes with chance p
let poll = |t, n, salt, p| {
    var c = 0
    for (j in range(0, n)) {
        if (rnd(t * n + j + 1, salt) < p) {
            c = c + 1
        }
    }
    return c / n
}
# a random arrangement of 0..n-1 (Fisher-Yates), reproducible from t
let shuffle = |n, t, salt| {
    var p = map(range(0, n), |i| i)
    var i = n - 1
    while (i > 0) {
        let j = to_int(floor((i + 1) * rnd(t * 2003 + i, salt)))
        let tmp = p[i]
        p[i] = p[j]
        p[j] = tmp
        i = i - 1
    }
    return p
}
# a percent axis: value v (in percent) sits at x0 + (v - lo) * u
let PctAxis = |x0, u, lo, hi, step, y, name| block {
    . Seg([x0 - 0.1, y, 0], [x0 + (hi - lo) * u + 0.1, y, 0], SLATE, 2.5)
    for (v in range(lo, hi + 1, step)) {
        . Seg([x0 + (v - lo) * u, y - 0.08, 0], [x0 + (v - lo) * u, y + 0.08, 0], SLATE, 2)
        . center{[x0 + (v - lo) * u, y - 0.32, 0]} Math(str_join([to_string(v), "\%%"]), 0.72, SLATE)
    }
    . center{[x0 + (hi - lo) / 2 * u, y - 0.7, 0]} Note(name, 0.74)
}
# one dot per poll at its result, scattered vertically so the dots can be told apart
let Strip = |vals, x0, u, lo, y, spread, r, col, salt| map(range(0, len(vals)), |i| Pt([x0 + (100 * vals[i] - lo) * u, y + (rnd(i + 1, salt) - 0.5) * spread, 0], col, r))