TITLE: Expected value of an expected value
QUESTION [20 upvotes]: I am looking at a proof that $\text{Var}(X)= E((X - EX)^2) = E(X^2) - (E(X))^2$
$E((X - EX)^2) =$
$E(X^2 - 2XE(X) + (E(X))^2) =$
$E(X^2) - 2E(X)E(X) + (E(X))^2)$
I can't see how the second line can be equal to the third line. I would have had the following for the third line -
$E(X^2) - E(2XE(X)) + E((E(X))^2))$
Which seems very messy... There must be something I am not understanding about the properties of expected values?

REPLY [7 votes]: $E(X^2-2XE(X)+(E(X))^2)=E(X^2)-E(2XE(X))+E((E(X))^2)$
$=E(X^2)-E(X)E(2X)+(E(X))^2$.
The second term is such because $E(X)$ is a constant, and the expectation of a constant is the constant itself (same for the last term ($E(X))^2$)
$=E(X^2)-2(E(X))^2+(E(X))^2=E(X^2)-(E(X))^2$