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: . 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
Let be a random variable that takes values with probabilities . Its expected value, written , is
The symbol means "add up over all the possible outcomes", as explained in summation notation. Each is a value the variable can take. Each 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 , 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 .
Note that is generally not . We will see the difference in the tradeoffs section.
Linearity
Expected value is linear. For any constants and , and any two random variables and (whether or not they are independent):
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 has a probability density instead of discrete outcomes, the sum becomes an integral, as in the definite integral:
The idea is identical. The density plays the role of the probabilities, and the integral adds up the weighted values.
Worked examples
A fair six-sided die has outcomes 1 to 6, each with probability .
- Write the definition: .
- Substitute the probabilities: .
- Add the values: .
- Divide: .
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.
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?
- Let be your net gain. The values are with probability and with probability .
- Compute: .
- Multiply out: and .
- Add: .
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.
Roll two fair dice and add the results. What is the expected total?
- Let and be the two dice. Each has , from the first example.
- Apply linearity: .
- Substitute: .
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.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Outcomes are very spread out, such as a rare large loss | The average can look fine while a single bad event ruins you | Look at the variance or the worst case as well |
| The distribution is heavily skewed | The mean is pulled toward the tail and may not be typical | Use the median or the full distribution |
| You want but compute | These are equal only for linear ; for a convex the second is smaller (see [[convex-function | convex functions]]) |
| The expectation does not exist (the sum or integral diverges) | The average does not settle, so a sample average never converges | Use a different summary, or check the tail behaviour first |
| You have only a few samples | The sample average is noisy and can be far from the true expected value | Report 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 . The expected value is . On average you gain 1 dollar per flip.
QuestionA fair die has expected value 3.5. What is the expected value of , where is the roll?Show answer
By linearity, . You did not need to compute the distribution of , only the expectation of .
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 and splitting the sum into and gives 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 with probability and with probability . The expected value is . 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
- Wikipedia, "Expected value": https://en.wikipedia.org/wiki/Expected_value
- Wikipedia, "Law of large numbers": https://en.wikipedia.org/wiki/Law_of_large_numbers