13.11 Probability problem set, part c: limit theorems and confidence intervals
LLN, CLT, confidence intervals, bootstrap puts an interval on every number your models report: the bits per character of the RNN language model, the BLEU of beam search, the accuracies of the evaluation harness in AI Engineering. Code computes those intervals without complaint whether or not you understand them, and a misread interval is worse than none: “95% sure model B is better” is not what a 95% interval says.
Concepts from other sections (10)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Bits per character (bpc): mean negative log-likelihood in nats divided by . Read more: 9.6 RNN language model with stateful TBPTT in AI Engineering
- Law of large numbers: the sample mean converges to the true mean as grows. Read more: 13.5 LLN, CLT, confidence intervals, bootstrap
- Variance: the expected squared distance from the mean; its square root is the standard deviation. Read more: 13.1 Random variables, expectation, variance, and normal draws by Box-Muller
- Standard normal: the distribution with density . Read more: 13.1 Random variables, expectation, variance, and normal draws by Box-Muller
- Cumulative distribution function (CDF): , defined for every random variable, discrete or continuous; it rises from 0 to 1, and for a continuous variable its derivative is the density. Read more: Chapter 13: Probability and Statistics
- Standard deviation: , the typical distance of a random variable from its mean, in the same units as the variable itself. Read more: Chapter 13: Probability and Statistics
- Linearity of expectation: , which holds even when and are dependent; it is the main tool for analysing randomized algorithms, such as the coupon collector’s expected draws. Read more: Chapter 13: Probability and Statistics
- Covariance: , a measure of linear co-movement; zero does not imply independence. Read more: 13.10 Probability problem set, part b: joint distributions, covariance, MLE
- Nearest-rank quantile: the -th smallest value, here with a allowance for float rounding. Read more: 23.11 An open-loop load generator in AI Engineering
- p-value: the probability under the null of a statistic at least as extreme as the one observed. Read more: 13.6 Hypothesis tests: paired and two-sample permutation, McNemar, Holm
This problem set makes three ideas concrete by hand, so that the code becomes a transcription: why averaging works (the law of large numbers), why the error is normal and shrinks like (the central limit theorem), and what exactly an interval promises. It is a pen-and-paper set with 9 answers (counting lettered parts) and one proof. A short review and three examples by hand come first; then the problems, each followed by a collapsed worked answer with the final result, the derivation, and the common wrong answers and why they are wrong. Try each problem before opening its answer. Read it alongside the limit-theorems section: Problems 3, 6, 7, and 8 are its functions by hand, and Problem 5 is why its intervals shrink. Problem set D follows with hypothesis tests.
The set builds on the variance of a sum from problem set B and on the limit-theorem and inference material in the chapter opening.
Learning objectives
- Compute the mean and variance of a sample mean and explain why its error shrinks like .
- Derive Chebyshev’s inequality from Markov’s and use it to prove the weak law of large numbers.
- Approximate tail probabilities of sums with the central limit theorem.
- Compute Student t, Wilson, and type 7 percentile intervals by hand.
- State correctly what a 95% confidence interval does and does not promise.
Notation
Section titled “Notation”The set uses these symbols.
| Symbol | Meaning | Type / shape |
|---|---|---|
independent draws, each with mean and variance (mu, s2) | reals | |
| the sample mean | real | |
(eps) | a tolerance, | real |
| the standard normal CDF | function | |
| sample standard deviation, divisor | real | |
| Student’s t quantile with degrees of freedom | real | |
| successes, trials, , the normal quantile | integers, reals | |
| sorted bootstrap replicates | reals |
Averages
Section titled “Averages”Linearity of expectation gives . Independence makes every covariance in vanish (Problem 3 of set B), so the variance of the sum is , and dividing by divides the variance by : . The standard deviation of the mean is .
Chebyshev and the law of large numbers
Section titled “Chebyshev and the law of large numbers”That variance turns into a law in three lines. Markov’s inequality, for and , holds because . Applied to with it becomes Chebyshev’s inequality, . With the bound shrinks to 0 as grows: that is the weak law of large numbers.
The central limit theorem
Section titled “The central limit theorem”The law of large numbers says the error goes to zero; the central limit theorem says what shape it has on the way. For large , is approximately standard normal whatever the distribution of each . Equivalently, a sum is approximately normal with mean and variance , so .
Intervals
Section titled “Intervals”A 95% confidence interval is a procedure: data in, interval out, built so that over repeated samples 95% of the intervals contain the fixed, unknown . Once computed, a particular interval either contains or not; the 95% belongs to the procedure. The limit-theorems section implements three procedures.
- Student t: .
- Wilson for a proportion: .
- Percentile bootstrap: the type 7 quantiles at and of the replicates: , , value .
Three examples by hand
Section titled “Three examples by hand”These are siblings of Problems 3, 6, and 8, not problems of the set.
A CLT tail. Take 400 fair coin flips and ask for . The count has mean and variance , sd 10, so and the probability is about . Twenty extra heads out of 400 is as surprising as ten out of 100: the sd grows like , not .
A t interval. With , , , and , the half-width is , so the interval is .
A percentile interval. Take five replicates . For : , , value . For : , value . The 50% interval is .
The problems
Section titled “The problems” is written s2, is eps, and is mu. An interval is written , and exact fractions such as are kept exact. Lettered parts are answered separately, and the tag after each problem says what kind of answer is expected.
The law of large numbers and the CLT
Section titled “The law of large numbers and the CLT”The first five problems build from the variance of a mean to a full proof of the weak law.
Problem 1. are independent, each with mean and variance , and . (a) . [expr in mu] (b) . [expr in s2, n]
Answer
(a) . (b) (s2/n). (a) Linearity: ; averaging keeps the mean. (b) Independence removes every covariance, so , and the factor comes out squared: . Common mistakes: for (a), dividing once too often; for (b), the variance of one draw; , squaring the but forgetting the sum has terms; , the standard error, not the variance.
Problem 2. For the same and any , Chebyshev’s inequality bounds . Give the bound. [expr in s2, n, eps]
Answer
(s2/(n*eps^2)). Apply Chebyshev to , whose mean is and variance (Problem 1): . For fixed this goes to 0 as grows, which is the law of large numbers (Problem 5). Common mistakes: , the bound for one draw, which does not shrink; , with not squared.
Problem 3. You flip a fair coin 100 times. Using the central limit theorem without a continuity correction, and for the standard normal CDF, approximate . [number, 3 significant digits]
Answer
(). The number of heads has mean and variance , sd 5. The CLT treats it as normal: , and the one-sided tail is . Common mistakes: , the two-sided tail (“at least 60 or at most 40”) when only one side was asked; , the CDF instead of the tail.
Problem 4. A 95% interval for an eval score is . By what factor must grow to halve its width (with unchanged)? [number, exact]
Answer
. The half-width is , proportional to . Halving it needs , so . Common mistakes: 2, treating the width as proportional to ; 16, squaring twice.
Problem 5. Prove the weak law of large numbers for finite variance: if are independent with mean and variance , then for every , as . [proof]
Answer
Claim. If are independent, each with mean and finite variance , and , then for every , as .
Proof. Fix .
- Mean. By linearity, .
- Variance. Independent variables have zero covariances, so , and scaling by multiplies the variance by : . This is where is used: every term is a finite number.
- Chebyshev. For with finite variance, Markov’s inequality ( for , , because ) applied to and gives .
- Combine. With : .
- Limit. The right side is a constant times and tends to 0; probabilities are at least 0, so the left side tends to 0 too.
Hence in probability. A complete proof computes the mean and variance (using independence for the variance), states or derives Chebyshev, takes the limit for every fixed , and says where finite variance is used. The model proof is also in course/solutions/solve/S-M07c/q5.md.
Confidence intervals
Section titled “Confidence intervals”The last four problems compute each of the three intervals and then ask what one of them means.
Problem 6. An eval of prompts has mean score and sample standard deviation (divisor ). With , give the 95% Student t interval for the true mean. [interval, exact decimals]
Answer
. The standard error is , and the half-width is , so . Common mistakes: , using the normal 1.96 when is estimated from 25 points (Student’s t is wider to pay for that estimate); , multiplying by instead of .
Problem 7. A safety check fails on 0 of prompts. Give the Wilson score interval for the failure rate with :
[interval, exact]
Answer
. With , , : the centre term is , the root is , and the denominator is . Lower: . Upper: . Zero failures in ten trials still leave a failure rate up to about 29% plausible. Common mistakes: , the Wald interval , which claims certainty from ten trials; , dropping the denominator .
Problem 8. Nine bootstrap replicates of a statistic, sorted, are . With the type 7 quantile (for sorted and level : , , value ), give the 80% percentile interval . [interval, exact]
Answer
. . For : , , value . For : , , value . This is the rule numpy uses by default, so the Python and Go implementations of the limit-theorems section agree with it. Common mistakes: , taking without interpolating; , a nearest-rank rule.
Problem 9. From one sample you compute the 95% confidence interval for a mean . Which statement is correct? [choice]
(a) , with random.
(b) 95% of the observations lie in .
(c) The procedure that produced it covers the true in 95% of repeated samples.
(d) A new sample’s mean lands in with probability 0.95.
Answer
(c). The parameter is fixed; the interval is the random object. Before sampling, the procedure has a 95% chance of producing an interval that covers ; once is computed, it either contains or not. Common mistakes: (a), which treats as random and this one interval as carrying the 95%; (d), which confuses a confidence interval with a prediction interval for a new sample mean (a new mean is itself random and lands in the interval less often). (b) confuses the interval for the mean with the spread of the observations.
What can go wrong
Section titled “What can go wrong”The variance mistakes come first and propagate into everything else. Forgetting that is squared in a variance reports the variance of a mean as or ; the sum has variance , times (Problem 1b). Confusing the variance with the standard error puts where a variance is asked; report and keep the root for the interval (Problems 1b and 6). Applying Chebyshev to one draw instead of the mean gives a bound that does not shrink with ; apply it to , whose variance is (Problem 2). Answering a one-sided question with a two-sided tail gives 0.0455 instead of 0.02275; take once (Problem 3). And treating width as proportional to leads to “double the data, halve the bar”; width goes as , so it takes four times the data (Problem 4).
Warning: Using the normal 1.96 with an estimated at small gives intervals that are too narrow, and multiplying by without dividing by gives intervals 5 times too wide. Use times (Problem 6).
The interval-specific pitfalls are about procedure. The Wald interval at gives , certainty from ten trials; Wilson stays open at (Problem 7). Nearest-rank quantiles instead of interpolated ones produce a bootstrap interval that disagrees with numpy and Go; interpolate with type 7 (Problem 8). And reading the 95% as a probability about this one interval (“95% chance the mean is in here”) misattributes it; the 95% belongs to the procedure (Problem 9).
Where this leads
Section titled “Where this leads”The variance of a sum with covariances is Problem 3 of problem set B, and LLN, CLT, confidence intervals, bootstrap implements mean_ci, wilson_interval, quantile, and bootstrap_ci, which are Problems 6, 7, and 8 in code. Problem set D reads the same sampling distributions as p-values. In AI Engineering, The evaluation harness and the model zoo reports every metric with its interval, together with what the interval does and does not claim, and Sequence metrics: exact match, BLEU, chrF bootstraps intervals over sentences for BLEU.
Further reading
Section titled “Further reading”- Blitzstein and Hwang, Introduction to Probability (free), ch. 10 “Inequalities and limit theorems”.
- Wasserman, All of Statistics, ch. 5 to 8.
Key terms
Section titled “Key terms”- Standard error: , the standard deviation of a sample mean.
- Chebyshev’s inequality: , a distribution-free tail bound derived from Markov’s inequality.
- Weak law of large numbers: the sample mean converges in probability to the true mean.
- Central limit theorem: the standardized sample mean is approximately standard normal for large , whatever the distribution of each draw.
- Confidence interval: a procedure that, over repeated samples, produces intervals covering the fixed true parameter at the stated rate.
- Wilson interval: a confidence interval for a proportion that stays sensible at 0 or successes.
- Type 7 quantile: the linearly interpolated quantile with , numpy’s default.
Summary
Section titled “Summary”- The mean of independent draws has the same mean and of the variance, so its error shrinks like ; halving an error bar costs four times the data (Problems 1 and 4).
- Chebyshev’s inequality turns that variance into the weak law of large numbers in three lines (Problems 2 and 5).
- The central limit theorem lets a normal table answer questions about sums of non-normal variables, such as coin flips (Problem 3).
- A confidence interval is a statement about the procedure, not about one interval: 95% of the intervals it would produce cover the true value (Problem 9).
- Student’s t, Wilson, and the type 7 percentile rule are each a few lines of arithmetic, the same numbers the limit-theorems section computes (Problems 6, 7, and 8).