# Small trouble with summation algebra

Wouldn't the first term below leads to the final term?

$$\hat{\beta_1}={\sum_{i=1}^n c_iy_i} = {\sum_{i=1}^n \frac{(x_i-\bar{x})(y_i)}{SXX}} = {\sum_{i=1}^n \frac{(x_i-\bar{x})(y_i)}{{\sum\limits_{i=1}^n (x_i-\bar{x})^2}}} = \frac{SXY}{SXX},$$ which is very different from $$\frac{\sum\limits_{i=1}^n{(x_i-\bar{x})(y_i)}}{{\sum\limits_{i=1}^n (x_i-\bar{x})^2}} = \frac{SXY}{SXX}=\hat{\beta_1}.$$

I am confused about how, in the first line, the author factored out was able to factor out the $SXX$ term from inside the summation.

\begin{align*} \widehat{β}_1 &= \sum_{k = 1}^n \frac{(x_k - \overline{x}) y_k}{S_{XX}} = \sum_{k = 1}^n \frac{(x_k - \overline{x}) y_k}{\displaystyle \sum_{j = 1}^n (x_j - \overline{x})^2}\\ &= \frac{1}{\displaystyle \sum_{j = 1}^n (x_j - \overline{x})^2} · \sum_{k = 1}^n (x_k - \overline{x}) y_k = \frac{\displaystyle \sum_{k = 1}^n (x_k - \overline{x}) y_k}{\displaystyle \sum_{j = 1}^n (x_j - \overline{x})^2}. \end{align*}

• Wait, you can just pull the inside summation out like that? I don't think I've seen that rule before. Can you point me to a proof of being able to do this? – L to the V May 27 '18 at 3:28
• @LtotheV Note that $c:=\dfrac1{\displaystyle \sum_{j=1}^n(x_j-\overline x)^2}$ is a constant irrelevant to the summation index $k$ in the outer summation, thus$$\sum_{k=1}^nc(x_k-\overline x)y_k=c\sum_{k=1}^n(x_k-\overline x)y_k.$$ – Saad May 27 '18 at 3:30
• So in the first line second last term, they use i for both the outside and inside summation, but for the summation inside you can switch from i to j, thus making it a constant? – L to the V May 27 '18 at 4:02
• @LtotheV In fact, it's incorrect to use $i$ in both outer and inner summation. – Saad May 27 '18 at 4:05
• @LtotheV $i$ can be used in both outer and inner summation like $\sum\limits_{i=1}^n\left(x_i+\sum\limits_{j=1}^i(a_jy_i+b_j)\right)$, but $i$ as the summation index for the outer sum cannot be used again as summation index in the inner one like $\sum\limits_{i=1}^n\left(x_i+\sum\limits_{i=1}^n(a_iy_i+b_i)\right)$, which is ambiguous. – Saad May 28 '18 at 7:12