Assume y=Xβ+ε with E[ε]=0, Cov⁡(ε)=σ2I and X of full column rank p. How do you prove that E[RSS]=(n−p)σ2, so that σ^2=RSS/(n−p) is unbiased?

Supervised learning, Least squares and the hat matrix
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

The trace argument with the hat matrix H: residuals are (I−H)ε and tr⁡(I−H)=n−p.

Key idea

The residual vector is e=(I−H)ε, with I−H a symmetric idempotent matrix. So RSS=ε⊤(I−H)ε, and its expectation is σ2tr⁡(I−H)=σ2(n−p).

Steps

  1. The hat matrix is H=X(X⊤X)−1X⊤, so y^=Hy and e=(I−H)y.
  2. Since HX=X, we get (I−H)Xβ=0. Therefore e=(I−H)(Xβ+ε)=(I−H)ε.
  3. H is symmetric and H2=H, so I−H is also symmetric and idempotent. Hence RSS=e⊤e=ε⊤(I−H)⊤(I−H)ε=ε⊤(I−H)ε.
  4. Take the expectation of a quadratic form: E[ε⊤Aε]=tr⁡(A E[εε⊤])=σ2tr⁡(A) for symmetric A.
  5. Compute the trace: tr⁡(I−H)=n−tr⁡(X(X⊤X)−1X⊤)=n−tr⁡((X⊤X)−1X⊤X)=n−tr⁡(Ip)=n−p, using the cyclic property of the trace.
  6. So E[RSS]=σ2(n−p) and dividing by n−p removes the bias. No Gaussian assumption is needed.

Common mistakes

How long your answer should be

Half a page; 5 minutes.

Last checked on 4 December 2026.

Read this

Previous in Supervised learning: For ridge regression, define the effective degrees of freedom df⁡(λ)=tr⁡(X(X⊤X+λI)−1X⊤) and express it with the singular values dj of X. If X has singular values 4,2,1 and λ=4, what are df⁡ and the shrinkage factor on each direction?
Next in Supervised learning: Write a distribution in exponential-dispersion form p(y∣θ)=exp⁡{yθ−b(θ)+c(y)}. How do you show that the Bernoulli and Poisson distributions fit this form, what is the canonical link in each case, and why does a canonical link make the log-likelihood gradient equal to X⊤(y−μ)?