Solution (source code)

= Solution

The <hat matrix> $P$ is an <orthogonal projection> of rank $p$, so $I-P$ is an orthogonal projection of rank $n-p$. Because $\varepsilon/\sigma$ is a standard <multivariate normal distribution> vector, <Cochran's theorem> gives
$$
\frac{n\widehat\sigma^2}{\sigma^2}
=\frac{\|(I-P)\varepsilon\|^2}{\sigma^2}
\sim\chi^2_{n-p}.
$$
Thus $\widehat\sigma^2\overset d=(\sigma^2/n)\chi^2_{n-p}$. Substituting this into the preceding formula gives the <Distribution of the Akaike information criterion in a normal linear model>:
$$
\boxed{\operatorname{AIC}\overset d=
n\log(\chi^2_{n-p})
+n\bigl(\log(2\pi\sigma^2/n)+1\bigr)+2(p+1).}
$$