I am solving a problem involving linear regression and I am finding that two different approaches to the matrix algebra is yielding different results.
In the second approach, I am merely simplifying the second component of the expression first. As you can see, the results are vastly different. Intuitively, I think the first approach is correct but I can't figure out what is wrong with the second approach to yield such a different answer.
Here, we assume $M_{x} = I -X(X'X)^{-1}X'$ and $X'X$ is non-singular. I am hoping that your answer will help me better understand matrix algebra!
Approach 1: $$ X'(M_{x})^{-1}X - X'(M_{x})^{-1}X(X'X)^{-1}(X'X) \\ X'(M_{x})^{-1}[I -X(X'X)^{-1}X']X \\ X'(M_{x})^{-1}M_{x}X \\ X'X $$
Approach 2: $$ X'(M_{x})^{-1}X - X'(M_{x})^{-1}X(X'X)^{-1}(X'X) \\ X'(M_{x})^{-1}X - X'(M_{x})^{-1}X \\ 0 $$
As @Rahul noted in comment, $M_x$ is not invertible since $$ X'M_x=X'(I -X(X'X)^{-1}X') = X' - (X'X)(X'X)^{-1}X' = \mathbb 0 $$ where the result is zero rectangular matrix. It means that all rows of $M_x$ are linearly dependent and $M_x$ is singular.