Hat matrix (source code)

= Hat matrix
{wiki}

The hat matrix
$$
H=X(X^TX)^{-1}X^T
$$
is the orthogonal projection onto the column space of a full-rank design matrix, and the fitted response is $\widehat Y=HY$.