# Why is the expected value $E(X^2) \neq E(X)^2$?

I wish to use the Computational formula of the variance to calculate the variance of a normal-distributed function. For this, I need the expected value of $X$ as well as the one of $X^2$. Intuitively, I would have assumed that $E(X^2)$ is always equal to $E(X)^2$. In fact, I cannot imagine how they could be different.

Could you explain how this is possible, e.g. with an example?

• If two random variables $X, Y$ are independent, then it is indeed true that $\mathbb{E}(XY) = \mathbb{E}(X) \mathbb{E}(Y)$. But $X$ is as far as possible from being independent of itself! May 25 '12 at 17:44
• Just take a simple example: if we have $1$ and $2$ as being equally probable, then $\left(\frac{1+2}{2}\right)^2 = \frac{9}{4}$ but $\frac{1^2 + 2^2}{2} = \frac{5}{2}$. May 25 '12 at 20:50
• No offense, but if you tried anything at all (even just blindly guessing a distribution) and computed $E(X^2)$ and $E(X)^2$, you would almost surely have found an example on your own. Experimentation is a very useful tool in mathematics.
– user14972
May 26 '12 at 0:28
• Jensens inequality. See mathoverflow.net/questions/47258/… May 26 '12 at 22:55
• @David: No, Cauchy-Schwarz. (Besides, indicating this MO page as a reference for Cauchy-Schwarz or for Jensen is, at best, a joke.)
– Did
Jul 25 '12 at 23:51

Assume $X$ is a random variable that is 0 half the time and 1 half the time. Then $$EX = 0.5 \times 0 + 0.5 \times 1 = 0.5$$ so that $$(EX)^2 = 0.25,$$ whereas on the other hand $$E(X^2) = 0.5 \times 0^2 + 0.5 \times 1^2 = 0.5.$$ By the way, since $Var(X) = E[(X - \mu)^2] = \sum_x (x - \mu)^2 P(x)$, the only way the variance could ever be 0 in the discrete case is when $X$ is constant.

Let $$EX=\mu$$ and $$E(X-\mu)^2=\sigma^2$$, then

$$EX^2 = E[X-\mu+\mu]^2=\\ =E(X-\mu)^2+2E[(X-\mu)\mu]+E(\mu^2)=\\=\sigma^2+2\mu E(X-\mu)+\mu^2=\\ =\sigma^2+\mu^2$$

So $$EX^2 =\sigma^2+\mu^2$$, no matter the distribution, and $$EX^2\ne(EX)^2$$ unless the variance equals zero.

• Isn't $2E[(X−μ)μ]$ supposed to have a plus in front of it instead of a minus? Not a huge deal since it equals $0$ though. Aug 11 at 4:13
• you are right! corrected, thanks! Aug 11 at 13:12

One is an average of squares, the other a square of an average. In general, when you reverse two procedures (mix cookies, bake cookies), you have no right to expect the same outcome.

Note that your logic applied to a uniform distribution would give that $$(x_1+x_2+\cdots+x_n)^2=n({x_1}^2+{x_2}^2+\cdots+{x_n}^2)$$ which is clearly not true in general.

• What are the dots for?
– Ilya
May 25 '12 at 20:54
• whoops. Meant to include them in both as an ellipsis. Fixed. May 25 '12 at 23:57
• The usual style is $x+y+z+\cdots$, FYI.
– user856
May 26 '12 at 1:07
• Thanks the for the tip Rahul! May 26 '12 at 1:57
• This (highly upvoted) explanation is seductive but it seems to miss the point: what $E(X^2)=E(X)^2$ would imply is something more like the square of the sum being the sum of the squares times the number of terms (not simply the sum of the squares). Another way to see it is that $E(X^2)=E(X)^2$ is true when $X$ is constant while the square of the sum is not the sum of the squares, even when the arguments are all equal.
– Did
May 26 '12 at 7:43

Let us take for example $X$ the standard normal, or any normal with mean $0$. Then $E(X)=0$.

But $X^2$ is always positive, so clearly its mean must be positive.

This shows that (in this case) $E(X^2)\ne (E(X))^2$.

In fact, when the expectations exist, $E(X^2)>(E(X))^2$ except when $X$ is constant with probability $1$.

• Even easier to see, maybe, if you make the values $-1$ and $1$. May 25 '12 at 17:18
• @RobertIsrael: I had deleted my post, since someone had posted the same example. Then decided to use normal, since that's what OP was working with, and ended up with a variant of your example. May 25 '12 at 17:22

Say you have a fair coin that says $X=1$ on one side and $X=3$ on the other side. You flip the coin. Clearly, $E(X)=\frac12(1+3) = 2$.

If you are counting $X^2$ instead of $X$, then one side of the coin is worth $1^2=1$ and the other side is worth $3^2=9$, so $E(X^2) = \frac12(1+9)=5$.

$5\ne 2^2$.

My turn:

Let $X$ be uniformly distributed on $[0,1]$. The $E X =\int_{t=0}^1 t dt = \frac{1}{2}$, but $E X^2 =\int_{t=0}^1 t^2 dt = \frac{1}{3}$.

May as well chime in :)

Expectations are linear pretty much by definition, so $E(aX + b) = aE(X) + b$. Also linear is the function $f(x) = ax$. If we take a look at $f(x^2)$, we get

$f(x^2) = a(x^2) \not= (ax)^2 = f(x)^2$.

If $E(X^2) = E(X)^2$, then $E(X)$ could not be linear, which is a contradiction of its definition. So, it's not true :)

Assuming $X$ is a discrete random variable $E(X)=\sum x_ip_i$. Therefore $E(X^2)=\sum x_i^2p_i$ while $[E(X)]^2=\left(\sum x_ip_i\right)^2$. Now, as Robert Mastragostino says, this would imply that $(x+y+z+\cdots)^2=x^2+y^2+z^2+\cdots$ which is not true unless $X$ is constant.

• How so? See my comment on the other answer.
– Did
May 26 '12 at 7:45