# Hat matrix with simple linear regression

However I am unable to work this out myself. When I multiply things out I get $\frac{1}{nS_{xx}}(\sum_{j=1}^n x_j^2 -2n\bar{x}x_i+nx_i^2)$. For things to be true, the terms inside the parenthesis can be rearranged to be $S_{xx}+n(x_i-\bar{x})^2$. I tried rearranging the terms so $\sum_{j=1}^n x_j^2 -n\bar{x}x_i+nx_i^2-n\bar{x}x_i$, but I can't seem to get to the answer. There must be some form of $S_{xx}$ that I am not aware of that is buried in their somewhere. Any help would be appreciated.

• Have you used the relation $S_{xx}= x_i^2-n\bar{x}^{2}$? – felasfa Oct 9 '16 at 22:31
• If you use that, you get the resulting equation. Let me know otherwise – felasfa Oct 9 '16 at 22:35
• I assume you mean $S_{xx}=\sum x_i^2 - n \bar{x}^2$. There is no $\bar{x}^2$ anywhere, so I am not sure where I would use that formula. Thanks! – Carl Ganz Oct 9 '16 at 22:43
• yes, you are right. I forgot the summation. – felasfa Oct 9 '16 at 23:16