Random variables and expected value
A random variable attaches a number to every outcome of an experiment — a payout, a waiting time, a count of faults. Its distribution is written as a table, and two numbers summarise that whole table: the expected value says what the results centre on, the variance says how far from it they wander.
Before you start
This topic builds on earlier ideas. Before you start, it's worth working through the lessons below — they'll make everything click:
- Trees and the Bernoulli schemeA multi-stage experiment draws as a tree: probabilities multiply along the branches and add across the paths. That one picture holds the formula for the union of two events, the difference between disjoint and independent events, and the whole Bernoulli scheme — including where its binomial coefficient comes from.
- Mean, median and modeThree answers to one question: which single number best describes a whole data set. The mean shares the total out evenly, the median stands exactly in the middle, and the mode points at the most frequent value — and which one you pick can change the conclusion.
- Variance and deviationTwo data sets can share the same mean and look nothing alike. The range, the variance and the standard deviation measure what the mean cannot see: how widely the data is spread around it.
Where this is used
Real situations where you count exactly the way this lesson teaches:
- A lottery ticketA ticket costs 5. The top prize of 1000 comes up with probability 1/2000 and a consolation 50 with probability 1/200. The expected payout is 1000/2000 + 50/200 = 0.50 + 0.25 = 0.75, so the player’s expected result is 0.75 − 5 = −4.25 per ticket. A hundred tickets a year means an expected loss of 425, and no run of luck changes that — it only changes when it shows.
- Pricing an insurance premiumAn insurer estimates that a claim occurs for 2 per cent of customers per year and that its average cost is 30,000. The expected payout per policy is 0.02 · 30,000 = 600, so a premium of 900 leaves 300 for costs and profit. The whole actuarial pricing of a policy is the computation of the expected value of the random variable “payout”.
- European rouletteA stake of 1 on a single number pays 35 to 1, and there are 37 numbers counting the zero. The expected value is 35 · 1/37 − 1 · 36/37 = −1/37, about −0.027 per unit staked. That is the house edge: 2.7 per cent of turnover, whatever the betting strategy and however many times the game is played.
- A flat-rate service contractA repair shop knows that a given machine breaks down within a year with probability 0.15 and that a repair costs 800. The expected cost is 0.15 · 800 = 120 per machine, so a flat annual fee of 200 covers it with room to spare. It is worth taking for the customer whenever they prefer a certain 200 to a lottery that costs 800 with probability 15 per cent — and that is the whole difference between expected value and risk.
All formulas
Random variable
a function attaching a number to an outcome
Distribution
a table of values and their probabilities
Expected value
a mean weighted by probabilities
Variance of a variable
mean squared deviation from E(X)
Computational form
one pass over the table instead of two
Standard deviation
in the same unit as X
Distribution function
non-decreasing, from 0 to 1
Linear transformation
a shift does not change the spread
The outcome of rolling two dice is a pair of faces, but a problem almost always asks about their sum. The outcome of a game is the whole play, but what interests us is the payout. In both cases an event is translated into a number — and that recipe for translating is what a random variable is.
A random variable is a function
A random variable is a function attaching a number to every elementary outcome:
The name misleads twice. It is not a variable in the algebraic sense — it does not stand in an equation and there is nothing to solve for. Nor is it a random number — the function is entirely determined; only its argument is random.
For a roll of two dice has elements, and = the sum of the faces assigns the number to the pair . The variable “simplifies” the experiment: instead of pairs we have numbers — at the price that they are no longer equally likely.
The distribution as a table
The distribution of a discrete variable is the list of its values together with their probabilities. It is written as a table:
There is one validity condition, and it is always worth checking:
The table exhausts every possibility, so the probabilities must add up to exactly one. The same distribution drawn as bars:
Expected value
The expected value of a random variable is the mean of its values weighted by their probabilities:
Physically it is the centre of mass of the distribution: the point where the bar chart could be balanced on a fingertip. For game A:
Two remarks, both more important than the arithmetic itself.
The expected value need not be possible. For a die roll , though a die never shows . It is a centre of mass, not a forecast of a single result.
The expected value is not a sample mean. The arithmetic mean is computed from what came up and changes from sample to sample. The expected value is computed from the model, that is from the probabilities, and is single. After a thousand die rolls the mean will be close to ; after ten it may well be — and is still in both cases.
Variance: what the expected value does not say
on its own summarises a distribution too aggressively. Compare game A with game B, whose payout is , or with the same probabilities:
Both games have and differ in everything that matters to a player. That difference is measured by the variance of the variable:
In practice the computational formula is handier, needing one pass over the table instead of two:
Mind the units: the variance is in squared units, so what compares with the variable itself is the standard deviation . It is the same relationship that appeared for the spread of a data set — with the difference that there the weights were counts, and here they are probabilities.
Two properties of linear transformations are also worth having:
A shift by does not change the spread — it moves the whole distribution rather than stretching it. That is why does not appear in the second formula at all.
The distribution function
Instead of asking “what is ”, we often ask “will stay below a given value”. That is answered by the distribution function:
For a discrete variable it is a step function: constant between the values, jumping by at each of them. For game A:
| interval | ||||
|---|---|---|---|---|
The distribution function is always non-decreasing, starts at and ends at — because probabilities accumulate rather than cancel. Its convenience is that the probability of an interval is read off by subtraction: .
A note on continuous variables
Everything above assumed the values could be listed. Sometimes they cannot: a bus waiting time, the height of a randomly chosen person or a measurement error take every value in an interval.
For such a continuous variable the probability of hitting any particular number is zero — not because it is impossible, but because there are infinitely many possibilities. The sensible question is about an interval, and it is answered by the area under the graph of a density function:
The sum over a table turns into a definite integral, and the condition “the probabilities add up to one” turns into “the area under the whole density is one”. The most important continuous variable of all, the normal distribution, comes two lessons further on.
Exercises
The set asks for two numbers, both computed from the same distribution table. The prompt gives “value → probability” pairs and asks for the expected value. The prompt gives a table of the same shape and asks for the variance of the variable, that is for .
The answer here is a number, not a fraction in lowest terms: an expected value is not a probability but a quantity on the variable’s own scale. The probabilities in the tables are chosen so that the result has at most two decimal places.
Practice
Work through a set of exercises — they get harder as you go. At the end you'll see your score and the mistakes worth reviewing.
The generator does not ask you to state a distribution — the answer would be a whole table together with the names of the events, not a number. Nor does it ask about the distribution function, for the same reason. Both are worked through in the examples above.
Common mistakes
- Confusing with the arithmetic mean of data — the first is a property of the model and is fixed, the second a property of the sample and changes with every repetition.
- Expecting to be one of the possible values — pips never comes up, and it is still the correct expected value.
- A table whose probabilities do not add up to one — that is not a distribution, and every quantity computed from it is meaningless. It is worth starting with that check.
- Squaring the probabilities instead of the values — in the squares apply to the , while the weights stay untouched.
- Comparing a variance with the variable itself — a variance is in squared units; what compares is the standard deviation.
- Concluding that two variables with the same are equivalent — games A and B share an expected value and differ twenty-five-fold in variance, which for a player is the whole difference.
Formula card
Topic: Random variables
Random variable
a function attaching a number to an outcome
Distribution
a table of values and their probabilities
Expected value
a mean weighted by probabilities
Variance of a variable
mean squared deviation from E(X)
Computational form
one pass over the table instead of two
Standard deviation
in the same unit as X
Distribution function
non-decreasing, from 0 to 1
Linear transformation
a shift does not change the spread
