Skip to content

Linearity of expectation, explained

6 min read

Short answer

E[X+Y]=E[X]+E[Y]E[X+Y]=E[X]+E[Y] holds for any random variables, independent or not, and E[cX]=cE[X]E[cX]=cE[X]. 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.

E[X + Y] = E[X] + E[Y]E[X + Y] = E[X] + E[Y]Always true no independence neededAny number of terms, finite sumsConstants E[cX + d] = cE[X] + dCareful E[XY] = E[X]E[Y] needs more
Sums are always safe. Products are not: splitting E[XY] needs independence (or at least uncorrelated variables).

Why it is true

Using the joint probability mass function p(x,y)p(x,y),

E[X+Y]=∑x,y(x+y) p(x,y)=∑xx∑yp(x,y)+∑yy∑xp(x,y)=E[X]+E[Y],E[X+Y]=\sum_{x,y}(x+y)\,p(x,y)=\sum_xx\sum_yp(x,y)+\sum_yy\sum_xp(x,y)=E[X]+E[Y],

because summing the joint over yy leaves the marginal of XX, 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 IAI_A is 11 if event AA occurs and 00 otherwise, so E[IA]=P(A)E[I_A]=P(A). To find the expected number of things that happen, write the count as a sum of indicators, one per thing, and add their probabilities:

N=∑iIAi ⟹ E[N]=∑iP(Ai).N=\sum_iI_{A_i}\ \Longrightarrow\ E[N]=\sum_iP(A_i).

You never need the distribution of NN, which could be a nightmare of dependencies. For example the count of heads in nn flips has E[N]=npE[N]=np with no binomial coefficients needed.

A surprising application

Shuffle nn hats and hand them back at random. Let Ii=1I_i=1 if person ii gets their own hat. Each person gets it back with probability 1n\tfrac1n, so the expected number of matches is n⋅1n=1n\cdot\tfrac1n=1 for every nn, even though the indicators are dependent.

This kind of result is nearly impossible to reach by listing all n!n! arrangements but takes one line with linearity.

Worked example

Let XX be a fair die roll and Y=7−XY=7-X. Find E[X+Y]E[X+Y] and explain why linearity applies even though YY depends completely on XX.

E[X]=3.5E[X]=3.5, and YY is also uniform on {1,…,6}\{1,\dots,6\}, so E[Y]=3.5E[Y]=3.5. Linearity gives E[X+Y]=7E[X+Y]=7.

Direct check: X+Y=7X+Y=7 always, so its expectation is 77. ✓ 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 1365\tfrac1{365}, so the expectation is 20⋅1365≈0.05520\cdot\tfrac1{365}\approx0.055 by linearity.

Keep going with practice

Vidi's expected-value lessons practice the indicator method on counting problems.