Sampling distributions and the central limit theorem: standard errors, confidence intervals and the √N rule
Ten problems on the sample mean and the central limit theorem: the mean and standard error of an average and of a sum, the sum of 100 dice with a continuity correction, a poll's margin, the sample size for a target error, a 95% confidence interval, the error of a Monte Carlo estimate, minibatch gradient noise, a sum of exponential waits, an A/B test, and a rare event where the normal approximation fails, with worked solutions and the mistakes of dividing by N instead of √N, standardizing a mean with σ, doubling the data to halve the error, adding standard errors, and trusting the normal when Np is small.
Before you start
Every number estimated from data is an average of something: a conversion rate, a validation accuracy, a Monte Carlo integral, a minibatch gradient. The sample mean is itself a random variable, and two facts describe it. Its standard deviation, the standard error, is ,σ/N, so the error shrinks with the square root of the amount of data and not in proportion to it. And whatever the distribution of a single observation, as long as its variance is finite, the central limit theorem says the average is close to normal once N is large. Together they turn a sample into a probability statement: how far the estimate is likely to be from the truth, how many samples a target accuracy needs, and whether a difference between two rates is bigger than the noise. These ten problems work through the standard error, the normal approximation for sums and proportions, confidence intervals, sample sizes, Monte Carlo and minibatch noise and a two-sample comparison, and end with a case where the approximation is poor. The five mistakes are the ones that give a confident wrong number.
x1,…,xN are independent draws from one distribution with mean μ and variance .σ2<∞. The sample mean is xˉ=N1∑nxn and the sum is .SN=∑nxn=Nxˉ.
E[xˉ]=μ and ,Var(xˉ)=σ2/N, because the variances of independent terms add and .Var(cX)=c2Var(X). The standard error is .SE=σ/N. For the sum, E[SN]=Nμ and .Var(SN)=Nσ2.
Central limit theorem. For large ,N,σ/Nxˉ−μ is approximately Normal,(0,1), whatever the distribution of each .xn. The approximation is better for symmetric distributions and worse for skewed ones.
Φ is the standard normal CDF, with .Φ(−z)=1−Φ(z). Useful values: ,Φ(1.25)=0.8944,,Φ(1.645)=0.95,,Φ(1.96)=0.975,.Φ(2)=0.9772.
A proportion is the mean of Bernoulli(p) variables, which have variance ,p(1−p), so the standard error of p^ is .p(1−p)/N. A rule of thumb for the normal approximation is Np≥10 and .N(1−p)≥10.
A 95% confidence interval for μ is ,xˉ±1.96SE, with σ replaced by the sample standard deviation s when it is unknown and N is large.
Continuity correction. When a sum of integers is approximated by a normal, P(SN≥k) is approximated by the normal probability above .k−21.
Measurements have mean μ=10 and standard deviation .σ=4. For the average of N=25 of them, find ,E[xˉ],Var(xˉ) and the standard error. Find the mean and standard deviation of their sum.
··
A fair die is rolled 100 times. Use the central limit theorem to approximate the probability that the total is at least .370.
··
In a city where exactly half the voters favor a measure, a poll asks N=400 random voters. Find the standard error of the sample proportion ,p^, and approximate the probability that the poll shows 55% or more in favor.
·
A proportion is to be estimated with a standard error of at most ,0.01, whatever the true p is. How many samples are needed? How many for a standard error of ?0.005?
··
A model's latency is measured on N=64 requests, with sample mean xˉ=52.3 ms and sample standard deviation s=8 ms. Find a 95% confidence interval for the true mean latency, and the width of the interval with N=256 requests and the same .s.
··
To estimate I=∫01x2dx by Monte Carlo, draw U1,…,UN∼Uniform(0,1) and average .Un2. Find the mean and variance of one term, the standard error with ,N=10000, and the N needed for a standard error of .0.001.
··
The gradient of a loss with respect to one weight varies across training examples with mean g and standard deviation .3. A minibatch gradient is the average over B examples drawn independently. Find the standard deviation of the minibatch gradient for ,B=32, and the batch size that halves it.
···
A job runs 50 independent stages, each taking an Exponential time with rate 2 per minute. Approximate the probability that the whole job takes more than 30 minutes, and say why the exact answer is larger.
···
An A/B test shows each version of a page to 2000 visitors. Version A converts 10% of them and version B .12%. Find the standard error of the difference ,p^B−p^A, the z-statistic, and whether the difference is significant at the two-sided 5% level.
···
A defect occurs on 1% of parts, independently. In a batch of ,N=100, find the exact probability of no defects, the Poisson approximation, and the normal approximation with a continuity correction. Which is poor, and why?
Answers
,E[xˉ]=10,,Var(xˉ)=0.64,;SE=0.8; the sum has mean 250 and standard deviation 20
P(S100≥370)≈0.127
;SE=0.025;,P(p^≥0.55)≈0.023, or 0.026 with the continuity correction
N=2500 for ,SE≤0.01, and N=10000 for SE≤0.005
(50.34,54.26) ms, width 3.92 ms; with 256 requests the width is 1.96 ms
,E[U2]=31,,Var(U2)=454,SE≈0.0030 at ;N=10000;N≈88900 for SE=0.001
sd(g^)≈0.530 at ;B=32;B=128 halves it to ≈0.265
P(T>30)≈0.079 by the central limit theorem; the exact value is 0.084
,SE≈0.0099,:z≈2.02: significant at ,5%, since ∣z∣>1.96 (two-sided )p≈0.043)
Exact ,0.3660, Poisson ,0.3679, normal ;0.3077; the normal is poor because Np=1
Worked solutions
Problem 1
Measurements have mean μ=10 and standard deviation .σ=4. For the average of N=25 of them, find ,E[xˉ],Var(xˉ) and the standard error. Find the mean and standard deviation of their sum.
E[xˉ]=251∑nE[xn]=2525⋅10=10Linearity of expectation; independence is not needed for this part.
Var(xˉ)=2521∑nVar(xn)=62525⋅16=2516=0.64Independence makes the variances add, and the factor 251 comes out squared.
SE=0.64=0.8=254The standard deviation of the average is .σ/N.
E[S25]=250 and Var(S25)=25⋅16=400The sum is ,25xˉ, so its variance is .252⋅0.64.
,E[xˉ]=10,,Var(xˉ)=0.64,;SE=0.8; the sum has mean 250 and standard deviation 20The sum spreads out like Nσ while the average tightens like .σ/N. Dividing by N instead of N gives 0.16 (Mistake 1).
Problem 2
A fair die is rolled 100 times. Use the central limit theorem to approximate the probability that the total is at least .370.
One roll: μ=61+2+⋯+6=3.5 and ,E[x2]=691, so σ2=691−3.52=1235.1+4+9+16+25+36=91.
E[S100]=350 and ,Var(S100)=100⋅1235≈291.67, so sd(S100)≈17.078Means and variances of independent rolls add.
P(S100≥370)≈P(Z≥17.078369.5−350)=P(Z≥1.1418)The total is an integer, so S≥370 is the same event as ;S>369.5; the continuity correction uses the midpoint.
1−Φ(1.1418)≈0.1268From a table or scipy.stats.norm.sf.
P(S100≥370)≈0.127The exact probability, by convolving the die's distribution with itself 100 times, is .0.1269. Without the continuity correction, z=20/17.078=1.171 and the estimate is ,0.1208, noticeably worse.
Problem 3
In a city where exactly half the voters favor a measure, a poll asks N=400 random voters. Find the standard error of the sample proportion ,p^, and approximate the probability that the poll shows 55% or more in favor.
SE(p^)=4000.5⋅0.5=200.5=0.025A proportion is a mean of Bernoulli(0.5) variables, each with variance .0.25.
z=0.0250.55−0.5=2Standardize with the standard error, not with the standard deviation of one vote.
P(p^≥0.55)≈1−Φ(2)≈0.0228The normal approximation is fine here: .Np=N(1−p)=200.
With the continuity correction, p^≥0.55 is k≥220 yes-votes, and P(k≥219.5)≈1−Φ(1.95)≈0.0256k has mean 200 and standard deviation .400⋅0.25=10.
;SE=0.025;,P(p^≥0.55)≈0.023, or 0.026 with the continuity correctionThe exact binomial probability is .0.0255. The usual "margin of error" of such a poll is 1.96×0.025≈4.9 percentage points.
Problem 4
A proportion is to be estimated with a standard error of at most ,0.01, whatever the true p is. How many samples are needed? How many for a standard error of ?0.005?
,p(1−p)≤41, with equality at p=21The worst case: p(1−p) is a downward parabola with its peak at .21.
N0.25≤0.01⟺N≥0.00010.25=2500Square both sides and solve for .N.
N0.25≤0.005⟺N≥0.0000250.25=10000The same calculation with the smaller target.
Halving the standard error multiplies N by 4,SE∝1/N, so .N∝1/SE2.
N=2500 for ,SE≤0.01, and N=10000 for SE≤0.005Each extra decimal digit of accuracy costs 100 times the data. Doubling to 5000 gives ,SE=0.00707, not 0.005 (Mistake 3).
Problem 5
A model's latency is measured on N=64 requests, with sample mean xˉ=52.3 ms and sample standard deviation s=8 ms. Find a 95% confidence interval for the true mean latency, and the width of the interval with N=256 requests and the same .s.
SE≈Ns=88=1 msσ is unknown, so the sample standard deviation stands in for it; with N=64 that is a good approximation.
xˉ±1.96SE=52.3±1.961.96 leaves 2.5% in each tail: .Φ(1.96)=0.975.
The interval is (50.34,54.26) msProcedures like this one cover the true mean in 95% of samples.
With ,N=256,SE=168=0.5 and the half-width is 0.98 msFour times the requests halves the interval.
(50.34,54.26) ms, width 3.92 ms; with 256 requests the width is 1.96 msThe 95% describes the procedure, not this particular interval: before the data are drawn, .P(∣xˉ−μ∣≤1.96SE)≈0.95. Using ,1.645, the one-sided 95% point, gives a 90% interval.
Problem 6
To estimate I=∫01x2dx by Monte Carlo, draw U1,…,UN∼Uniform(0,1) and average .Un2. Find the mean and variance of one term, the standard error with ,N=10000, and the N needed for a standard error of .0.001.
E[U2]=∫01u2du=31The estimator is unbiased: its mean is the integral.
,E[U4]=51, so Var(U2)=51−91=454≈0.0889The variance shortcut, with U2 as the variable.
SE=100004/45≈0.00298Standard deviation of one term, ,0.2981, over .10000=100.
N4/45≤10−6⟺N≥454×106≈88889Square the target.
,E[U2]=31,,Var(U2)=454,SE≈0.0030 at ;N=10000;N≈88900 for SE=0.001The error of Monte Carlo shrinks like 1/N in any dimension, which is why it is used for high-dimensional integrals where grids are hopeless, and why variance reduction pays.
Problem 7
The gradient of a loss with respect to one weight varies across training examples with mean g and standard deviation .3. A minibatch gradient is the average over B examples drawn independently. Find the standard deviation of the minibatch gradient for ,B=32, and the batch size that halves it.
The minibatch gradient is ,g^=B1∑b=1Bgb, with E[g^]=gAn average of unbiased per-example gradients is unbiased.
sd(g^)=323≈0.530The standard error of a mean.
Halving it needs B to double, so B=4⋅32=128.1283≈0.265.
128 examples cost 4 times the computation of 32One step with B=128 costs as much as four steps with ,B=32, and only halves the noise.
sd(g^)≈0.530 at ;B=32;B=128 halves it to ≈0.265This is the arithmetic behind the trade-off between batch size and number of steps. Sampling without replacement from a finite dataset makes the noise slightly smaller, by the factor (M−B)/(M−1) for a dataset of M examples.
Problem 8
A job runs 50 independent stages, each taking an Exponential time with rate 2 per minute. Approximate the probability that the whole job takes more than 30 minutes, and say why the exact answer is larger.
One stage: mean 21 minute and variance 221=41For an Exponential,(λ), the mean is λ1 and the variance .λ21.
The total T has E[T]=25 and ,Var(T)=12.5, so sd(T)≈3.536Fifty independent stages.
P(T>30)≈1−Φ(3.53630−25)=1−Φ(1.414)≈0.0786No continuity correction: T is continuous.
The exact T has a Gamma(50,2) distribution, and P(T>30)=P(Poisson(60)≤49)≈0.0844More than 30 minutes means at most 49 stage completions in 30 minutes of a rate-2 process.
P(T>30)≈0.079 by the central limit theorem; the exact value is 0.084Each exponential is skewed to the right, and 50 terms are not quite enough to make the sum symmetric, so the right tail is heavier than the normal's.
Problem 9
An A/B test shows each version of a page to 2000 visitors. Version A converts 10% of them and version B .12%. Find the standard error of the difference ,p^B−p^A, the z-statistic, and whether the difference is significant at the two-sided 5% level.
Var(p^A)=20000.10⋅0.90=4.5×10−5 and Var(p^B)=20000.12⋅0.88=5.28×10−5The variance of each proportion, with the observed rates in place of the unknown ones.
Var(p^B−p^A)=4.5×10−5+5.28×10−5=9.78×10−5The two groups are independent, so the variances add, even for a difference.
SE=9.78×10−5≈0.00989The square root comes after the adding.
z=0.009890.12−0.10≈2.02The difference in units of its standard error.
,SE≈0.0099,:z≈2.02: significant at ,5%, since ∣z∣>1.96 (two-sided )p≈0.043)Only just. Adding the two standard errors instead of the variances gives 0.0140 and z=1.43 (Mistake 4).
Problem 10
A defect occurs on 1% of parts, independently. In a batch of ,N=100, find the exact probability of no defects, the Poisson approximation, and the normal approximation with a continuity correction. Which is poor, and why?
P(k=0)=0.99100≈0.3660Each of the 100 parts must be good.
Poisson with :λ=Np=1:P(k=0)≈e−1≈0.3679For a rare event in many trials, the binomial is close to a Poisson with the same mean.
Normal: mean ,1, standard deviation ,100⋅0.01⋅0.99≈0.995, and P(k≤0.5)≈Φ(0.9950.5−1)=Φ(−0.5025)≈0.3077Continuity correction: k=0 is everything below .0.5.
,Np=1, far below the rule of thumb of 10The distribution of k is piled up at 0 and 1 with a long right tail, nothing like a bell curve, and the normal also puts probability on negative counts.
Exact ,0.3660, Poisson ,0.3679, normal ;0.3077; the normal is poor because Np=1The central limit theorem is a statement about large N for a fixed distribution; when p shrinks as N grows the limit is the Poisson, not the normal.
Where this goes wrong
1. Dividing σ by N instead of √N
The average of N values is the sum divided by ,N, so its spread is divided by N too.
σ=4 and ,N=25, as in Problem 1Right so far.
“The average divides everything by ,N, including the standard deviation.”Dividing by N divides the standard deviation of the sum by ,N, but the sum's standard deviation is ,Nσ=20, not .Nσ.
SE=254=0.16Five times too small. ,Var(xˉ)=σ2/N=0.64, so .SE=0.8. An interval built on 0.16 would claim far more precision than 25 measurements can give.
2. Standardizing a mean with σ
The z-score of a single observation is reused for an average.
Measurements have μ=10 and ,σ=4, and xˉ averages N=25 of themRight so far: Problem 1.
“:P(xˉ>11):.z=411−10=0.25.”The step that causes the mistake: 4 is the spread of one measurement; the average has spread .0.8.
P(xˉ>11)≈1−Φ(0.25)≈0.4013That is the chance that a single measurement exceeds .11. For the average, z=0.81=1.25 and .P(xˉ>11)≈1−0.8944=0.1056.
3. Doubling the data to halve the error
The error is assumed to shrink in proportion to the amount of data.
N=2500 gives SE≤0.01 for a proportionRight so far: Problem 4.
“Twice the data, half the error.”The error is proportional to ,1/N, not .1/N.
N=5000 gives SE≤0.005:0.25/5000≈0.00707: doubling the data cuts the error only by .2. Halving it needs four times the data, .N=10000.
4. Adding standard errors instead of variances
The standard error of a difference of two independent estimates is taken as the sum of their standard errors.
SE(p^A)=4.5×10−5≈0.00671 and SE(p^B)=5.28×10−5≈0.00727Right so far: Problem 9.
“.SE(p^B−p^A)=0.00671+0.00727=0.01397.”Standard deviations do not add; variances of independent quantities do.
,z=0.013970.02≈1.43, so the difference is not significantThe standard error is 4.5×10−5+5.28×10−5≈0.00989 and ,z≈2.02, which is significant at .5%. Adding standard errors always overstates the noise, here enough to reverse the conclusion.
5. The normal approximation when Np is small
The central limit theorem is applied to every binomial count.
,k∼Binomial(100,0.01), with mean 1 and standard deviation 0.995Right so far: Problem 10.
“100 trials is a large sample, so k is approximately normal.”What matters is the expected number of successes, ,Np=1, not the number of trials.
P(k=0)≈Φ(−0.5025)≈0.3077The exact value is ,0.99100≈0.3660, and the Poisson approximation e−1≈0.3679 is far closer. The normal also gives P(k≤−0.5)=Φ(−1.51)≈0.066 to counts below zero.