This is a problem out of my statistics book but my issue is simplifying from Step 3 to Step 4 below:
Step 1: var X=$\sum\:p_i\:(x_i-E[X])^2$
Step 2: var X=$\sum\:p_i[x_i^2+E[X]^2-2x_iE[X]]$
Step 3: var X=$\sum\:p_ix_i^2+(E[X])^2\sum\:p_i-2E[X]\sum\:p_ix_i$
Step 4: var X=$\sum\:p_ix_i^2-(E[X])^2$
Additional Information
- $p_i$ is the probability that X takes the value $x_i$
- E[X] is the expected value of X, defined as $\sum\:p_ix_i$
My attempt to Step 4 is provided below but that is where I am stuck:
var X=$\sum\:p_ix_i^2+(E[X])^2\sum\:p_i-2E[X]^2$
Step 3 is given by
$ \mathrm{Var}[X] = \sum p_i x_i^2 + (\mathrm{E}[X])^2 \cdot \color{red}{\sum p_i} - 2 \cdot \mathrm{E}[X] \cdot \color{blue}{\sum p_i x_i}. $
This is equivalent to
$ \mathrm{Var}[X] = \sum p_i x_i^2 + (\mathrm{E}[X])^2 \cdot \color{red}{1} - 2 \cdot \mathrm{E}[X] \cdot \color{blue}{\mathrm{E}[X]}. $
This, in turn, is equivalent to step 5, given by
$ \mathrm{Var}[X] = \sum p_i x_i^2 + (\mathrm{E}[X])^2 - 2 \cdot (\mathrm{E}[X])^2 = \sum p_i x_i^2 - (\mathrm{E}[X])^2. $