Solution (source code)

= Solution

Full column <matrix rank> makes $X^TX$ a <positive-definite matrix>, and its <matrix inverse> is symmetric. Thus the <hat matrix> satisfies
$$
P^T=X\bigl((X^TX)^{-1}\bigr)^TX^T=P,
\qquad P^2=X(X^TX)^{-1}(X^TX)(X^TX)^{-1}X^T=P.
$$
Also $PX=X$ and the image of $P$ is contained in the <column space> of $X$. These identities show that \b[$P$ is the <orthogonal projection matrix> onto the <column space> of $X$].