Expectation, Variance & Moments

the computational formula for variance

The definition Var(X) = E[(X - mu)^2] is honest but clumsy in practice: you first compute the mean mu, then go back through every value to square its deviation. A little algebra turns that two-pass chore into a one-pass formula that is almost always how variance is actually calculated.

Expand the square: E[(X - mu)^2] = E[X^2 - 2 mu X + mu^2] = E[X^2] - 2 mu E[X] + mu^2. Since E[X] = mu, the last two terms collapse to -2 mu^2 + mu^2 = -mu^2, leaving Var(X) = E[X^2] - (E[X])^2. In words: the average of the squares minus the square of the average. You only need two numbers — E[X^2] (computed by LOTUS) and E[X] — and you are done. This is sometimes remembered as 'mean of the square minus square of the mean'.

Because variance can never be negative, this formula carries a built-in sanity check: E[X^2] is always at least (E[X])^2. (That inequality is exactly Jensen's inequality for the convex function g(x) = x^2, and equality holds only when X is a constant.) One numerical warning for real computations: when E[X^2] and (E[X])^2 are both large and nearly equal, subtracting them can lose precision badly — statisticians use more stable algorithms in that regime — but for hand calculations the formula is a gift.

Fair die: E[X] = 3.5 and E[X^2] = 91/6 ≈ 15.167. Then Var(X) = 91/6 - (7/2)^2 = 91/6 - 49/4 = (182 - 147)/12 = 35/12 ≈ 2.917. The shortcut needs no list of deviations.

Variance = mean of the square minus square of the mean: E[X^2] - (E[X])^2.

If you ever compute E[X^2] - (E[X])^2 and get a negative number, you have made an arithmetic error — variance can never be negative, since E[X^2] >= (E[X])^2 always.

Also called
shortcut formulaE[X^2] - (E[X])^2變異數捷徑公式