Search

Search papers and lessons

Expected Value

Level 1 · 8 min read

The expected value of a random variable is its long-run average: each possible outcome weighted by how likely it is, then summed.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Sign in to see your progress

TL;DR

The expected value of a random variable is the average result you get if you repeat the experiment a very large number of times. You compute it by taking every possible outcome, multiplying it by its probability, and adding the results up. It is a single number that summarises where a random quantity tends to sit.

Expected value is not necessarily a value the variable can actually take. The average roll of a die is 3.5, and no single roll ever shows 3.5.

Where you'll see it: in the expected payoff of a bet, in the average loss a model is trained to minimise, and in the mean that the variance and the law of large numbers are built on.

Intuition

Suppose a shop sells a box of cereal with a toy inside. Each box holds one of three toys, each equally likely. If the toy is worth 1, 2 or 5 dollars to a collector, what is a box worth on average?

You could open a thousand boxes, add up the values, and divide by a thousand. The answer would be close to the same number every time you tried. You do not need to open them to know it, though. A third of the boxes give 1, a third give 2 and a third give 5, so the average is roughly one third of each: 13(1)+13(2)+13(5)=2.67\frac{1}{3}(1) + \frac{1}{3}(2) + \frac{1}{3}(5) = 2.67. Each outcome counts in proportion to how often it shows up.

That is the whole idea. The expected value is a weighted average where the weights are probabilities. It answers the question "if I could repeat this many times, what would the average tend to be?", and it answers that question before any repetition happens.

It is useful for two reasons. It gives a single summary of a random quantity, the way the mean does for a list of numbers. And it is linear, which makes it easy to compute for complicated combinations of random things, as the examples below show.

flowchart LR
  A[Each outcome x] --> B[Multiply by its probability p of x]
  B --> C[Add all of these products]
  C --> D[Expected value]

The math

Discrete definition

Definition: Expected value (discrete)

Let XX be a random variable that takes values x1,x2,…x_1, x_2, \dots with probabilities p(x1),p(x2),…p(x_1), p(x_2), \dots. Its expected value, written E[X]\mathbb{E}[X], is

E[X]=∑ixi p(xi).\mathbb{E}[X] = \sum_{i} x_i \, p(x_i).

The symbol ∑i\sum_i means "add up over all the possible outcomes", as explained in summation notation. Each xix_i is a value the variable can take. Each p(xi)p(x_i) is the probability of that value, and the probabilities must add to 1. The sum is only defined when the outcomes are finite, or when the sum converges.

Expectation of a function

Often you care about a function of XX, such as the squared error or the payoff of a bet. The rule is the same: weight the function's values by the probabilities of XX.

E[g(X)]=∑ig(xi) p(xi).\mathbb{E}[g(X)] = \sum_{i} g(x_i) \, p(x_i).

Note that E[g(X)]\mathbb{E}[g(X)] is generally not g(E[X])g(\mathbb{E}[X]). We will see the difference in the tradeoffs section.

Linearity

Expected value is linear. For any constants aa and bb, and any two random variables XX and YY (whether or not they are independent):

E[aX+b]=a E[X]+b,E[X+Y]=E[X]+E[Y].\mathbb{E}[aX + b] = a\,\mathbb{E}[X] + b, \qquad \mathbb{E}[X + Y] = \mathbb{E}[X] + \mathbb{E}[Y].

The second rule is the important one. It says the expected value of a sum is the sum of the expected values, with no condition on how the two variables relate. This is what makes expectation so easy to work with.

Continuous definition

When XX has a probability density f(x)f(x) instead of discrete outcomes, the sum becomes an integral, as in the definite integral:

E[X]=∫−∞∞x f(x) dx.\mathbb{E}[X] = \int_{-\infty}^{\infty} x \, f(x) \, dx.

The idea is identical. The density plays the role of the probabilities, and the integral adds up the weighted values.

Worked examples

Example
A fair die

A fair six-sided die has outcomes 1 to 6, each with probability 16\frac{1}{6}.

  1. Write the definition: E[X]=∑i=16xi p(xi)\mathbb{E}[X] = \sum_{i=1}^{6} x_i \, p(x_i).
  2. Substitute the probabilities: E[X]=16(1+2+3+4+5+6)\mathbb{E}[X] = \frac{1}{6}(1 + 2 + 3 + 4 + 5 + 6).
  3. Add the values: 1+2+3+4+5+6=211 + 2 + 3 + 4 + 5 + 6 = 21.
  4. Divide: E[X]=216=3.5\mathbb{E}[X] = \frac{21}{6} = 3.5.

Interpretation: if you roll the die many times, the average of your rolls settles near 3.5. No single roll is 3.5, but that is the centre of mass of the outcomes.

Example
A biased game

You pay 1 dollar to play. With probability 0.1 you win 10 dollars back (a net gain of 9), and with probability 0.9 you win nothing (a net loss of 1). Is the game worth playing?

  1. Let YY be your net gain. The values are 99 with probability 0.10.1 and −1-1 with probability 0.90.9.
  2. Compute: E[Y]=9×0.1+(−1)×0.9\mathbb{E}[Y] = 9 \times 0.1 + (-1) \times 0.9.
  3. Multiply out: 9×0.1=0.99 \times 0.1 = 0.9 and (−1)×0.9=−0.9(-1) \times 0.9 = -0.9.
  4. Add: 0.9+(−0.9)=00.9 + (-0.9) = 0.

Interpretation: the expected net gain is zero, so the game is fair. You neither gain nor lose on average. A game where the expected value is negative is one you should not play repeatedly.

Example
Using linearity on a sum of dice

Roll two fair dice and add the results. What is the expected total?

  1. Let X1X_1 and X2X_2 be the two dice. Each has E[Xj]=3.5\mathbb{E}[X_j] = 3.5, from the first example.
  2. Apply linearity: E[X1+X2]=E[X1]+E[X2]\mathbb{E}[X_1 + X_2] = \mathbb{E}[X_1] + \mathbb{E}[X_2].
  3. Substitute: 3.5+3.5=73.5 + 3.5 = 7.

Interpretation: you did not need to list the 36 combinations. Linearity lets you add the averages directly, and it would work just as well if the two dice were dependent. The total itself is spread across 2 to 12.

Tradeoffs and failure modes

The expected value is a good summary, but it hides information. Use it with care.

SituationWhat goes wrongBetter choice
Outcomes are very spread out, such as a rare large lossThe average can look fine while a single bad event ruins youLook at the variance or the worst case as well
The distribution is heavily skewedThe mean is pulled toward the tail and may not be typicalUse the median or the full distribution
You want E[g(X)]\mathbb{E}[g(X)] but compute g(E[X])g(\mathbb{E}[X])These are equal only for linear gg; for a convex gg the second is smaller (see [[convex-functionconvex functions]])
The expectation does not exist (the sum or integral diverges)The average does not settle, so a sample average never convergesUse a different summary, or check the tail behaviour first
You have only a few samplesThe sample average is noisy and can be far from the true expected valueReport the uncertainty, not just the average

Expected value also says nothing about any single trial. A game with expected value zero can still bankrupt you on one bad day. That is the reason variance matters.

History

Expected value grew out of gambling problems. In the 1650s, Blaise Pascal and Pierre de Fermat corresponded about how to divide the stake of an interrupted game of chance fairly, and Christiaan Huygens published a short treatise on the subject in 1657 that set out the idea of an expected gain. The concept was later named "expectation" and then "expected value".

Its link to averages was made rigorous later. Jakob Bernoulli's Ars Conjectandi, published in 1713, contained an early form of the law of large numbers. That result says sample averages converge to the expected value, and it is the reason the concept is trusted as a description of long-run behaviour. The modern measure-theoretic definition came in the twentieth century, but the basic recipe, weight each outcome by its probability and add, has not changed.

Check yourself

QuestionA fair coin pays you 4 dollars for heads and costs you 2 dollars for tails. What is the expected payoff?Show answer

Heads and tails each have probability 12\frac{1}{2}. The expected value is 12(4)+12(−2)=2−1=1\frac{1}{2}(4) + \frac{1}{2}(-2) = 2 - 1 = 1. On average you gain 1 dollar per flip.

QuestionA fair die has expected value 3.5. What is the expected value of 2X+32X + 3, where XX is the roll?Show answer

By linearity, E[2X+3]=2 E[X]+3=2(3.5)+3=10\mathbb{E}[2X + 3] = 2\,\mathbb{E}[X] + 3 = 2(3.5) + 3 = 10. You did not need to compute the distribution of 2X+32X + 3, only the expectation of XX.

QuestionWhy is the expected value of the sum of two dependent random variables still the sum of their expected values?Show answer

Linearity of expectation does not depend on independence. Writing E[X+Y]=∑(x+y) p(x,y)\mathbb{E}[X + Y] = \sum (x + y) \, p(x, y) and splitting the sum into ∑x p(x,y)\sum x \, p(x,y) and ∑y p(x,y)\sum y \, p(x,y) gives E[X]+E[Y]\mathbb{E}[X] + \mathbb{E}[Y] for any joint distribution. Dependence matters for variance, not for the mean.

QuestionA lottery pays 1000 dollars with probability 0.001 and nothing otherwise. A ticket costs 1 dollar. Compute the expected net gain, and say whether a person who values money linearly should buy it.Show answer

The net gain is 999999 with probability 0.0010.001 and −1-1 with probability 0.9990.999. The expected value is 999×0.001+(−1)×0.999=0.999−0.999=0999 \times 0.001 + (-1) \times 0.999 = 0.999 - 0.999 = 0. The ticket is fair in expectation, so a person who values money linearly is indifferent. In practice, people who worry about the chance of losing a dollar, or who weigh the large win differently, may decline it.

Sources