Statistics for ML: estimation, bias and variance, bootstrap, hypothesis tests

A child page of Topic: math. How much a number computed from data would move on another sample, and whether a difference is bigger than that: estimators, maximum likelihood, intervals, the bootstrap, tests and power, Bayesian estimation and regression, on the root's tiny model whose truth is known; every simulation seeded and every number recomputed. Reading: 33 min, plus 6 in closed details. Data as of October 2026.

The idea in one picture

Every number computed from data is one draw of a random variable. Statistics measures how far it would move on another sample of the same size (its standard error), and asks whether a difference is bigger than that wobble.

The running example is the one from Topic: math: a tiny language model whose bet for the word after "the cat" is p=(0.665,0.245,0.090)p = (0.665, 0.245, 0.090) over cat, dog, sat. Its average loss is its entropy, 0.832 nats, and here (unlike in real life) we know it exactly, so we can count how often each statistical tool recovers it. Fig. 1 is the whole page in five steps:

  1. The population. The tiny model's loss on one sampled word: 0.408, 1.408 or 2.408 nats with probabilities 0.665, 0.245 and 0.090, drawn as one strip whose widths are the probabilities and heights the losses; mean μ\mu = 0.832, standard deviation σ\sigma = 0.651.
  2. One sample of 30. Thirty words drawn from it (the first seeded sample of the page's simulation); dots flow from the strip into the row. Their average, 1.008, is one estimate of 0.832.
  3. Seven more samples. Each row is another 30 words, and each average lands as a dot on the value axis at the front. The eight run from 0.641 to 1.008: the estimate is itself a random variable.
  4. 20,000 samples. Their averages simulated build a bell centred on 0.832 whose width is 0.651/30\sqrt{30} = 0.119, the standard error. Three spikes for one word have become a bell for the average (section 4).
  5. What you actually have. One sample (22 cat, 5 dog, 3 sat; mean 0.775) and the 95% interval built from it alone, (0.525, 1.024), which here catches the truth. Every section below is one of these steps: estimators and the CLT explain step 4, the bootstrap measures it when no formula does (Fig. 6 repeats this picture with the sample in place of the population), intervals and tests read step 5.

simulated marks numbers from this page's seeded simulations (src/sims.py); exact marks numbers computed exactly.

You need: random variables, expectation and variance, the normal and Beta distributions, and Bayes' rule, from Probability for ML (its sections 1, 3 and 5). This page uses them without re-deriving them.

Estimator: a recipe from sample to guess, θˆ\hat\theta
Standard error: the standard deviation of an estimate over samples
Bias, variance, MSE: off-centre, scatter, and their sum
Fisher information: curvature of the log-likelihood; sets the MLE's error bar
Confidence interval: a procedure that catches the truth 95% of the time
Bootstrap: resample your sample to see the wobble
p-value: how surprising the data are if nothing is going on
Power: the chance a test detects a real effect
FWER, FDR: error rates for many tests at once
Credible interval, conjugate prior: the Bayesian versions
Idea (section)In one lineOn the running example
Estimators (1)judge a recipe by bias² + variance = MSE, not by bias aloneat n=5n = 5 the bias-corrected entropy estimate has the larger MSE
Maximum likelihood (2)the curvature of the log-likelihood is the error bar9 heads of 10: qˆ\hat q = 0.9, SE 0.0949
Why n−1n - 1 (3)spread around a fitted mean is too small by (n−1)/n(n-1)/ndivide-by-nn variance at n=5n = 5 averages 0.340, not 0.424
Central limit theorem (4)averages are nearly normal, width σ/n\sigma/\sqrt{n}at n=30n = 30 the average wobbles by 0.119
Confidence interval (5)a procedure, not a probability for this intervalt-interval at n=30n = 30 covers 0.832 in 92.7% of repeats
Bootstrap (6)resample the samplespread 0.122 against the true 0.119
Tests, power, A/B (7 to 9)how surprising under "no effect", and how often a real effect is found9 heads of 10: two-sided pp = 0.021
Bayesian estimation (10)a probability for the parameter itselfBayes factor 9.3 against "fair"
Regression (11)least squares is MLE; ridge is a Gaussian priorslope 0.81 ±\pm 0.33
Bounds, models, CV (12 to 14)guarantees at every nn; bias and variance of a fitted model; what CV estimatesnaive CV interval covered 85.8%

Where this page sits: the root gives the intuition in its section 6 ("Statistics: was the improvement real?"). Eval statistics owns statistics on real benchmarks: Wilson and Bayes intervals for small evals, clustered errors, paired tests on real model comparisons, and a sample-size calculator; each section below links its match there. Regularisation owns the bias-variance trade-off as a model-choice tool and double descent; this page keeps the bias and variance of an estimator (section 1).

1. Estimators: bias, variance and their sum

You computed a validation loss of 0.81 on 10 examples; a colleague, on 10 other examples from the same source, got 1.11. Both are honest. Ten sampled words, 7 cat, 2 dog and 1 sat, average (7×0.408+2×1.408+1×2.408)/10=0.808(7 \times 0.408 + 2 \times 1.408 + 1 \times 2.408)/10 = 0.808; ten more, 5 cat, 3 dog and 2 sat, average 1.108. exact The spread of such averages over many samples of 10 is σ/10=0.651/3.162=0.206\sigma/\sqrt{10} = 0.651/3.162 = 0.206, so a gap of 0.3 between two samples of 10 is ordinary.

The vocabulary, briefly: the population is everything you could have measured (here every word the model could sample; in ML, the inputs the model will meet in use) and a parameter is a fixed number describing it, such as μ=0.832\mu = 0.832; a sample is the nn values observed, usually assumed i.i.d. (independent draws from the same population); an estimator θˆ\hat\theta is a statistic (any number computed from the sample: its average, its largest value, its median) used as a recipe to turn the sample into a guess of a parameter θ\theta, and the estimate is what it gives on one sample. Over all the samples you might have drawn, the estimate has a sampling distribution; its standard deviation is the standard error.

When i.i.d. fails (near-duplicate test items, several items cut from one document, leaked test data, users in both train and test), the draws carry less information than their count suggests and every error bar computed as if they were independent is too narrow (clustered standard errors: section 3 of Eval statistics). The test set is a sample from deployment; the trained weights are an estimate; so is every metric you report; keeping train and test samples apart is what makes a test score an honest estimate.

What makes an estimator good. Think of darts at a bullseye θ\theta, one throw per sample. The throws can be centred off the bullseye (bias) or scattered (variance); the mean squared error counts both:

Bias⁡(θˆ)=𝔼[θˆ]−θ,Var⁡(θˆ)=𝔼[(θˆ−𝔼θˆ)2],MSE⁡(θˆ)=𝔼[(θˆ−θ)2]=Bias2⁡+Var⁡.\operatorname{Bias}(\hat\theta) = \mathbb{E}[\hat\theta] - \theta, \qquad \operatorname{Var}(\hat\theta) = \mathbb{E}\big[(\hat\theta - \mathbb{E}\hat\theta)^2\big], \qquad \operatorname{MSE}(\hat\theta) = \mathbb{E}\big[(\hat\theta - \theta)^2\big] = \operatorname{Bias}^2 + \operatorname{Var}.

So being unbiased is not the goal; being close is. Estimate μ=1\mu = 1 from n=4n = 4 samples of variance 4: the sample mean is unbiased with MSE 4/4=14/4 = 1; the shrunk estimate 0.5x‾0.5\,\bar{x} has bias −0.5-0.5 and variance 0.25, so MSE 0.25+0.25=0.50.25 + 0.25 = 0.5, half the error. exact When three or more means are estimated together, a data-driven shrinkage beats the plain sample means in total MSE whatever the true means are (James and Stein 1961); weight decay and a prior towards zero (Probability for ML, section 9) are the same trade.

Derivations: MSE = bias² + variance, and the best shrinkage factor (depth)
  1. Write m=𝔼[θˆ]m = \mathbb{E}[\hat\theta] and split θˆ−θ=(θˆ−m)+(m−θ)\hat\theta - \theta = (\hat\theta - m) + (m - \theta). Squaring gives (θˆ−m)2+2(θˆ−m)(m−θ)+(m−θ)2(\hat\theta - m)^2 + 2(\hat\theta - m)(m - \theta) + (m - \theta)^2.
  2. In expectation the first term is the variance; in the middle term m−θm - \theta is a fixed number, so 𝔼[2(θˆ−m)(m−θ)]=2(m−θ)(m−m)=0\mathbb{E}[2(\hat\theta - m)(m - \theta)] = 2(m - \theta)(m - m) = 0; the last term is Bias2⁡\operatorname{Bias}^2. So MSE⁡=Var⁡+0+Bias2⁡\operatorname{MSE} = \operatorname{Var} + 0 + \operatorname{Bias}^2.
  3. Shrinkage: MSE⁡(cx‾)=(c−1)2μ2+c2σ2/n\operatorname{MSE}(c\bar{x}) = (c - 1)^2\mu^2 + c^2\sigma^2/n. Setting the derivative 2(c−1)μ2+2cσ2/n2(c - 1)\mu^2 + 2c\,\sigma^2/n to zero gives c∗=μ2/(μ2+σ2/n)=1/(1+1)=0.5c^\ast = \mu^2/(\mu^2 + \sigma^2/n) = 1/(1 + 1) = 0.5 here, so 0.5 is also the best factor. The catch: c∗c^\ast depends on the unknown μ\mu, which is why James-Stein's data-driven version matters. (No noise term appears because the target is the fixed number μ\mu.)
  4. Consistent means the estimate converges to the truth as n→∞n \to \infty (P(|θˆn−θ|>ϵ)→0P(|\hat\theta_n - \theta| > \epsilon) \to 0 for every ϵ>0\epsilon > 0). If bias and variance both go to 0 then MSE⁡→0\operatorname{MSE} \to 0, and by Chebyshev's inequality (section 12) P(|θˆn−θ|>ϵ)≤MSE⁡/ϵ2P(|\hat\theta_n - \theta| > \epsilon) \le \operatorname{MSE}/\epsilon^2, so the estimator is consistent.

Three estimators of the same entropy

The tiny model's entropy (0.832 nats) can be estimated from nn sampled words in three ways: Monte Carlo averages −ln⁡p(word)-\ln p(\text{word}) and needs the model's probabilities; plug-in counts the words and computes the entropy of the frequencies pˆ\hat p, needing only samples (how entropy and mutual information of data are usually estimated); Miller-Madow adds (m−1)/(2n)(m - 1)/(2n) to the plug-in, with mm the number of distinct words seen, a first-order bias correction (Miller 1955; Paninski 2003, Neural Computation 15, section 3). Predict before you look: which has the smallest error at n=5n = 5?

The exact table behind the figure (reference)
nnEstimatorMeanBiasVarianceMSE
5Monte Carlo0.83200.08490.0849
Plug-in0.608-0.2240.09260.1428
Miller-Madow0.721-0.1110.13210.1446
10Monte Carlo0.83200.04240.0424
Plug-in0.718-0.1140.05090.0639
Miller-Madow0.796-0.03650.06150.0629
30Monte Carlo0.83200.01410.0141
Plug-in0.797-0.03560.01570.0169
Miller-Madow0.829-0.00320.01610.0161
100Monte Carlo0.83200.00420.0042
Plug-in0.822-0.01010.00440.0045
Miller-Madow0.832-0.00010.00440.0044

Estimating the entropy of a large vocabulary from few samples is where this bias bites (Paninski 2003).

In ML: when a paper calls a new estimator (of a gradient, a mutual information, a KL, a policy value) "unbiased" or "lower variance", compare MSE at your sample size; REINFORCE against the reparameterised gradient (Probability for ML, section 11), policy-gradient baselines and importance-sampling corrections are all this trade.

The bias correction removes bias but adds variance: at n=5n = 5 it loses

Each bar is one estimator's MSE, split into bias² and variance; each panel has its own scale. Exact: every possible set of counts, weighted by its multinomial probability. exact The plug-in is always biased low (a small sample looks more predictable than the population; at n=10n = 10 its bias is −0.114-0.114, close to the first-order −(K−1)/(2n)=−2/20=−0.1-(K - 1)/(2n) = -2/20 = -0.1 for K=3K = 3 words). Miller-Madow removes most of the bias, yet at n=5n = 5 its MSE (0.1446) is slightly worse than the plug-in's (0.1428). By n=100n = 100 all three agree to 0.01: all are consistent.

2. Maximum likelihood, read as an estimator

Probability for ML (section 7) derives the maximum-likelihood estimate (the parameters that make the observed data most probable) and shows that minimising cross-entropy is exactly that. The statistician's questions are different: how good is the MLE as an estimator, and where does its error bar come from?

A worked example. Sample 30 words from the tiny model and get 22 cat, 5 dog, 3 sat. The MLE of the probabilities is the frequencies, pˆ=(0.733,0.167,0.100)\hat p = (0.733, 0.167, 0.100), against the truth (0.665,0.245,0.090)(0.665, 0.245, 0.090). The MLE of any function of the parameters is that function of the MLE (invariance), so the MLE of the entropy is the plug-in estimate of section 1, 0.756 here. That is why the plug-in is biased low: the MLE is consistent and, for large nn, as precise as any unbiased estimator can be, but it is not unbiased.

The error bar is the curvature. For large nn the MLE is approximately normal around the truth,

θˆ≈𝒩(θ, 1nI(θ)),I(θ)=−𝔼[∂2∂θ2ln⁡p(x|θ)],SEˆ=(−∂2ℓ∂θ2|θˆ)−1/2,\hat\theta \approx \mathcal{N}\!\Big(\theta,\ \frac{1}{n\,I(\theta)}\Big), \qquad I(\theta) = -\mathbb{E}\Big[\frac{\partial^2}{\partial\theta^2}\ln p(x \mid \theta)\Big], \qquad \widehat{\mathrm{SE}} = \Big(-\frac{\partial^2 \ell}{\partial\theta^2}\Big|_{\hat\theta}\Big)^{-1/2},

where ℓ\ell is the log-likelihood of the whole sample and II is the Fisher information of one observation (equivalently the variance of the score, the slope of the log-likelihood). A sharply curved log-likelihood pins the parameter down; a flat one does not. For a coin with 9 heads in 10, ℓ(q)=9ln⁡q+ln⁡(1−q)\ell(q) = 9\ln q + \ln(1 - q), qˆ=0.9\hat q = 0.9, the curvature at qˆ\hat q is n/(qˆ(1−qˆ))=111.1n/(\hat q(1 - \hat q)) = 111.1, so the standard error is 1/111.1=0.09491/\sqrt{111.1} = 0.0949. exact

Efficiency. No unbiased estimator can beat the Cramér-Rao bound Var⁡(θˆ)≥1/(nI(θ))\operatorname{Var}(\hat\theta) \ge 1/(n\,I(\theta)). For a coin I=1/(q(1−q))I = 1/(q(1 - q)), so the bound is q(1−q)/nq(1 - q)/n: exactly the variance of the observed fraction of heads, which is therefore efficient. The MLE reaches the bound as n→∞n \to \infty (Wasserman, All of Statistics, chapter 9). For the 30-word sample the standard error of pˆcat\hat p_{\text{cat}} is 0.733×0.267/30=0.0807\sqrt{0.733 \times 0.267/30} = 0.0807.

The Fisher information is also the curvature the root page reads three ways ("same object in different hats").

A sharper peak is a smaller error bar, and at small nn the peak is not a parabola

The solid curve is the log-likelihood minus its maximum; the dashed parabola is the normal approximation with the same curvature, whose 95% interval qˆ±1.96SEˆ\hat q \pm 1.96\,\widehat{\mathrm{SE}} is the bracket. Predict, then switch: does the parabola fit better or worse as nn grows? At 9 of 10 the parabola is symmetric while the curve is not, and its interval (0.714, 1.086) runs past 1, an impossible heads probability. At 90 of 100 (SE 0.030) and 900 of 1,000 (SE 0.0095) the two agree: this is the asymptotic normality above, visible. Near a boundary at small nn, use Wilson or Bayes intervals instead (section 1 of Eval statistics).

3. The sample variance: why divide by n−1n - 1

The sample mean x‾\bar{x} is unbiased for μ\mu (linearity of expectation) with variance σ2/n\sigma^2/n (variances of independent draws add, then dividing by nn divides the variance by n2n^2), so its standard error is σ/n\sigma/\sqrt{n}. The spread is harder: the average squared distance from x‾\bar x is too small, because x‾\bar x was fitted to these very points.

𝔼[∑i=1n(xi−x‾)2]=(n−1)σ2,s2=1n−1∑i=1n(xi−x‾)2,𝔼[s2]=σ2.\mathbb{E}\Big[\sum_{i=1}^{n}(x_i - \bar x)^2\Big] = (n - 1)\sigma^2, \qquad s^2 = \frac{1}{n - 1}\sum_{i=1}^{n}(x_i - \bar x)^2, \qquad \mathbb{E}[s^2] = \sigma^2.

Estimating the mean from the same data uses up one of the nn pieces of information: the deviations xi−x‾x_i - \bar x add to zero, so only n−1n - 1 are free (the degrees of freedom). Dividing by n−1n - 1 (Bessel's correction) pays it back. For the eight numbers: divide-by-nn variance 32/8=432/8 = 4 (the MLE), divide-by-(n−1)(n-1) 32/7=4.57132/7 = 4.571, so s=2.138s = 2.138. On the tiny model (population variance 0.424) the divide-by-nn variance at n=5n = 5 averages 45×0.424=0.340\frac45 \times 0.424 = 0.340, a 20% underestimate. exact

Derivation of (n−1)σ2(n - 1)\sigma^2, and two fine points (depth)
  1. Expand, using ∑ixi=nx‾\sum_i x_i = n\bar x:
    ∑i(xi−x‾)2=∑ixi2−2x‾∑ixi+nx‾2=∑ixi2−nx‾2.\sum_i (x_i - \bar x)^2 = \sum_i x_i^2 - 2\bar x \sum_i x_i + n\bar x^2 = \sum_i x_i^2 - n\bar x^2.
  2. For any random variable 𝔼[Y2]=Var⁡(Y)+(𝔼Y)2\mathbb{E}[Y^2] = \operatorname{Var}(Y) + (\mathbb{E}Y)^2, so 𝔼[xi2]=σ2+μ2\mathbb{E}[x_i^2] = \sigma^2 + \mu^2 and 𝔼[x‾2]=σ2/n+μ2\mathbb{E}[\bar x^2] = \sigma^2/n + \mu^2.
  3. So
    𝔼[∑ixi2−nx‾2]=n(σ2+μ2)−n(σ2n+μ2),\mathbb{E}\Big[\sum_i x_i^2 - n\bar x^2\Big] = n(\sigma^2 + \mu^2) - n\Big(\frac{\sigma^2}{n} + \mu^2\Big),
    which is nσ2−σ2=(n−1)σ2n\sigma^2 - \sigma^2 = (n - 1)\sigma^2: dividing by nn gives n−1nσ2\frac{n-1}{n}\sigma^2, dividing by n−1n - 1 gives σ2\sigma^2.

First fine point: ss itself is still biased low for σ\sigma, because the square root is concave (Jensen's inequality); for normal data with n=2n = 2, 𝔼[s]=0.798σ\mathbb{E}[s] = 0.798\,\sigma. Nobody corrects this in practice; the t-distribution of section 5 absorbs it. Second: unbiased is not best in MSE; for normal data dividing by n+1n + 1 gives the smallest MSE of all divisors (a standard exercise; the shrinkage of section 1 again).

What the libraries do, a classic port bug: NumPy's np.var divides by nn unless you pass ddof=1; PyTorch's torch.var defaults to correction=1 ("Defaults to Bessel's correction", v2.14.1 source); pandas' .var() divides by n−1n - 1. BatchNorm uses both. Pass ddof or correction explicitly.

BatchNorm's two variances, and Adam's bias correction (depth)

BatchNorm: "At train time in the forward pass, the standard-deviation is calculated via the biased estimator, equivalent to torch.var(input, correction=0). However, the value stored in the moving average of the standard-deviation is calculated via the unbiased estimator" (PyTorch v2.14.1, torch/nn/modules/batchnorm.py, saved in src/inputs/). Adam's bias correction of its second-moment estimate is the same family of idea (a running estimate corrected for how it was started; Optimisers and learning-rate schedulers).

The fitted mean is the centre that makes the squared deviations smallest, so they understate the spread

For the eight numbers (2,4,4,4,5,5,7,9)(2, 4, 4, 4, 5, 5, 7, 9) (the same as Probability for ML, section 7), the sum of squared deviations from a centre cc is 32+8(c−5)232 + 8(c - 5)^2. It bottoms out at c=x‾=5c = \bar x = 5; any other centre, including the unknown true mean, gives more. On average the shortfall is exactly one σ2\sigma^2.

Skew slows the bell; infinite variance stops it

Bars: the distribution of the sample mean over 20,000 simulated samples per setting simulated; line: the normal curve the CLT predicts; green: the true mean. The four numbers under it are for the nn shown.

4. Where the central limit theorem holds, and where it fails

Probability for ML (section 4) states and simulates the two theorems: the law of large numbers (an average of i.i.d. draws converges to μ\mu) and the central limit theorem (for finite variance the average is close to 𝒩(μ,σ2/n)\mathcal{N}(\mu, \sigma^2/n) whatever the shape of one draw, so four times the samples halve the error). This section keeps what a statistician needs from them: the numbers that set error bars, and where the bell fails. An accuracy is a mean of 0/1 scores; at accuracy 0.5 one score has σ=0.5\sigma = 0.5, so the standard error is 0.25/500=0.022\sqrt{0.25/500} = 0.022 on 500 examples and 0.25/2000=0.011\sqrt{0.25/2000} = 0.011 on 2,000. On the tiny model an average of 30 losses has standard error 0.651/30=0.1190.651/\sqrt{30} = 0.119 and a 95% half-width of 1.96×0.119=0.2331.96 \times 0.119 = 0.233, although one draw is skewed (skewness 1.26: a long right tail from the rare "sat"). exact

Fig. 4 steps nn from 1 to 1,000 for four populations. Predict first: by n=30n = 30, which of them look like a bell? The tiny model's three spikes blur into one by n=30n = 30, the lognormal stays lopsided much longer, and the Pareto never settles.

  1. n = 1. One draw is the population: three spikes at 0.408, 1.408 and 2.408 nats, lopsided to the right. The black curve is the normal with the same mean and standard deviation, and it fits badly.
  2. n = 2. Averages of two words take only six values: still lumpy.
  3. n = 5. The spikes start to merge; the right tail from the rare "sat" remains (skewness 0.56).
  4. n = 30. Close to the bell: skewness 0.25, and 95.1% of the means fall within ±1.96\pm 1.96 standard errors.
  5. n = 100. Skewness 0.12, and the bell is 100/30\sqrt{100/30} times narrower than at 30.
  6. n = 1,000. The bars sit on the normal curve; the t-interval built from each sample covers the truth in 94.9% of them.

Two things slow the approach: skew (the skewness of a mean is that of one draw divided by n\sqrt{n}, so a lognormal's 6.18 needs nn in the hundreds to fade) and heavy tails. With infinite variance the theorem does not apply: averages of a Pareto with tail index 1.5 never settle into a bell and their spread shrinks more slowly than 1/n1/\sqrt{n}. For skewed means use the t multiplier (section 5), the BCa bootstrap (section 6) or a transform; when the variance may be infinite (losses on rare tokens, heavy-tailed rewards, latencies) report medians, quantiles or trimmed means rather than a mean with a normal error bar. The same 1/B1/\sqrt{B} law sets the noise of a minibatch gradient (Calculus and optimisation for ML, section 10) and of Monte Carlo estimates (Probability for ML, section 4).

The LLN in one line, and how fast the CLT arrives: Berry-Esseen (depth)

With finite variance the LLN is one line: X‾n\bar X_n has variance σ2/n\sigma^2/n, so by Chebyshev (section 12) P(|X‾n−μ|≥ϵ)≤σ2/(nϵ2)→0P(|\bar X_n - \mu| \ge \epsilon) \le \sigma^2/(n\epsilon^2) \to 0. Formally the CLT says (X‾n−μ)/(σ/n)(\bar X_n - \mu)/(\sigma/\sqrt{n}) converges in distribution to 𝒩(0,1)\mathcal{N}(0,1): the probability of landing in any interval approaches the normal one, and 95% of 𝒩(0,1)\mathcal{N}(0,1) lies within ±1.96\pm 1.96.

The largest gap between the distribution function of the standardised mean and the normal one is at most Cρ/(σ3n)C\rho/(\sigma^3\sqrt{n}), with ρ=𝔼|X−μ|3\rho = \mathbb{E}|X - \mu|^3 and C<0.4748C < 0.4748 (Shevtsova 2011, arXiv 1111.6554). When 0/1 scores are few (an AIME paper has 15 items) the normal approximation fails near 0% and 100%; exact coverage of Wald, Wilson, Clopper-Pearson and Bayes intervals is in section 1 of Eval statistics.

The promise is about the procedure: skewed small samples break it, all on one side

Each row is one experiment: nn draws, their mean (dot) and 95% interval (line); the vertical line is the truth; grey intervals catch it, orange ones miss. simulated, seeded; long-run rates from 5,000 repetitions (every combination is in the CI and test lab).

5. Confidence intervals: what 95% does and does not mean

Turn the CLT around: if x‾\bar x is within 1.96 standard errors of μ\mu in 95% of samples, then x‾±1.96SE\bar x \pm 1.96\,\mathrm{SE} contains μ\mu in 95% of samples. We do not know σ\sigma, so we plug in ss and pay with a wider multiplier, the 97.5% point of Student's t-distribution with n−1n - 1 degrees of freedom, which has heavier tails than the normal and approaches 1.96 as nn grows (exact for normal data; Gosset, writing as "Student", Biometrika 1908):

x‾±tn−1,0.975sn,t29,0.975=2.045,t4,0.975=2.776,z0.975=1.96.\bar x \pm t_{n-1,\,0.975}\,\frac{s}{\sqrt{n}}, \qquad t_{29,\,0.975} = 2.045, \quad t_{4,\,0.975} = 2.776, \quad z_{0.975} = 1.96.

For the eight numbers of section 3: SE =2.138/8=0.756= 2.138/\sqrt{8} = 0.756, t7,0.975=2.365t_{7,\,0.975} = 2.365, interval 5±1.788=(3.21,6.79)5 \pm 1.788 = (3.21, 6.79). For an accuracy near 0.5 on 500 questions: SE 0.022, half-width 0.044 with 1.96 and 0.045 with "2 standard errors"; pick one multiplier and say which. exact

Fig. 5 runs one experiment 100 times, in six stretches, and draws every interval. Pick a population on the figure; the step list follows it.

  1. The set-up. Bell-shaped data with mean 0.832 and standard deviation 0.651. Each experiment draws n=30n = 30 values and builds x‾±2.045s/30\bar x \pm 2.045\,s/\sqrt{30} (or 1.96, with the other button).
  2. Experiment 1. Its 30 draws (dots at the top), their mean (bar) and its interval (the first row) catch the truth (green line). From inside one experiment you cannot tell whether yours did.
  3. Experiments 2 to 10. The intervals jump around; the truth never moves. 9 of 10 catch it.
  4. To 25. 23 of 25.
  5. To 50. 46 of 50.
  6. All 100. 95 of 100 caught the truth with t (93 with 1.96); over 5,000 repetitions the t procedure covers 94.8%. That is what "95% confident" promises: a rate for the procedure, with misses on both sides in the long run.
What a 95% confidence interval means, and three things it does not

It means: the procedure catches the true value in 95% of repetitions of the whole experiment.

It does not mean (1) "a 95% probability that μ\mu is in this interval": μ\mu is fixed and this interval either contains it or not (that is a Bayesian credible interval, section 10); (2) "95% of the data lie inside": that is a much wider prediction interval; (3) "a repeat will land inside with 95% probability": for a normal mean with known σ\sigma, a replication's mean lands inside the original interval only 2Φ(1.96/2)−1=83.4%2\Phi(1.96/\sqrt{2}) - 1 = 83.4\% of the time on average, because both estimates wobble (Cumming and Maillardet 2006, Psychological Methods 11).

Do not compare intervals by overlap. Two equal-width 95% intervals fail to overlap only when the estimates differ by 2×1.96=3.922 \times 1.96 = 3.92 standard errors, but the difference is significant at 5% already at 1.962=2.771.96\sqrt{2} = 2.77 (the difference of independent estimates has standard error 2\sqrt 2 times one). Overlap does not mean "not significant", and non-overlap corresponds to p≈0.0056p \approx 0.0056 (Schenker and Gentleman, The American Statistician 55, 2001). For paired data overlap is even less informative: test the per-example differences (section 8).

Corrected from the old notes
The old page gave the unpaired error bar of a 1-point gap on 500 examples as "about ±6.3\pm 6.3 points" while computing the paired one with 1.96. With 1.96 throughout, the unpaired half-width is 1.96×2×0.25/500=1.96×0.0316=0.0621.96 \times \sqrt{2 \times 0.25/500} = 1.96 \times 0.0316 = 0.062, so ±6.2\pm 6.2 points (6.3 is the 2-standard-error figure). Its "±0.045\pm 0.045" for one score uses 2 standard errors; 1.96 gives 0.044. Both are now stated with their multiplier (section 8 has the paired comparison).

Report the interval, the nn and how it was computed. Intervals for 0/1 eval scores, the variance split between items, samples and judges, and a real comparison worked through every interval are sections 1 and 2 and the Interval lab of Eval statistics.

6. The bootstrap: resample your sample

σ/n\sigma/\sqrt{n} is for means. What is the error bar on a median, an F1 score, a ratio of losses, a pass@k curve, or the entropy estimate of section 1? The ideal is to draw many fresh samples and watch the statistic vary; we have one sample. Efron's bootstrap (Annals of Statistics 7, 1979) treats the sample as the population: draw nn points with replacement from your nn (some twice, some not at all), recompute the statistic, repeat BB times (a few thousand). The spread of the BB values estimates the standard error; their percentiles give an interval.

θˆb∗=s(xb,1∗,…,xb,n∗),xb,i∗ drawn uniformly from {x1,…,xn},SEˆboot=sd⁡(θˆ1∗,…,θˆB∗),\hat\theta^{*}_b = s\big(x^{*}_{b,1}, \dots, x^{*}_{b,n}\big), \quad x^{*}_{b,i} \text{ drawn uniformly from } \{x_1, \dots, x_n\}, \qquad \widehat{\mathrm{SE}}_{\text{boot}} = \operatorname{sd}\big(\hat\theta^{*}_1, \dots, \hat\theta^{*}_B\big),

with s(⋅)s(\cdot) any recipe computed the same way on the resample, and a star marking a bootstrap quantity. It works because the resample is to the sample what the sample is to the population: if the statistic's wobble depends on the population only through features the sample reproduces well (centre, spread and shape, for smooth statistics), the two wobbles match. Each resample leaves out (1−1/n)n(1 - 1/n)^n of the points on average: 36.2% at n=30n = 30, tending to e−1=36.8%e^{-1} = 36.8\%.

  1. One sample. The 30 words of the hero's last step (22 cat, 5 dog, 3 sat), mean 0.775. This is all we have.
  2. Resample 1. Thirty slots, each a copy of a point picked at random from the sample, with replacement; dots flow from each picked point. 11 of the 30 points were never picked (they fade) and some were picked two or three times: on average 36.2% are left out at n=30n = 30. This resample's mean is 0.741.
  3. Five more resamples. Means 0.641, 0.775, 0.875, 0.875 and 0.808 (drawn here with a fixed seed), landing on the value axis. They scatter around the sample's 0.775, not around the truth.
  4. 4,000 resamples. Their means form the bootstrap distribution simulated. Its spread, 0.122, is the bootstrap standard error.
  5. The truth beside it. The means of 20,000 fresh samples from the population (orange glass; impossible in practice) spread 0.119. The bootstrap got the wobble right without ever seeing the population; it did not move the centre, which stays at the sample's 0.775.

Truth: 20,000 fresh samples from the population (impossible in practice). Bootstrap: 4,000 resamples of one sample. simulated On the tiny model at n=30n = 30 they agree: bootstrap spread 0.122 against the true 0.119. On a lognormal at n=10n = 10 the one sample happened to contain no large value (its ss is 0.70 against a population σ\sigma of 2.16), so the bootstrap thinks the spread is 0.21 when it is 0.70. The six resamples drawn in Fig. 6 come from src/mk_stage.py (seed 2026); the 4,000 and the 20,000 from src/sims.py.

From resamples to an interval. The percentile interval takes the 2.5th and 97.5th percentiles of the θˆ∗\hat\theta^*: simple, never leaves the range of possible values, but inherits any bias and narrowness of the bootstrap distribution. BCa (bias-corrected and accelerated; Efron, JASA 82, 1987) shifts those percentiles to correct for median bias and for skew, and its coverage error shrinks like 1/n1/n rather than 1/n1/\sqrt{n} (Efron and Tibshirani, An Introduction to the Bootstrap, 1993, chapters 14 and 22). Over 5,000 repetitions on the lognormal at n=30n = 30, coverage is 88.6% (t), 88.3% (percentile) and 89.4% (BCa): BCa helps, but nothing reaches 95% there. simulated

When it struggles. Small nn: at n=5n = 5 from a normal population the percentile interval covers only 83.0% (t: 94.9%), because a resample's spread is the divide-by-nn spread with no t-correction. Heavy symmetric tails: on a t-distribution with 3 degrees of freedom at n=10n = 10, BCa covers 86.4% against t's 95.9%, because one outlier swings the jackknife acceleration. Extremes (the maximum) and dependent data (time series, items in clusters) need other schemes: the mm-out-of-nn bootstrap, block or cluster resampling.

The paired bootstrap. To compare models A and B scored on the same examples, resample examples, keeping each example's pair of scores together, and compute A minus B on each resample. The spread of those differences is the uncertainty of the delta, and the fraction of resamples in which A wins says how often the ordering survives. Keeping the pair together keeps each example's shared difficulty in both columns, so it cancels. It is the robust default for LLM evals with a few hundred to a few thousand examples (Koehn 2004 popularised it for machine translation); the paired and cluster bootstrap on real model comparisons are sections 4 and 5 of Eval statistics. Bagging (train on resamples and average: variance reduction; ensembles are on Regularisation, section 1) and the out-of-bag error of random forests (the 36.8% left out are a free validation set) are the same resampling.

The three intervals on the two samples, BCa's formulas, bootstrap bias correction, and how many resamples exist (depth)

The intervals. On the n=30n = 30 sample above (22 cat, 5 dog, 3 sat; mean 0.775; truth 0.832): t-interval (0.525, 1.024), percentile (0.541, 1.041), BCa (0.575, 1.108), shifted right because the population's tail is to the right. Lognormal, n=10n = 10 (truth 1.649): t (0.668, 1.665) just catches it, percentile (0.792, 1.598) misses, BCa (0.848, 1.756) catches it. simulated

BCa uses shifted percentiles α1,α2\alpha_1, \alpha_2 instead of 2.5% and 97.5%:

α1=Φ(zˆ0+zˆ0+z0.0251−aˆ(zˆ0+z0.025)),\alpha_1 = \Phi\!\Big(\hat z_0 + \frac{\hat z_0 + z_{0.025}}{1 - \hat a(\hat z_0 + z_{0.025})}\Big),
zˆ0=Φ−1(#{θˆb∗<θˆ}B),\hat z_0 = \Phi^{-1}\!\Big(\frac{\#\{\hat\theta^*_b < \hat\theta\}}{B}\Big),
aˆ=∑i(θ‾(⋅)−θˆ(i))36[∑i(θ‾(⋅)−θˆ(i))2]3/2,\hat a = \frac{\sum_i (\bar\theta_{(\cdot)} - \hat\theta_{(i)})^3}{6\big[\sum_i (\bar\theta_{(\cdot)} - \hat\theta_{(i)})^2\big]^{3/2}},

and α2\alpha_2 the same with z0.975z_{0.975}. zˆ0\hat z_0 measures the median bias of the bootstrap distribution (0 if half the resamples fall below θˆ\hat\theta); θˆ(i)\hat\theta_{(i)} is the statistic with point ii left out (the jackknife) and θ‾(⋅)\bar\theta_{(\cdot)} their average; aˆ\hat a, the acceleration, measures how the standard error changes with the parameter, which is what skew does.

Bias. The bootstrap estimates bias as the average of θˆ∗\hat\theta^* minus θˆ\hat\theta. On the tiny-model sample the plug-in entropy is 0.756; the resamples average 0.718, so the estimated bias is −0.039-0.039 (the exact bias at n=30n = 30 is −0.036-0.036, section 1), and the corrected estimate is 2×0.756−0.718=0.7952 \times 0.756 - 0.718 = 0.795.

Counting. There are (2n−1n)\binom{2n-1}{n} distinct resamples (10 at n=3n = 3; about 5.9×10165.9 \times 10^{16} at n=30n = 30), so we sample them rather than list them.

7. Tests, p-values, power, and A/B tests

A coin lands heads 9 times in 10. Biased, or a fair coin that got lucky? Every "B beats A" is the same question. A test is a proof by near-contradiction: state a null hypothesis H0H_0 (no effect: the coin is fair), choose a test statistic that grows with evidence against it (heads far from 5), work out its distribution if H0H_0 were true, and ask how surprising the observed value is. The p-value is the probability, under H0H_0, of a result at least as extreme as the one observed.

Reject H0H_0 when p<αp < \alpha, the significance level (conventionally 0.05). Two mistakes are possible: a Type I error (false positive; rate α\alpha when H0H_0 is true) and a Type II error (false negative; rate β\beta when there is a real effect). Power 1−β1 - \beta is how often a real effect is found; you set α\alpha, while power depends on the effect size, the noise and nn. A two-sided test at level α\alpha rejects "θ=θ0\theta = \theta_0" exactly when θ0\theta_0 lies outside the (1−α)(1 - \alpha) confidence interval built from the same statistic, which is why the CI and test lab computes power from intervals.

The p-value is the tail mass of the null distribution beyond what you saw

Heads in 10 flips of a fair coin, exact. P(≥9)=((109)+(1010))/210=11/1024=0.011P(\ge 9) = (\binom{10}{9} + \binom{10}{10})/2^{10} = 11/1024 = 0.011; counting the equally extreme "at most 1 head" too gives the two-sided p=22/1024=0.021p = 22/1024 = 0.021. exact

Power and sample size. For a two-sided z-test of a mean shift δ\delta with noise σ\sigma, power 1−β1 - \beta needs

n=((z1−α/2+z1−β)σδ)2.n = \Big(\frac{(z_{1-\alpha/2} + z_{1-\beta})\,\sigma}{\delta}\Big)^2.

A/B tests. An online A/B test is this test on two proportions with each user randomised to one arm. To detect a lift from a 10% to an 11% conversion rate at α=0.05\alpha = 0.05 with 80% power, each arm needs

n=(z0.975+z0.8)2[p1(1−p1)+p2(1−p2)](p2−p1)2=7.849×(0.09+0.0979)0.012,n = \frac{(z_{0.975} + z_{0.8})^2\,[p_1(1 - p_1) + p_2(1 - p_2)]}{(p_2 - p_1)^2} = \frac{7.849 \times (0.09 + 0.0979)}{0.01^2},
so 14,749 users per arm; a half-point lift needs 57,760. exact (derived from the formula; sample sizes are rounded up). Small lifts on low base rates are expensive. Running them in production: Production eval engineering; as explore-then-commit: Bandits and exploration; for evals, with a calculator: section 7 of Eval statistics.

Peeking breaks the test. Testing as the data arrive and stopping at the first "significant" result makes each look another test. Our simulation: 200,000 runs with no real effect, up to 100 observations, a z-test at 5% after every kk-th observation, stopping at the first rejection. simulated

Ten looks almost quadruple the nominal 5% (19.4%); checking after every observation gives 37.6%. Armitage, McPherson and Rowe (JRSS A 132, 1969) worked this out for repeated significance tests (their tables are not re-fetched here). Fixes: decide nn in advance; use a sequential design whose boundaries spend α\alpha across looks (Pocock, O'Brien-Fleming); or use always-valid sequential tests. A dashboard with a live p-value invites exactly this mistake.

What a p-value is not

The American Statistical Association's 2016 statement (Wasserstein and Lazar, The American Statistician 70; principles quoted from the ASA's release, saved in src/inputs/) lists six principles; three are about misreadings: "2. P-values do not measure the probability that the studied hypothesis is true, or the probability that the data were produced by random chance alone." "5. A p-value, or statistical significance, does not measure the size of an effect or the importance of a result." "6. By itself, a p-value does not provide a good measure of evidence regarding a model or hypothesis."

So p=0.021p = 0.021 is not "a 2.1% chance the coin is fair" (that needs a prior; section 10 computes 9.7% under even prior odds), and 1−p1 - p is not the probability the effect is real. A large pp is not evidence of no effect: a test with low power usually fails to reject a real effect (30 observations find a half-standard-deviation shift only 78% of the time), so report the interval, which shows which effects the data rule out. A tiny pp on a huge eval can come from a trivial effect.

Power is the part of the "real effect" curve beyond the rejection line

The test statistic under "no effect" (grey) and under a real shift of half a standard deviation (blue), α=0.05\alpha = 0.05 two-sided. Predict how large nn must be for 80% power, then drag. With z0.975=1.96z_{0.975} = 1.96 and z0.8=0.8416z_{0.8} = 0.8416, n=((1.96+0.8416)/0.5)2=31.4n = ((1.96 + 0.8416)/0.5)^2 = 31.4, so 32 observations (power 80.7%); with 30 the power is 78.2%, with 10 it is 35.3%. Halving the effect quadruples nn. exact

8. Which test: t, McNemar, permutation

The t-test divides a distance by its standard error, t=(x‾−μ0)/(s/n)t = (\bar x - \mu_0)/(s/\sqrt{n}), compared with Student's tn−1t_{n-1}. The paired t-test is the same test on per-example differences di=ai−bid_i = a_i - b_i with μ0=0\mu_0 = 0; for two independent groups, Welch's t-test uses (x‾1−x‾2)/s12/n1+s22/n2(\bar x_1 - \bar x_2)/\sqrt{s_1^2/n_1 + s_2^2/n_2}, which does not assume equal variances. Why pairing matters: when two models are scored on the same examples, most of the variation in a score is which examples are easy, which both models share; per-example differences cancel it, while comparing two separate averages carries it twice.

McNemar's test (McNemar 1947) is the paired test for right/wrong scores. Only the discordant examples count:

Here χ2=25/55=0.45\chi^2 = 25/55 = 0.45, p=0.50p = 0.50: no evidence. The paired standard error of the difference is (b+c)−(b−c)2/n/n=54.95/500=0.0148\sqrt{(b + c) - (b - c)^2/n}\,/\,n = \sqrt{54.95}/500 = 0.0148, a 95% interval of ±0.029\pm 0.029 (about ±3\pm 3 points); treated as independent, with accuracies near 0.5, it would be ±1.962×0.25/500=±0.062\pm 1.96\sqrt{2 \times 0.25/500} = \pm 0.062, about ±6.2\pm 6.2 points. Pairing halves the error bar but still cannot rescue a 1-point claim. With b=30b = 30, c=15c = 15 (a 3-point lead), χ2=225/45=5.0>3.84\chi^2 = 225/45 = 5.0 > 3.84, p=0.025p = 0.025. exact

Continuity correction and the exact version (depth)

Some texts subtract 1 from |b−c||b - c| before squaring, slightly more conservative: 4.36 and p=0.037p = 0.037 for the 3-point lead. With few discordant examples use the exact version: under H0H_0, b∼Binomial(b+c,12)b \sim \text{Binomial}(b + c, \tfrac12), which gives p=0.036p = 0.036.

Only the examples where the models disagree carry evidence

B rightB wrong
A rightboth right: drops outbb = 30
A wrongcc = 25both wrong: drops out

500 examples; A leads by (30−25)/500=1(30 - 25)/500 = 1 point. Under H0H_0 each discordant example is equally likely to fall either way, and χ2=(b−c)2/(b+c)\chi^2 = (b - c)^2/(b + c) is compared with a chi-squared distribution with one degree of freedom (5% critical value 3.84).

Permutation tests need no distribution, only a symmetry of the null (R. A. Fisher, The Design of Experiments, 1935): if A and B are equally good, each per-example difference was as likely to be +di+d_i as −di-d_i. Flip the signs every possible way, recompute the mean, and count how often it is as extreme as observed.

Rank tests (Wilcoxon's signed-rank for pairs, Mann-Whitney for two groups) are the classic robust choice for ordinal or heavy-tailed scores; they test a shift in location rather than the mean. For training runs across seeds, Welch's test with few seeds works, more seeds work better; Dietterich (1998, Neural Computation 10) compares the tests for comparing learning algorithms. Which test fits which eval, with one real comparison run through all of them, is section 5 of Eval statistics; its section 4 measures how much pairing shrinks the interval on real models.

An exact p-value by flipping signs: 16 of 256 patterns are as extreme

Eight per-example loss improvements (0.31,−0.12,0.25,0.40,0.05,0.18,−0.07,0.22)(0.31, -0.12, 0.25, 0.40, 0.05, 0.18, -0.07, 0.22) illustrative, mean 0.1525. The dots are the means of all 28=2562^8 = 256 sign patterns; the orange ones are at least as far from zero as observed, so p=16/256=0.0625p = 16/256 = 0.0625, exact at any nn. The paired t-test on the same numbers gives t=2.353t = 2.353, p=0.051p = 0.051: close, but it leaned on normality that eight numbers cannot confirm. With large nn, sample a few thousand random sign patterns.

9. Many tests at once: Bonferroni, Holm, and the false discovery rate

You try 20 prompt variants and one beats the baseline with p=0.03p = 0.03. Each test at α=0.05\alpha = 0.05 has a 5% false-positive rate when nothing is going on, so 20 independent tests on true nulls produce at least one "significant" result with probability 1−0.9520=0.641 - 0.95^{20} = 0.64, the family-wise error rate (FWER).

  • Bonferroni: test each of mm hypotheses at α/m\alpha/m (0.05 / 20 = 0.0025). By the union bound
    P(any false positive)≤∑iP(false positive i)≤m⋅αm=α,P(\text{any false positive}) \le \sum_i P(\text{false positive } i) \le m \cdot \frac{\alpha}{m} = \alpha,
    whatever the dependence between tests. The cost is power.
  • Holm (Holm 1979, Scandinavian Journal of Statistics 6): sort the p-values p(1)≤⋯≤p(m)p_{(1)} \le \dots \le p_{(m)}; reject while p(k)≤α/(m−k+1)p_{(k)} \le \alpha/(m - k + 1), stop at the first failure. Same FWER guarantee, never less power, so there is no reason to use plain Bonferroni.
  • Benjamini-Hochberg (JRSS B 57, 1995) controls the false discovery rate, the expected fraction of rejections that are false, FDR=𝔼[V/max⁡(R,1)]\mathrm{FDR} = \mathbb{E}[V/\max(R, 1)] with VV false rejections out of RR: find the largest kk with p(k)≤kα/mp_{(k)} \le k\alpha/m and reject the kk smallest. Proved for independent tests and for positively dependent ones (Benjamini and Yekutieli 2001). Use it when screening many candidates with a tolerable share of false leads.

The hidden comparisons count too: every prompt, seed, checkpoint, metric, subset and preprocessing choice tried and dropped (Gelman and Loken's "garden of forking paths", 2013). Simmons, Nelson and Simonsohn (Psychological Science 22, 2011) showed by simulation that four common flexible choices together push a nominal 5% false-positive rate to about 61%. The best of a sweep (the best of 50 runs) is also optimistically biased as an estimate of its own performance. The cleanest fix is a held-out confirmation run on new data, decided in advance, or a pre-registered analysis. The same problem appears in evaluating many benchmarks or slices, per-feature or per-neuron tests in interpretability, and release gates that check many metrics (section 6 of Eval statistics).

Same ten p-values, three rules: 7, 1 and 4 discoveries

Ten sorted p-values illustrative: 0.001, 0.008, 0.012, 0.019, 0.030, 0.041, 0.045, 0.21, 0.50, 0.80. Uncorrected at 0.05: 7 rejections. Bonferroni (each below 0.005): 1. Holm: 0.001 ≤\le 0.05/10, then 0.008 >> 0.05/9 = 0.0056, stop: 1. Benjamini-Hochberg at 5%: thresholds k×0.005k \times 0.005 are 0.005, 0.010, 0.015, 0.020, ...; the first four are under theirs (0.019 ≤\le 0.020) and none after, so 4 rejections, of which on average at most 5% are false. exact

10. Bayesian estimation: priors, posteriors, conjugacy

What most people want to say is "a 95% probability the true accuracy is in this range" or "B is better with probability 0.9". That needs the unknown to be a random variable with a prior, updated by Bayes' rule into a posterior (Probability for ML, section 9, derives the coin case). A 95% credible interval holds 95% of the posterior probability: the statement a confidence interval is often misread as making, now true by construction, at the price of choosing a prior.

A prior is conjugate to a likelihood when the posterior has the same form, so updating is arithmetic. For a heads probability with a Beta prior and kk heads in nn flips,

Beta(a,b)→k of nBeta(a+k, b+n−k),posterior mean=a+ka+b+n,\text{Beta}(a, b) \;\xrightarrow{\;k \text{ of } n\;}\; \text{Beta}(a + k,\ b + n - k), \qquad \text{posterior mean} = \frac{a + k}{a + b + n},

so the prior acts like aa heads and bb tails seen before the data (Gamma for Poisson rates and normal for normal means are the other common pairs).

Bayes factors compare two hypotheses by how well each predicted the data, BF10=P(data|H1)/P(data|H0)\mathrm{BF}_{10} = P(\text{data} \mid H_1)/P(\text{data} \mid H_0), each likelihood averaged over that hypothesis's prior. Fair coin: P(9 of 10)=10/1024=0.00977P(9 \text{ of } 10) = 10/1024 = 0.00977; any bias, uniform: ∫0110q9(1−q)dq=10×9!1!11!=1/11=0.0909\int_0^1 10\,q^9(1-q)\,dq = 10 \times \frac{9!\,1!}{11!} = 1/11 = 0.0909. So BF10=9.31\mathrm{BF}_{10} = 9.31, and with even prior odds the posterior probability of a fair coin is 1/(1+9.31)=0.0971/(1 + 9.31) = 0.097: about 10%, not the 2.1% a misread p-value suggests. Kass and Raftery (JASA 90, 1995) call factors from 3 to 20 "positive" evidence. exact

Credible intervals from weak priors match confidence intervals closely once nn is large; they differ, usefully, when nn is small or the parameter is near a boundary (accuracy near 0% or 100%). In ML: small evals of tens of items, A/B tests reported as "probability B beats A", Thompson sampling (Bandits and exploration) and Bayesian optimisation of hyperparameters. Beta-Bernoulli intervals for small evals and their exact coverage are in section 1 of Eval statistics.

Two cautions about Bayes factors (depth)

Bayes factors depend strongly on the prior under H1H_1 (a very wide prior spreads its bets and predicts the data poorly), and with huge nn a tiny p-value can come with a Bayes factor favouring H0H_0 (Lindley's paradox, 1957).

With 10 flips the prior still moves the answer; the data pull every prior towards 0.9

Dashed: the prior; solid: the posterior after 9 heads in 10; shaded: its 95% equal-tailed credible interval. exact Uniform: Beta(10, 2), mean 10/12=0.83310/12 = 0.833, interval (0.587, 0.977), P(q>0.5|data)=0.994P(q > 0.5 \mid \text{data}) = 0.994. Sceptical Beta(5, 5), as if 5 heads and 5 tails were already seen: Beta(14, 6), mean 0.700, interval (0.488, 0.874), P(q>0.5)=0.968P(q > 0.5) = 0.968. Jeffreys: Beta(9.5, 1.5), mean 0.864, interval (0.619, 0.989).

11. Regression as statistics: least squares, standard errors, ridge as a prior

Fit y=w0+w1x+εy = w_0 + w_1 x + \varepsilon with Gaussian noise ε∼𝒩(0,σ2)\varepsilon \sim \mathcal{N}(0, \sigma^2). The log-likelihood is −12σ2∑i(yi−w0−w1xi)2-\frac{1}{2\sigma^2}\sum_i (y_i - w_0 - w_1 x_i)^2 plus a constant, so least squares is the MLE. Because the fitted weights are a linear function of the noisy yy, their sampling distribution is exact for Gaussian noise:

wˆ=(X⊤X)−1X⊤y,Cov⁡(wˆ)=σ2(X⊤X)−1,SE(wˆ1)=sSxx,s2=RSSn−2,\hat w = (X^\top X)^{-1} X^\top y, \qquad \operatorname{Cov}(\hat w) = \sigma^2 (X^\top X)^{-1}, \qquad \mathrm{SE}(\hat w_1) = \frac{s}{\sqrt{S_{xx}}}, \quad s^2 = \frac{\mathrm{RSS}}{n - 2},

with Sxx=∑i(xi−x‾)2S_{xx} = \sum_i (x_i - \bar x)^2 and n−2n - 2 because two parameters were fitted (the degrees-of-freedom idea of section 3 again). Worked example illustrative: the eight numbers of section 3 as yy against x=1,…,8x = 1, \dots, 8. Sxx=42S_{xx} = 42, Sxy=34S_{xy} = 34, slope wˆ1=34/42=0.8095\hat w_1 = 34/42 = 0.8095, intercept 1.357, residual sum of squares 4.476, s=4.476/6=0.864s = \sqrt{4.476/6} = 0.864, SE(wˆ1)=0.864/42=0.1333\mathrm{SE}(\hat w_1) = 0.864/\sqrt{42} = 0.1333. The t-test of "no slope" gives t=6.07t = 6.07 on 6 degrees of freedom (p=0.0009p = 0.0009), and the 95% interval is 0.8095±2.447×0.1333=(0.483,1.136)0.8095 \pm 2.447 \times 0.1333 = (0.483, 1.136).

Ridge is a Gaussian prior. Give the slope a prior w1∼𝒩(0,τ2)w_1 \sim \mathcal{N}(0, \tau^2); the MAP estimate minimises ∑i(yi−yˆi)2+λw12\sum_i (y_i - \hat y_i)^2 + \lambda w_1^2 with λ=σ2/τ2\lambda = \sigma^2/\tau^2 (the MAP derivation is Probability for ML, section 9). With centred xx and the intercept left unpenalised, the slope becomes Sxy/(Sxx+λ)S_{xy}/(S_{xx} + \lambda).

This is the shrinkage of section 1 in a model: the penalty adds bias and removes variance, and λ\lambda is chosen by cross-validation (section 14) or, in the Bayesian reading, by the prior. Weight decay, dropout and early stopping as variance control are on Regularisation; linear and logistic regression in practice are on Classical ML.

A stronger prior pulls the slope towards zero: bias bought for variance

Dots: the eight points; dashed: least squares; solid: ridge. The equivalent prior standard deviation is τ=s/λ\tau = s/\sqrt{\lambda}, taking ss as the noise level. λ=1\lambda = 1: slope 0.7907 (τ=0.864\tau = 0.864); λ=10\lambda = 10: 0.6538 (τ=0.273\tau = 0.273); λ=42=Sxx\lambda = 42 = S_{xx}: 0.4048, exactly half, with τ=0.133\tau = 0.133, the size of the slope's own standard error. exact

12. Concentration bounds: guarantees at every nn

The CLT is a statement about the limit. A concentration inequality bounds the chance that an average lands far from its mean at every nn, with no "approximately". Three, each built on the previous: Markov, for X≥0X \ge 0, P(X≥a)≤𝔼[X]/aP(X \ge a) \le \mathbb{E}[X]/a; Chebyshev, P(|X−μ|≥t)≤σ2/t2P(|X - \mu| \ge t) \le \sigma^2/t^2 (and σ2/n\sigma^2/n for a mean of nn draws); Hoeffding (JASA 58, 1963, Theorem 2), for the mean of nn i.i.d. variables in [0,1][0, 1],

P(|X‾n−μ|≥t)≤2e−2nt2(divide the exponent by (b−a)2 for variables in [a,b]).P\big(|\bar X_n - \mu| \ge t\big) \le 2e^{-2nt^2} \qquad (\text{divide the exponent by } (b - a)^2 \text{ for variables in } [a, b]).

An accuracy on 500 examples: the chance of being off by 5 points or more is at most 2e−2×500×0.052=2e−2.5=0.162e^{-2 \times 500 \times 0.05^2} = 2e^{-2.5} = 0.16 by Hoeffding and 0.25/(500×0.0025)=0.20.25/(500 \times 0.0025) = 0.2 by Chebyshev; the CLT approximation says 0.025 and the exact binomial answer at accuracy 0.5 is 0.028. Pushing Hoeffding below 0.05 needs n≥ln⁡(2/0.05)/(2×0.052)=737.8n \ge \ln(2/0.05)/(2 \times 0.05^2) = 737.8, so 738 examples. exact

In ML these give worst-case eval sizes, generalisation bounds, and the confidence bonuses of bandits (UCB adds a Hoeffding-shaped bonus; Bandits and exploration), which must decide from finitely many samples which option is best, as RLHF data selection must.

The bounds on the tiny model, proofs, generalisation bounds, and concentration in high dimensions (depth)

Tiny model: Markov says P(loss≥2.408)≤0.832/2.408=0.346P(\text{loss} \ge 2.408) \le 0.832/2.408 = 0.346; the truth is 0.090. Chebyshev bounds the chance of landing two standard deviations (1.302) from the mean by 0.25; the truth is again 0.090 (only "sat" is that far). How loose a bound is depends on how much it assumes.

  1. Markov: 𝔼[X]≥𝔼[X⋅[X≥a]]≥aP(X≥a)\mathbb{E}[X] \ge \mathbb{E}[X \cdot [X \ge a]] \ge a\,P(X \ge a), since XX is at least aa where the indicator is 1 and at least 0 elsewhere.
  2. Chebyshev: apply Markov to (X−μ)2≥0(X - \mu)^2 \ge 0 with a=t2a = t^2.
  3. Hoeffding, sketch (the Chernoff method): apply Markov to eλ(X‾n−μ)e^{\lambda(\bar X_n - \mu)}, use independence to split the expectation into a product, bound each factor with Hoeffding's lemma 𝔼[eλ(X−𝔼X)]≤eλ2(b−a)2/8\mathbb{E}[e^{\lambda(X - \mathbb{E}X)}] \le e^{\lambda^2(b-a)^2/8}, and choose the best λ\lambda.

Generalisation bounds: the same inequality, plus a union bound. For one model fixed in advance and a test set of nn examples with 0/1 loss, with probability at least 1−δ1 - \delta, |true error−test error|≤ln⁡(2/δ)/(2n)|\text{true error} - \text{test error}| \le \sqrt{\ln(2/\delta)/(2n)}. If you pick the best of |ℋ||\mathcal H| models on the same data, each must be covered at once: δ\delta becomes δ/|ℋ|\delta/|\mathcal H| and the gap (ln⁡|ℋ|+ln⁡(2/δ))/(2n)\sqrt{(\ln|\mathcal H| + \ln(2/\delta))/(2n)} (Shalev-Shwartz and Ben-David, Understanding Machine Learning, 2014, chapter 4). With n=10,000n = 10{,}000 and δ=0.05\delta = 0.05: 0.0136 for one model, 0.0296 for the best of a million. Selecting on the test set costs you, but only logarithmically. For a training set and an infinite family, ln⁡|ℋ|\ln|\mathcal H| is replaced by a capacity measure (VC dimension, Rademacher complexity). For deep networks these bounds are vacuous (larger than 1): Zhang et al. (ICLR 2017, arXiv 1611.03530) showed that standard image networks fit random labels perfectly, so any bound that depends only on the family's capacity cannot explain why they generalise on real labels. PAC-Bayes bounds, which depend on how far the trained weights moved from a prior and how flat the minimum is, gave the first non-vacuous numbers for such networks (Dziugaite and Roy, UAI 2017, arXiv 1703.11008).

High dimensions concentrate hard. The squared norm of a random Gaussian vector in dd dimensions is close to dd (its length close to d\sqrt{d}), and the cosine similarity of two independent random vectors has standard deviation about 1/d1/\sqrt{d} (0.031 at d=1024d = 1024). Random vectors are nearly orthogonal and nearly equal-length, which is why random projections, hashing and random-feature models work, and part of the geometry of embeddings.

A guarantee costs you: the bounds sit far above the exact tail

The probability that an accuracy of 0.5 measured on nn examples is off by at least 5 points: exact binomial, the CLT approximation, and the two bounds. Hoeffding assumes the worst variance a bounded variable can have, which is why it is loose; it is still a guarantee.

13. Bias and variance of a model, and double descent

A trained model is an estimator too, so section 1's split applies to its predictions; how that split guides model choice (the U-shaped trade-off, ensembles against boosting, double descent decomposed into bias² and variance with Belkin, Hsu and Xu's exact formula, and why a little ridge removes the peak) is owned by Regularisation, sections 1 and 8.

14. Cross-validation and what it really estimates

KK-fold cross-validation: split the data into KK folds; for each fold, train on the other K−1K - 1 and record the loss on the held-out fold; average all nn held-out losses. Every example is tested once by a model that did not see it (leave-one-out: K=nK = n). It is how models and hyperparameters are chosen on small data, and how out-of-fold predictions for stacking are made.

It does not estimate what you think. Bates, Hastie and Tibshirani (JASA 2023, arXiv 2104.00673) show that cross-validation "estimates the average prediction error of models fit on other unseen training sets drawn from the same population", not the error of the model fitted on your data, and that naive intervals "may have coverage far below the desired level"; they propose nested cross-validation to estimate the variance. Our run simulated: linear regression with 20 Gaussian features, n=100n = 100, noise variance 1, 10-fold CV on 4,000 independent datasets. The naive 95% interval covered the error of the model actually fitted on that dataset in only 85.8% of runs, and the average error over training sets (1.253, exact for this design) in 89.5%. The CV estimate's real standard deviation across datasets was 0.214, against an average naive standard error of 0.179, and it was essentially uncorrelated with the error of the model it was meant to assess (correlation −0.047-0.047): exactly Bates et al.'s point. CV tells you how well this recipe (family, hyperparameters, training procedure) does on data like yours, not how good this fitted model is.

Selection inside CV. Choosing hyperparameters by CV and reporting the same CV score is optimistic (the best of many noisy numbers, section 9): use nested CV (an inner loop to choose, an outer loop to score) or a final untouched test set. Preprocessing fitted on all the data (scaling, feature selection) must also go inside the loop, or the held-out folds leak (Classical ML).

Any two fold models share most of their training data, so their errors are correlated

10-fold CV: each row is one model, the orange cell its held-out fold. Rows 1 and 2 share 8 of their 9 training folds, so their held-out errors move together, and the naive standard error s/ns/\sqrt{n} of the nn held-out losses is too small. Bengio and Grandvalet (JMLR 5, 2004) prove "there exists no universal (valid under all distributions) unbiased estimator of the variance of K-fold cross-validation".

Notation you will meet in papers (reference)
SymbolRead asMeaning
θˆ\hat\theta, θˆn\hat\theta_ntheta hatan estimate of θ\theta from data (of size nn)
x‾\bar x, s2s^2x bar, s squaredsample mean; sample variance with n−1n - 1
SE\mathrm{SE}, SEˆ\widehat{\mathrm{SE}}standard errorstandard deviation of an estimate; its estimate
𝒩(μ,σ2)\mathcal N(\mu, \sigma^2)normalthe second argument is a variance, not a standard deviation
zqz_{q}, tν,qt_{\nu, q}quantilesthe point below which a fraction qq of the normal (or t with ν\nu degrees of freedom) lies; z0.975=1.96z_{0.975} = 1.96
Φ\Phi, Φ−1\Phi^{-1}Phithe standard normal CDF and its inverse
→p\xrightarrow{p}, →d\xrightarrow{d}converges in probability, in distributionLLN-type and CLT-type limits
Op(1/n)O_p(1/\sqrt n)big O in probability"of order 1/n1/\sqrt n with high probability": the size of the estimation error
H0H_0, H1H_1, α\alpha, β\betanull, alternative, false-positive rate, false-negative rate (power 1−β1 - \beta)
x∗x^*, θˆ∗\hat\theta^*x stara bootstrap resample, a bootstrap replicate
θˆ(i)\hat\theta_{(i)}theta hat, i left outthe jackknife: the estimate without observation ii
𝔼𝒟\mathbb{E}_{\mathcal D}expectation over datasetsthe average over training sets in bias-variance statements