1.3.8 · D2Probability & Statistics

Visual walkthrough — Expectation, variance, and standard deviation

1,934 words9 min readBack to topic

This page builds, from nothing, the rule that measures how spread out a random variable is — and its famous shortcut. We will not use a single symbol before it has a picture attached: we first meet the averaging operator, then the spread measure, then its shortcut, then its square-root cousin. By the end you will see why we square, why the shortcut is true, and what happens in the strange cases (a constant, a rescaled variable, two variables added together).

Parent: Expectation, variance, and standard deviation. If the words "random variable" or "probability" feel new, read random variables & distributions first.


Step 1 — A random variable is dots on a number line

WHAT. A random variable is just a rule that spits out a number when you run an experiment. Roll a die → you get one of . Each possible number has a weight : how often it shows up in the long run. All weights are between and and they add to .

WHY. Before we can talk about "spread," we need something to spread. Picture the possible values as dots sitting on a horizontal number line, and let the size of each dot be its probability. Big dot = happens often.

PICTURE. Six equal dots for a fair die — each carries weight .

Figure — Expectation, variance, and standard deviation

Step 2 — Expectation is the balance point

WHAT. The expectation is the balance point of those weighted dots:

WHY. Imagine the number line is a see-saw and each dot is a physical weight sitting at position . The point where the see-saw balances is exactly . That is the single number that best represents "where the values sit." For a fair die it lands at — between and , because the weights are symmetric.

PICTURE. A triangular pivot ▲ slid under the dots until they balance, at .

Figure — Expectation, variance, and standard deviation

Step 3 — Deviation: how far each dot sits from the pivot

WHAT. For each value define its deviation This is a signed arrow from the pivot to the dot: positive (pointing right) if , negative (pointing left) if , zero if the dot sits on the pivot.

WHY. "Spread" should mean "how far are the dots from the center, typically." So the raw material we need is the collection of distances . But there is a trap: if we just average the signed deviations we get Every distribution! The left arrows exactly cancel the right arrows — that is literally what "balance point" meant in Step 2. So the naive average distance is always zero and tells us nothing. We must kill the signs.

PICTURE. Blue arrows pointing left (negative ), pink arrows pointing right (positive ), summing to zero.

Figure — Expectation, variance, and standard deviation

Step 4 — Square each arrow to remove the sign

WHAT. Replace each signed arrow by its square . Geometrically, an arrow of length becomes a square with side and area . Area is never negative, so both left and right arrows now contribute positively.

WHY squaring, not absolute value? Two reasons, both visible in the picture.

  1. Squares can't cancel. A left arrow and a right arrow of the same length give the same area, so they add up instead of cancelling.
  2. Smooth algebra. has a sharp kink at (no clean slope there), which wrecks calculus. is a smooth bowl — you can differentiate it everywhere. That smoothness is exactly what gradient descent and MSE loss rely on.

The absolute-value version exists (Mean Absolute Deviation) but loses these two gifts.

PICTURE. Each arrow grows into a shaded square; long arrows become much bigger squares (area grows like length²), so far-off values are emphasized.

Figure — Expectation, variance, and standard deviation

Step 5 — Variance is the average of the squares

WHAT. The variance is the probability-weighted average of those square areas:

WHY. Big squares that happen often (big area × big weight) dominate; rare far-out values contribute area but only a little weight. So variance is the typical square-area — one number summarizing the spread. It is the balance point of the squares, just as was the balance point of the values.

PICTURE. The see-saw again, but now the weights are the square areas; the balance point of those areas is .

Figure — Expectation, variance, and standard deviation

Step 6 — The shortcut:

WHAT. Expand the square inside the expectation. Watch each term:

Take expectation of each piece. Expectation is linear (it passes through and pulls out constants), and is just a fixed number:

Combine the last two:

WHY this form? To compute it you only need two easy averages — the average of (gives ) and the average of — then subtract . No need to compute every deviation. Note always, so this is guaranteed : that inequality is Step 5's non-negativity in disguise.

PICTURE. Left tower = (average height of the squared values). We chop off a block of height ; what remains is the variance.

Figure — Expectation, variance, and standard deviation

Step 7 — Edge cases: constant, rescale, and shift

WHAT & WHY. A formula you don't test at the extremes is a formula you don't understand. Three degenerate inputs:

  • A constant (all weight on one dot). No spread: every square area is .
  • Rescale (stretch the line by factor ). Every arrow length scales by , so every area scales by : For the standard deviation this becomes — the absolute value appears because the square root of is , not . (This matters for feature scaling: dividing by makes the new SD exactly .)
  • Shift (slide every dot right by ). The pivot slides by too, so distances don't change:

PICTURE. Three mini-boards: a lone dot (variance ), a stretched set of squares ( bigger), a slid set (identical squares).

Figure — Expectation, variance, and standard deviation

The one-picture summary

Values on a line → find the balance point → measure signed arrows (they cancel!) → square them into areas → average the areas = variance → algebra rewrites it as → square-root gives SD in original units.

Figure — Expectation, variance, and standard deviation
Recall Feynman retelling — say it like a story

Picture beads on a wire, each bead heavier if it happens more often. Slide a pivot under the wire until it balances — that spot is the mean. Now I want to know "how scattered are the beads?" My first idea: measure how far each bead is from the pivot and average those distances. But that's always zero — the beads on the left pull the average down exactly as much as the beads on the right pull it up; it's the balance point, after all. So I cheat the signs away by squaring each distance, turning every arrow into a little square whose area can't be negative. I average those square-areas, weighting by how often each bead shows up — that average is the variance. Squaring also punishes far-away beads extra hard, and it keeps the math smooth so calculus works. Finally, since I squared the distances, the units got squared too (metres became metres²), so I take a square root at the end to get the standard deviation, back in honest units. A clever algebra trick, expanding , shows the whole thing equals "average of the squares minus the square of the average," which is the fast way to compute it. Constants have zero variance (no scatter), stretching the wire by multiplies variance by , and sliding it sideways changes nothing.

Recall Quick self-test

Why is the average signed deviation always zero? ::: Because is the balance point, so left and right deviations cancel: . Why square instead of absolute value? ::: Squares can't cancel by sign and are smooth (differentiable), giving clean algebra and calculus. State the shortcut formula. ::: . What is ? ::: — the shift does nothing, the scale enters squared. Why take the square root for SD? ::: To undo the squaring and return to the original data units.