Why is $E(X^2)$ not equal to the sum of $(x^2 \cdot P(x^2))$ instead of $x^2 \cdot P(x)$ Why is $E(X^2)$ not equal to the sum of $(x^2 \cdot P(x^2))$ instead of $x^2 \cdot P(x)$? I don't understand why you only substitute the first $X$ from the $E(X)$ formula and not the one inside the probability function?

Let us say $X$ is a discrete random variable. Let $Y=X^2$. Then
$$E(X^2) = E(Y) = \sum_y y \Pr(Y = y) = \sum_y y \Pr(X^2 = y).$$
Let $x = \sqrt{y}$. Then $y=x^2$ and we have,
$$E(X^2) = \sum_x x^2 \Pr(X^2 = x^2)= \sum_x x^2 \Pr(X = x)=\sum x^2 P(x).$$
