Solution (source code)

= Solution

Assume $X$ has full column rank. The log-likelihood, up to constants, is
$$
-\frac n2\log\sigma^2-\frac1{2\sigma^2}\|Y-X\beta\|^2.
$$
The <ordinary least squares estimators>[ordinary least squares] normal equations give
$$
\widehat\beta=(X^TX)^{-1}X^TY,
$$
and maximizing over the variance gives the maximum-likelihood estimator
$$
\widehat\sigma^2=\frac1n\|(I-H)Y\|^2.
$$
Because $I-H$ is an orthogonal projection of rank $n-p$,
$$
\boxed{\frac{n\widehat\sigma^2}{\sigma^2}\sim\chi^2_{n-p}}.
$$
Writing $\chi^2_{\nu,q}$ for the $q$-quantile, a confidence interval of level $1-\alpha$ is
$$
\boxed{\left[
\frac{n\widehat\sigma^2}{\chi^2_{n-p,1-\alpha/2}},
\frac{n\widehat\sigma^2}{\chi^2_{n-p,\alpha/2}}
\right]}.
$$