Linearity of expectation, explained
6 min read
Short answer
holds for any random variables, independent or not, and . This makes expectation a linear operation, and it lets you compute the expected count of a complicated event by splitting it into indicator variables and adding their probabilities.
Why it is true
Using the joint probability mass function ,
because summing the joint over leaves the marginal of , and vice versa. Independence never entered the calculation: the joint distribution can be anything with these marginals. Continuous variables work the same way with integrals.
The indicator-variable trick
An indicator is if event occurs and otherwise, so . To find the expected number of things that happen, write the count as a sum of indicators, one per thing, and add their probabilities:
You never need the distribution of , which could be a nightmare of dependencies. For example the count of heads in flips has with no binomial coefficients needed.
A surprising application
Shuffle hats and hand them back at random. Let if person gets their own hat. Each person gets it back with probability , so the expected number of matches is for every , even though the indicators are dependent.
This kind of result is nearly impossible to reach by listing all arrangements but takes one line with linearity.
Worked example
Let be a fair die roll and . Find and explain why linearity applies even though depends completely on .
, and is also uniform on , so . Linearity gives .
Direct check: always, so its expectation is . ✓ The strong dependence did not matter, because linearity only uses each variable's own average.
Try it yourself
Twenty people each have a birthday on a uniformly random day of a 365-day year. What is the expected number of people whose birthday is January 1?
Show the answer
Each person has probability , so the expectation is by linearity.
Keep going with practice
Vidi's expected-value lessons practice the indicator method on counting problems.