F4 · Random Variables and Expectation · Lesson 2 of 8
Conditional Expectation
The tower property, conditioning on the first step, and Wald's identity.
25 min
Conditioning on a random variable
E[X∣Y] is the best guess of X once you know Y. It is itself a random variable: a function of Y. If Y is a die roll, E[X∣Y] takes six values, one for each face.
Three rules do almost all the work.
Tower property:E[E[X∣Y]]=E[X]. Average the conditional answers, weighted by how likely each condition is.
Taking out what is known:E[g(Y)X∣Y]=g(Y)E[X∣Y].
Law of total variance:Var(X)=E[Var(X∣Y)]+Var(E[X∣Y]).
Total uncertainty is the noise left after learning Y, plus the uncertainty about what you will learn.
Worked example
roll a die, then flip that many coins
Roll a fair die and call the result N. Then flip N fair coins and let H be the number of heads. Find E[H] and Var(H).
Show solutionHide solution
Given N, H is binomial: E[H∣N]=N/2 and Var(H∣N)=N/4.
In a game or a process, condition on what happens next. If V(s) is the value from state s,
V(s)=E[reward now+V(next state)s].
For optimal stopping games (stop or continue), compare the value of stopping now with the value of continuing, and take the larger. Solve from the end backwards: the last decision is easy, and each earlier one uses the value of the one after it.
Random sums and Wald's identity
Let X1,X2,… be i.i.d. with mean μ, and let N be a stopping time: whether you stop after step n depends only on X1,…,Xn. If E[N]<∞, then
E[i=1∑NXi]=E[N]μ.
The surprising part is that N may depend on the Xi already seen. It may not peek into the future: "stop just before the first 6" is not a stopping time.
Gambler's ruin
A walk moves +1 with probability p and −1 with probability q=1−p, starting at k and stopping at 0 or N. Let Pk be the probability of reaching N. First-step analysis gives Pk=pPk+1+qPk−1 with P0=0, PN=1. The solution is
Pk=⎩⎨⎧Nk,1−(q/p)N1−(q/p)k,p=21,p=21.
A faster route uses martingales. For the fair walk, Sn is a martingale, so E[ST]=k, giving NPk=k. And Sn2−n is a martingale, so E[T]=E[ST2]−k2=N2⋅Nk−k2=k(N−k). For the biased walk, (q/p)Sn is a martingale and gives the second formula directly.
Worked example
a favourable walk
You start with $2 and bet $1 at a time, winning each bet with probability 32. You stop at $5 or at $0. What is the probability you reach $5?
Show solutionHide solution
Here q/p=2/31/3=21, k=2, N=5:
P2=1−(1/2)51−(1/2)2=31/323/4=3124≈0.774.
Check the limits: as N→∞, Pk→1−(q/p)k=43, the probability of never going broke.
Knowledge check
You roll a die until the first 6 appears, and add up every roll including the 6. What is the expected total?
Knowledge check
A fair ±1 random walk starts at 3 and stops when it hits 0 or 10. What is the expected number of steps?
Knowledge check
X and Y are i.i.d. continuous random variables. What is E[X∣X+Y=s]?