# How can you derive the least squares hat matrix from the GLM hat matrix?

The GLM hat matrix is $$\mathbf{H}_{GLM} = \mathbf{W^{1/2}X(X^{T}WX)^{-1}X^{T}W^{1/2}}$$

where $\mathbf{W}$ is a diagonal matrix with elements $w_i = (\delta\mu_i/\delta\eta_i)^2/\text{var}(y_i).$ For OLS, the link function is identity so $\mu_i = \eta_i$ and $\delta\mu_i/\delta\eta_i = 1.$ Also, the random component is Gaussian, so $\text{var}(y_i) = \sigma^2$.

From this I can express $\mathbf{W}$ as $\frac{1}{\sigma^2}\mathbf{I}.$ Plugging this into the GLM hat matrix, I get

\begin{align}\mathbf{H}_{OLS} &= \left(\frac{1}{\sigma^2}\mathbf{I}\right)^{1/2}\mathbf{X(X^{T}}\left(\frac{1}{\sigma^2}\mathbf{I}\right)\mathbf{X)^{-1}X^{T}}\left(\frac{1}{\sigma^2}\mathbf{I}\right)^{1/2} \\ &=\frac{1}{\sigma^4}\mathbf{X(X^{T}X)^{-1}X^{T}} \end{align}

But thats not right! That $\frac{1}{\sigma^4}$ term does not belong there. The correct answer should be $$\mathbf{H}_{OLS} = \mathbf{X(X^{T}X)^{-1}X^{T}}$$

What did I do wrong?

In \begin{align}\mathbf{H}_{OLS} &= \left(\frac{1}{\sigma^2}\mathbf{I}\right)^{1/2}\mathbf{X(X^{T}}\left(\frac{1}{\sigma^2}\mathbf{I}\right)\mathbf{X)^{-1}X^{T}}\left(\frac{1}{\sigma^2}\mathbf{I}\right)^{1/2}, \end{align} we have (twice, once left, once right) $\left(\frac{1}{\sigma^2}\right)^{1/2}=\frac{1}{\sigma}$ as well as $$\left(\frac{1}{\sigma^2}\right)^{-1}=\sigma^2$$ in the middle term.