Solution (source code)

= Solution

For the <normal linear model>, the <Gaussian likelihood> gives
$$
\ell(\beta,\sigma^2)
=-\frac n2\log(2\pi\sigma^2)
-\frac1{2\sigma^2}\|Y-X\beta\|^2.
$$
Maximization over $\beta$ gives the <ordinary least squares> estimator $\widehat\beta$, and maximization over the variance gives
$$
\widehat\sigma^2=\frac1n\|Y-X\widehat\beta\|^2.
$$
At this value the quadratic term in $-2\ell$ is $n$. There are $p$ <regression coefficient>[regression coefficients] and one variance parameter, so substitution into the <Akaike information criterion> yields
$$
\boxed{\operatorname{AIC}=n\bigl(1+\log(2\pi\widehat\sigma^2)\bigr)+2(p+1).}
$$