Consider fixed-design regression yi=μi+εi (i=1,…,n) with independent noise E[εi]=0 and Var⁡(εi)=σ2, and let y^=f(y) be any fitted predictor. How do you prove that the expected in-sample optimism equals E[Errin]−E[err‾]=2n∑i=1nCov⁡(y^i,yi), and how does this simplify to 2σ2dn for rank-d ordinary least squares (giving Mallows' Cp)?

Foundations, Model selection
Level L5 Expert. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can derive the covariance formula for training-error optimism from first principles and specialise it to linear smoothers and OLS.

Key idea

Training error err‾ uses the same yi twice (to fit y^i and to evaluate it), creating a −2Cov⁡(y^i,yi) downward bias relative to fresh responses yinew; for linear smoothers y^=Hy, ∑iCov⁡(y^i,yi)=σ2tr⁡(H).

Steps

  1. Define both errors: let err‾=1n∑i=1n(yi−y^i)2 be the training MSE, and let yinew=μi+εinew be an independent copy of the response at the same fixed input xi, so Errin=1n∑i=1nEynew[(yinew−y^i)2∣y].
  2. Expand the expected in-sample error for coordinate i: since yinew−μi has zero mean and is independent of y^i, Ey,ynew[(yinew−y^i)2]=E[((yinew−μi)+(μi−y^i))2]=σ2+E[(y^i−μi)2].
  3. Expand the expected training error for coordinate i: write yi−y^i=(yi−μi)−(y^i−μi) to obtain Ey[(yi−y^i)2]=σ2+E[(y^i−μi)2]−2 E[(yi−μi)(y^i−μi)].
  4. Subtract to get the optimism: because E[yi−μi]=0, the cross term simplifies without assuming y^i is unbiased: E[(yi−μi)(y^i−μi)]=E[(yi−μi)(y^i−E[y^i])]=Cov⁡(y^i,yi). Averaging over i=1,…,n yields E[Errin]−E[err‾]=2n∑i=1nCov⁡(y^i,yi).
  5. Specialise to linear smoothers y^=Hy (such as OLS or ridge regression, where H is the n×n smoother matrix): since Cov⁡(y)=σ2In, Cov⁡(y^,y)=HCov⁡(y,y)=σ2H, so ∑i=1nCov⁡(y^i,yi)=σ2tr⁡(H)=σ2df⁡(y^).
  6. Specialise to OLS with full-rank design matrix X∈Rn×d (rank⁡(X)=d): H=X(X⊤X)−1X⊤ satisfies tr⁡(H)=tr⁡((X⊤X)−1X⊤X)=tr⁡(Id)=d, so the optimism is 2σ2dn. Adding an unbiased estimate σ^2 gives Mallows' Cp=err‾+2σ^2dn, which matches AIC (up to a constant) for Gaussian linear models with known σ2.

Common mistakes

How long your answer should be

One page; 8–10 minutes.

Last checked on 4 December 2026.

Read this

Previous in Foundations: How is Schwarz's Bayesian Information Criterion BIC=kln⁡n−2ℓ(θ^MLE) derived from the Bayesian marginal likelihood p(D∣M)=∫Rkp(D∣θ,M) p(θ∣M) dθ using Laplace's approximation?
Next in Foundations: none