I recently came across this question on stats stack exchange where a user asked for the proof that the T statistic has a t distribution. The question assumes a linear model of the form;
$$Y=X\beta+\epsilon$$
The proof in the accepted answer makes a step in which it first defines the residual maker matrix as:
$$M=I_n - X(X^TX)^{-1}X^T$$
And then states $My=\hat{\varepsilon}$ (the estimated residuals) and that $M$ is symmetric and idempotent. I understand this so far. Later on though it makes this step:
$$\frac{\hat\varepsilon^T\hat\varepsilon}{\sigma^2} = \left(\frac{\varepsilon}{\sigma}\right)^T M \left(\frac{\varepsilon}{\sigma}\right)$$
I am confused though as, given $My=\hat{\varepsilon}$, it seems this should equal:
$$\frac{\hat\varepsilon^T\hat\varepsilon}{\sigma^2} = \left(\frac{y}{\sigma}\right)^T M \left(\frac{y}{\sigma}\right)$$
However, if you were to change this the original proof no longer seems to work. Have I misunderstood this?
Note: I have also asked this question as a comment on the original post but it seems as though the author of the solution might not have logged in for a long time so made this separate question. I will add a comment to the original post if any answers are added here.