How to expand the sum of a squared bracket?

125 Views Asked by At

I am following the video lecture series "Bayesian Statistics: Techniques and Models" - week 1 lesson 2: Non-conjugate models from UCSC and am having trouble understanding how they expanded their summation of a squared bracket, as I haven't seen the theory for this before. (I have omitted parts of the equation that are not relevant but still visible in the provided attachment.) The formula in question

$$-1/2\sum_{i=1}^n (yi-\mu)^2$$

turns into

$$-1/2(\sum_{i=1}^n yi^2-2\mu \sum_{i=1}^n yi + n\mu^2)$$

Would someone be able to walk through the process of expansion between these two steps or provide a reference to theory explaining how we expand squared terms inside of a sum? In particular I am confused about where n comes from (as I guess it comes from the summation term, but would prefer to know for certain, rather than guess).

Thanks

1

There are 1 best solutions below

4
On BEST ANSWER

We ave:

$$ \sum_{i=1}^n(y_i-\mu)^2=\sum_{i=1}^n(y_i^2-2\mu y_i+\mu^2)= $$ $$ =\sum_{i=1}^ny_i^2 -\sum_{i=1}^n2\mu y_i +\sum_{i=1}^n\mu^2= \sum_{i=1}^ny_i^2 -2\mu\sum_{i=1}^n y_i +n\mu^2 $$