Skip to content

Expectation and variance

Two numbers describe most of what you need from a distribution. Compute them, combine them, and see why planning on the average can mislead.

Introductory ~10 min8 steps

What runs in CodeSplash

You will be able to

  • Compute an expected value and a variance from a table of probabilities
  • Apply the rules for scaling and adding random variables
  • Explain why an expected value isn't what you should expect to get

Read first

01

The long-run average

Read

The expected valueExpected valueA random variable's probability-weighted average, where the long-run average of many draws settles. of a random variable is its probability-weighted average: where the long-run average of many draws settles.

E[X]=∑xx Pr⁡(X=x)E[X] = \sum_x x \, \Pr(X = x)

A fair die gives E[X]=(1+2+3+4+5+6)/6=3.5E[X] = (1 + 2 + 3 + 4 + 5 + 6)/6 = 3.5, a value you can never roll. That's fine: it's a balance point, not a forecast of one roll.

02

Should you play?

Predict

Predict first

A game costs 3 to play. It pays 10 with probability 1/4, and nothing otherwise. Should you play, going by the average?

Play: you gain on averageSkip: you lose on averageIt makes no difference on average
Reveal

Skip it. You expect to win 10×1/4=2.510 \times 1/4 = 2.5 and you pay 3, so the expected gain per game is −0.5-0.5. You'll sometimes win, but over many games you lose.

03

Spread: variance

Read

The varianceVarianceThe average squared distance from the mean; the SD squared. is the expected squared distance from the mean, and the standard deviation is its square root:

Var⁡(X)=E[(X−E[X])2]\operatorname{Var}(X) = E\left[(X - E[X])^2\right]

For the die, the squared distances average 35/12≈2.9235/12 \approx 2.92, so the standard deviation is about 1.711.71.

These rules carry a lot of statistics:

E[aX+b]=aE[X]+b,Var⁡(aX+b)=a2Var⁡(X)E[aX + b] = aE[X] + b, \qquad \operatorname{Var}(aX + b) = a^2\operatorname{Var}(X)

If XX and YY are independent, Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)\operatorname{Var}(X + Y) = \operatorname{Var}(X) + \operatorname{Var}(Y).

04

The flaw of averages

Explore

Now plan with an uncertain demand and price. Guess first. Then compare Plugging in averages with Average profit, change Capacity, and watch Chance of a loss.

DExplorable · Monte Carlo risk and the flaw of averages

If you plan on average demand and average price, how wrong can the average plan be?

Compared with plugging in average demand and price, will the average simulated profit be…

How sure?
250
2.0
1000

You can't sell more than you can make.

5000
plug-in 2000average 1186break even

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

05

An expected value isn't a promise

Explore

Average profit in a simulated stocking decision is 3,357 across 5,000 scenarios. The standard deviation is 1,653, and the middle 90% of outcomes runs from 167 to 5,599. Plan for the range as well as for the average.

06

Check your reading

Checkpoint

Check yourself

You flip a fair coin three times. What is the expected number of heads?

Show the answer

Answer: 1.5

0×1/8+1×3/8+2×3/8+3×1/8=12/8=1.50 \times 1/8 + 1 \times 3/8 + 2 \times 3/8 + 3 \times 1/8 = 12/8 = 1.5. Or use three flips times a half.

Check yourself

XX has a mean of 10. What is the mean of 2X+32X + 3?

Show the answer

Answer: 23

2×10+3=232 \times 10 + 3 = 23.

Check yourself

Independent XX and YY have standard deviations 3 and 4. What is the variance of X+YX + Y?

Show the answer

Answer: 25

Variances add, standard deviations don't: 9+16=259 + 16 = 25, so the standard deviation of the sum is 5, not 7. This is where the standard error of a difference comes from.

07

Look at your own columns

In the app

For a column of data, the mean and standard deviation estimate these two numbers. Before you trust them, look at the shape: a heavy tail can make the mean a poor summary.

08

Recap

Recap
  • E[X]E[X] is the long-run average, and it may be a value that can never occur.
  • Means add up. Variances add up too, but only for independent variables, and scaling by aa multiplies variance by a2a^2.
  • Plugging averages into a nonlinear plan can give the wrong answer. Simulate the uncertainty.

Concepts in this lesson