How to show sum of squares regression formula?

73 Views Asked by At

Given an $n$ x $1$ vector $y$ and design matrix $X$, how does one show $$SS_{reg}=y^T(H-\vec{1}(\vec{1}^T\vec{1})^{-1}\vec{1}^T)y$$

Where $H=X(X^TX)^{-1}X^T$ is the $p$ x $p$ hat matrix, and $SS_{reg}=\sum\hat{y_i}^2-\frac{(\sum{y_i})^2}{n}$