Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 37 · Probability Distributions

Discrete Random Variables and Expected Value

Learn probability distributions for discrete random variables, how to compute expected value, variance and standard deviation, and how they scale.

A random variable is a number produced by a random process: the value of a die, the number of heads in ten flips, the number of customers in an hour. It is discrete when it takes separate values you can list (0, 1, 2, ...), as opposed to continuous values like heights.

A probability distribution lists every possible value with its probability. The probabilities must be between 0 and 1 and must add to exactly 1. With a distribution you can compute the long-run average, called the expected value, and measure how spread out the outcomes are.

A distribution as a table

Let X be the value shown by a fair die.

x 1 2 3 4 5 6
P(X = x) 1/6 1/6 1/6 1/6 1/6 1/6

Another example: X = number of heads in two fair coin flips.

x 0 1 2
P(X = x) 1/4 1/2 1/4

Expected value

The expected value (or mean) of X is each value weighted by its probability:

Text
E(X) = Σ x · P(X = x)

For the die: E(X) = (1 + 2 + 3 + 4 + 5 + 6)/6 = 3.5. You never roll 3.5; it is the long-run average. For the two-coin example: 0 × 1/4 + 1 × 1/2 + 2 × 1/4 = 1.

Variance and standard deviation

The variance measures spread around the mean:

Text
Var(X) = Σ (x - μ)² · P(X = x) = E(X²) - μ²

where μ = E(X). The standard deviation is σ = √Var(X). For the die, E(X²) = 91/6, so Var(X) = 91/6 - 3.5² = 35/12 ≈ 2.917 and σ ≈ 1.708.

Python Expected value, variance and standard deviation from a table

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Fair games

A game costs $2 to play. You roll a die: a six wins $6, anything else wins nothing. Let W be your winnings before the cost:

Text
E(W) = 6 × 1/6 + 0 × 5/6 = 1

Net result per play: 1 - 2 = -1. On average you lose one dollar each play. A game is fair if the expected net gain is zero. Casinos and lotteries are designed so that it is negative for the player.

Python Simulate the game and compare with E(X)

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Linear transformations

If you change every value of X, the mean and variance change in predictable ways. For constants a and b:

Text
E(aX + b) = a·E(X) + b
Var(aX + b) = a² · Var(X)

Adding b shifts everything and does not change the spread. Multiplying by a scales the spread by a (standard deviation by |a|). Example: a die shows X and a game pays 2X + 1 dollars. Then E = 2 × 3.5 + 1 = 8 and Var = 4 × 35/12 = 35/3.

For the sum of two independent random variables, E(X + Y) = E(X) + E(Y) always, and Var(X + Y) = Var(X) + Var(Y).

Expected values always add, even for dependent variables. Variances add only when the variables are independent.

Python Check the linear rules by exact calculation

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. A distribution has P(1) = 0.2, P(2) = 0.5, P(3) = 0.3. What is E(X)?

    0.2 × 1 + 0.5 × 2 + 0.3 × 3 = 0.2 + 1.0 + 0.9 = 2.1.
  2. 2. What must the probabilities in a discrete distribution add up to?

    Something must happen, so all probabilities together make 1.
  3. 3. E(X) = 5 and Var(X) = 4. What is Var(3X + 2)?

    Var(aX + b) = a² Var(X) = 9 × 4 = 36. Adding 2 does not change the variance.
  4. 4. A game costs $3 to play and pays $10 with probability 0.2, otherwise nothing. The expected net gain per play is...

    E(win) = 10 × 0.2 = 2, and 2 - 3 = -1, so you lose $1 per play on average.

Summary

  • A discrete random variable has a distribution: values with probabilities adding to 1.
  • E(X) = Σ x P(x) is the long-run average.
  • Var(X) = E(X²) - μ²; the standard deviation is its square root.
  • E(aX + b) = aE(X) + b and Var(aX + b) = a² Var(X).
  • A game is fair when the expected net gain is zero.

Next: The Binomial Distribution