Find a course

Module 3: Random VariablesLesson 5 of 1214 min

Random Variables and Expected Value

Turn outcomes into numbers with random variables, describe them with PMFs and CDFs, and compute expected values for games, insurance and decisions.

Step 1 of 14Learn

From outcomes to numbers

Flip a coin three times. The sample space has 8 outcomes such as HTH and TTH. Often you don't care about the exact sequence, only about a number: how many heads came up, or how much money you won. A random variable is a rule that assigns a number to each outcome.

Let X = number of heads in three flips. Then X(HHH) = 3, X(HTH) = 2, X(TTT) = 0, and so on. Grouping outcomes by their value of X gives its probability mass function (PMF), the list of P(X = x) for each possible value:

x0123
P(X = x)1/83/83/81/8

A valid PMF has every value between 0 and 1, and the values add to exactly 1.

The cumulative distribution function (CDF) accumulates the PMF: F(x) = P(X ≤ x). Here F(0) = 1/8, F(1) = 4/8, F(2) = 7/8 and F(3) = 1. The CDF always rises from 0 to 1, never decreasing. It answers "at most" questions directly, and "at least" questions through the complement: P(X ≥ 2) = 1 − F(1) = 1/2.

Random variables that take separate, countable values (counts, dice totals, numbers of customers) are discrete. Those that can take any value in a range (heights, times, temperatures) are continuous, and they are handled with areas under a curve, as you'll see later.

Step 2 of 14Practice · Fill in the blanks

Fill in the blanks

For the number of heads X in three fair coin flips, P(X ≤ 1) = and P(X ≥ 1) = .

Step 3 of 14Chart

Distribution of X = number of heads in 3 flips

The probability mass function as bars. The bars add up to 1, and the balance point of the picture is the mean, 1.5.

Distribution of X = number of heads in 3 flipsBar chart with 4 categories: 0: 0.125; 1: 0.375; 2: 0.375; 3: 0.125.00.10.20.30.4Probability0123Heads0.1250.3750.3750.125
Distribution of X = number of heads in 3 flips
HeadsP(X = x)
00.125
10.375
20.375
30.125

Step 4 of 14Learn

Expected value: the long-run average

The expected value (mean) of a discrete random variable is the probability-weighted average of its values:

E[X] = Σ x · P(X = x)

For three coin flips: E[X] = 0(1/8) + 1(3/8) + 2(3/8) + 3(1/8) = 12/8 = 1.5 heads.

For a fair die: E = (1 + 2 + 3 + 4 + 5 + 6)/6 = 3.5.

Neither 1.5 heads nor 3.5 pips can happen on a single trial. The expected value is not the "most likely" result; it is the long-run average over many repetitions. Roll a die 6,000 times and the average roll will be very close to 3.5.

Expected value is the standard tool for judging bets and decisions with uncertain payoffs.

Roulette. A $1 bet on red at an American wheel (18 red, 18 black, 2 green) wins $1 with probability 18/38 and loses $1 with probability 20/38:

E = (+1)(18/38) + (−1)(20/38) = −2/38 ≈ −$0.053.

On average, you lose about 5.3 cents per dollar bet. That is the house edge, and it's why the casino can be certain of a profit over millions of bets while individual players win some nights.

Step 5 of 14Practice · Work it out

A raffle sells 1,000 tickets at $5 each. One ticket wins $2,000 and two tickets win $500 each. What is the expected net gain, in dollars, of buying one ticket? (Use a negative number for a loss.)

Step 6 of 14Try the calculator

Expected value of a simple bet

A bet wins an amount W with probability p and otherwise loses your stake S. Try roulette (p = 18/38 ≈ 0.4737, W = 1, S = 1) or a fair coin.

Expected value per bet
-0.0526 $
Expected result of 1,000 bets
-53 $
Break-even win probability
0.5

Step 7 of 14Learn

Expected value of a function

Often you need the mean of something computed from X, such as a payoff, a cost or X2. The rule is simple: apply the function to each value, then weight by the same probabilities.

E[g(X)] = Σ g(x) · P(X = x)

Example. For a fair die, E[X2] = (1 + 4 + 9 + 16 + 25 + 36)/6 = 91/6 ≈ 15.17. Notice that E[X2] is not (E[X])2 = 3.52 = 12.25. In general, E[g(X)] ≠ g(E[X]) unless g is a straight line. The gap between E[X2] and (E[X])2 will turn out to be the variance.

This matters in practice. Suppose a factory's daily cost is C = 100 + 2X2, where X is the number of breakdowns. Plugging in the average number of breakdowns underestimates the average cost, because days with many breakdowns cost disproportionately more.

Insurance. A phone worth $800 has a 5% chance of being destroyed in a year. Expected loss = 0.05 × 800 = $40. An insurer charging $70 a year makes an expected $30 per customer. Is buying it irrational? Not necessarily. Expected value ignores risk: losing $800 might be a hardship you'd pay to avoid. Expected value is the right guide for small, repeated bets, and a starting point, not the whole story, for rare large losses.

Step 8 of 14Diagram

Computing E[g(X)] in four moves

Computing E[g(X)] in four movesProcess diagram: List values x → Apply g to each → Weight by P(X = x) → Add the products.List values xApply g toeachWeight by P(X= x)Add theproducts

Tap a shape with to see more.

List values x

Every value X can take, with its probability.

Apply g to each

For example g(x) = x2 or a payoff rule.

Weight by P(X = x)

Use the original probabilities; they do not change.

Add the products

E[g(X)] = Σ g(x)·P(X = x). In general this is not g(E[X]).

Step 9 of 14Note

Step 10 of 14Practice · Work it out

You roll two fair dice. What is the expected value of their sum?

Step 11 of 14Practice · True or false

If X is a random variable, then E[X2] is always equal to (E[X])2.

Step 12 of 14Note

Step 13 of 14Chart

The blender warranty in dollars

The gap is the store's expected profit per warranty, about $35.

The blender warranty in dollarsBar chart with 2 categories: Warranty price: $45; Expected repair cost: $9.6.$0$10$20$30$40$50Warranty priceExpected repair cost$45$9.6
Uses the callout's assumptions: 8% chance of a covered failure, about $120 per repair.
The blender warranty in dollars
ItemDollars
Warranty price$45
Expected repair cost$9.6

Step 14 of 14Practice · Choose one

A game costs $2 to play. You roll one die: a 6 pays $9, a 5 pays $3, anything else pays nothing (all payouts are in addition to losing the $2 fee). What is the expected net gain per game?