How do they simplify these regression formulas My book writes
$$\text{SSres}=\sum (y_j-\hat y_j)^2$$ $$=\sum y^{2}_{j}-n \bar y ^{2} - \beta_{1} 
Sxy$$
How is this the same formula?
 A: We have $\hat{y_{j}}=\hat{\beta_0}+\hat{\beta_1} x_j$, 
where $$\hat{\beta_0} = \bar{y}-\hat{\beta_1}\bar{x}, \qquad \hat{\beta_1}=\dfrac{\sum_{j}(x_j-\bar{x})(y_j-\bar{y})}{\sum_j (x_j-\bar{x})^2} =\dfrac{S_{xy}}{S_{xx}}$$
\begin{eqnarray*}
SS_{res}&=&\sum_j (y_j-\hat{y_j})^2 = \sum_j(y_j-(\hat{\beta_0}+\hat{\beta_1} x_j))^2\\
&=&\sum_j(y_j-(\bar{y}-\hat{\beta_1}\bar{x}+\hat{\beta_1} x_j))^2\\
&=&\sum_j\left((y_j-\bar{y})-\hat{\beta_1}(x_j-\bar{x})\right)^2\\
&=&\sum_j(y_j-\bar{y})^2 + \hat{\beta_1}^2 \sum_j (x_j-\bar{x})^2-2\hat{\beta_1}\sum_j(y_j-\bar{y})(x_j-\bar{x})\\
&=&\sum_j(y_j-\bar{y})^2 + \hat{\beta_1}^2 \sum_j (x_j-\bar{x})^2-2\hat{\beta_1}\left(\dfrac{\sum_j(y_j-\bar{y})(x_j-\bar{x})}{\sum_j (x_j-\bar{x})^2}\right)\sum_j (x_j-\bar{x})^2\\
&=&\sum_j(y_j-\bar{y})^2 + \hat{\beta_1}^2 \sum_j (x_j-\bar{x})^2 -2\hat{\beta_1}^2 \sum_j (x_j-\bar{x})^2\\
&=&\sum_j(y_j-\bar{y})^2 - \hat{\beta_1}^2 \sum_j (x_j-\bar{x})^2 \\
&=&\sum_j(y_j-\bar{y})^2 - \hat{\beta_1}^2 S_{xx}, \qquad\mbox{since } S_{xx} =\sum_j (x_j-\bar{x})^2 \\
&=&\sum_j y_{j}^2 - n\bar{y}^2 -\hat{\beta_1}^2 S_{xx},\qquad\mbox{since }
\sum_j(y_j-\bar{y})^2 = \sum_j y_{j}^2 - n\bar{y}^2\\
&=&\sum_j y_{j}^2 - n\bar{y}^2 - \hat{\beta_1}\dfrac{S_{xy}}{S_{xx}} S_{xx}\\
&=&\sum_j y_{j}^2 - n\bar{y}^2 - \hat{\beta_1} S_{xy}\\
\end{eqnarray*}
