projection matrix using A = QR in a projection matrix where P = $A(A^TA)^{-1}A^T$, if you allow A=QR where Q is orthogonal and R is reversible, P can be then expressed as P = $QQ^T$. I can follow all those steps, but I seem to also be able to come up with an incorrect solution, and can't figure out what rule I'm violating.
P = $A(A^TA)^{-1}A^T$ and A = QR
P = $QR((QR)^TQR)^{-1}(QR)^T$
P = $QR(R^TQ^TQR)^{-1}(QR)^T$
at this point if we simplify $Q^TQ$=I then it leads to the correct P=$QQ^T$ but if we don't combine and keep going...
P = $QRR^{-1}Q^{-1}(Q^T)^{-1}(R^T)^{-1}(QR)^T$
P = $QRR^{-1}Q^{-1}(Q^T)^{-1}(R^T)^{-1}R^TQ^T$
P = $QIQ^{-1}(Q^T)^{-1}IQ^T$ = $QQ^{-1}(Q^T)^{-1}Q^T = II = I$
This is supposed to be the case when Q is square, but not all cases.
I'm pretty sure I did something illegal, but I can't seem to find where. 

Hint: you are inverting $Q$. Is this well-defined for nonsquare matrices?
