The expected value
A random variable attaches a number to each outcome of an experiment (lesson 5.2.1). Its probability mass function (pmf), , gives the chance of each value . The expected value of weights each value by its chance and adds up.
Rule: Expected value
The sum runs over every value can take. is also called the mean of and written (mu). It has the units of : dollars, days, dots on a die.
For a fair die, each face from 1 to 6 has probability :
| 1 | 2 | 3 | 4 | 5 | 6 | |
|---|---|---|---|---|---|---|
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | |
| 1/6 | 2/6 | 3/6 | 4/6 | 5/6 | 6/6 |
The last row adds up to . No roll ever shows 3.5: an expected value need not be a value can take.
A game with a negative expected value
Roll a die. You win $4 on a six and lose $1 on anything else. Your winnings are 4 with probability and with probability , so
That is a loss of about $0.17 a game: the game loses money on average. A prize of $5 would make it fair, with . A constant , which takes one value with probability 1, has .
Try it
expected is the rule: a sum of value times probability. Fraction keeps exact fractions, so the die prints 7/2.
The last line averages the two possible winnings without their probabilities. That gives 1.5, which is wrong (common mistake 1).
The balance point and the long-run average
Picture the pmf as bars standing on a ruler, each as heavy as its probability. The expected value is the point where the ruler balances. A fair die balances in the middle, at 3.5.
Each pmf balances at its expected value. The die is symmetric, so it balances in the middle. The waiting time is most often 1, but its long tail pulls the balance point out to 3.
Now count the rolls until a 5 or a 6 first appears. That count is geometric with (lesson 5.2.2), and one roll is the most likely count. Yet the mean is 3: the balance point is not the tallest bar.
The long-run average
Roll the die times and average the results. Each face turns up in about of the rolls, so the average is close to . As grows, the share of each face settles on its probability, and the average settles on .
That is what an expected value means in practice: the average result per try over a great many tries. Lesson 5.7.2 states it precisely as the law of large numbers, and case study 5.3.5 averages 1,000 daily returns this way.
Try it
100,000 simulated rolls from one seeded run. rng.integers(1, 7) draws whole numbers from 1 to 6: the upper end, 7, is left out.
The average of the first rolls wanders at first, then settles near 3.5. The last line plays the game 100,000 times: the average winnings are , close to .
When the sum is infinite
The sum in the rule can fail to settle. Toss a coin until the first head. If that takes tosses, which has probability , you win dollars.
Each term of the sum is , so the expected value is . That series diverges (lesson 1.5.3), so the game has no finite expected value. If it paid nothing after 10 tails in a row, the expected value would be exactly $10: one dollar for each toss allowed.
A simulation shows the symptom: averages never settle. Rare long runs of tails pay huge amounts, so the more games you play, the larger the typical average.
Try it
For each number of games , the cell plays 100 separate runs of games. It prints the median of the 100 averages, the middle one once they are sorted. The number of tosses is geometric with .
In this seeded run the median grows by about 3 each time is multiplied by 10. It does not settle, because there is no number to settle on.
The means of module 5.2's distributions
The same sum gives the mean of each distribution of module 5.2.
| distribution | values | |
|---|---|---|
| Bernoulli() | 0 or 1 | |
| 0 to | ||
| , trials to the first success | 1, 2, 3, … | |
| 0, 1, 2, … |
A Bernoulli variable is 1 with probability and 0 otherwise, so . The cell checks the other three, and lesson 5.3.2 shows why the binomial gives .
Each mean reads naturally. Ten trials with give 3 successes on average, and waiting for a six takes 6 rolls on average. A Poisson count of rare events with rate averages 2.5.
Try it
The binomial sum has 11 terms. The geometric and Poisson sums have infinitely many, so the cell adds enough terms for the rest to be tiny.
For the geometric, the sums of the first 10, 20, 50 and 200 terms climb to 6. SciPy's .mean() gives each answer directly.
The expected value of a function: LOTUS
A function of a random variable is another random variable. If is a die roll, its square is one, and so were the game's winnings. To find you could work out the pmf of first, but you do not need to.
Rule: LOTUS
Weight each value by the probability of . The name is short for the law of the unconscious statistician, because people use it without noticing that it is a rule.
Here is the same answer found both ways. Let take the values , 0, 1 and 2, each with probability , and let .
| 0 | 1 | 2 | ||
|---|---|---|---|---|
| 1/4 | 1/4 | 1/4 | 1/4 | |
| 1 | 0 | 1 | 4 |
- With LOTUS: .
- Through the pmf of : is 0 with probability , 1 with probability (from and ), and 4 with probability . So , the same.
The second way had to merge the two values of that give . LOTUS never needs that step.
For a fair die, LOTUS gives . With it gives .
Try it
expect_g is LOTUS: it applies g to each value and weights by . The second line builds the pmf of by hand and agrees.
Then the die, exactly and from 100,000 seeded rolls: 15.2204 and 0.4073.
The mean of is not of the mean
The mean of the squares is not the square of the mean. For the die, , but . They differ by , a number lesson 5.3.2 calls the variance.
The same happens with : , but . Putting the mean into works only for straight lines, (lesson 5.3.2).
Case study 2.4.5 met this with . A fair flip of $20,000 on $100,000 has expected log wealth 11.4925, below . Lesson 5.7.1 shows which way the gap goes for curves that bend up or down: Jensen's inequality.
Try it
Each line prints and then for the die, as exact fractions.
Only the straight line, , gives the same number twice.
Common mistakes
- Weight by the probabilities. Averaging the game's two outcomes, 4 and , gives 1.5; the expected value is .
- Check that the probabilities add up to 1 before trusting an expected value.
- Do not round a mean to a possible value. A die's mean is 3.5, not 3 or 4.
- The mean of a function is not the function of the mean. is larger than unless never varies.
- In LOTUS, weight by the probabilities of . If you build the pmf of instead, add up the probabilities of every that gives the same .
- A simulated average can mislead. When the sum for diverges, averages never settle. Check the sum, not only a simulation.
Expected values and LOTUS
0 of 12 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- : each value weighted by its probability, in the units of . It is the balance point of the pmf and the long-run average of many draws.
- A mean need not be a possible value, it can be negative, and it fails to exist when the sum diverges.
- Means: Bernoulli , binomial , geometric (trials to the first success), Poisson .
- LOTUS: , with no need for the pmf of .
- In general : for the die, against . Straight lines are the exception.