I am facing the following problem in the context of linear regression:
On the one hand, it holds that $SS_{reg}=\sum(\hat{Yi} - \bar{Y})^2= Y'(H - \frac 1 nJ)Y$ where $H = X(X'X)^{-1}X'$ and $J$ is a matrix of ones (see e.g. https://math.stackexchange.com/q/1334601). If I understand this equality correctly this should imply that $(H - \frac 1 nJ)$ is idempotent. That is because $SS_{reg}=\sum(\hat{Yi} - \bar{Y})^2 = (\hat{Y} - \bar{Y})'(\hat{Y} - \bar{Y}) = ((H - \frac 1 n J)Y)'((H - \frac 1 n J)Y) = Y'(H - \frac 1 n J)(H - \frac 1 n J)Y$.
If I compute the product numerically the results also suggest that $H - \frac 1 n J$ is idempotent.
However, $(H - \frac 1 n J)(H - \frac 1 n J) = H - \frac 1 nHJ-\frac 1 n JH+\frac 1 n J$ which would suggest that $(H - \frac 1 n J)$ is not idempotent because $H$ is of course not the identity (see e.g. Proving that $\mathbf{(H-\frac{1}{n}J_n)}$ is indempotent). I don't know what I am missing.