STAT 6100 - MATH 6180 Lecture 4 - Computing Expectations by Conditioning
STAT 6100 - MATH 6180 Lecture 4 - Computing Expectations by Conditioning
Review:
For discrete random variables 𝑋 and 𝑌, the conditional p.f. of 𝑋|𝑌 = 𝑦 is: 𝑓𝑋|𝑌=𝑦 (𝑥|𝑦) =
𝑓𝑋,𝑌 (𝑥,𝑦) 𝐽𝑜𝑖𝑛𝑡 𝑝.𝑓. 𝑜𝑓 𝑋 𝑎𝑛𝑑 𝑌
𝑃(𝑋 = 𝑥|𝑌 = 𝑦) = =
𝑓𝑌 (𝑦) 𝑀𝑎𝑟𝑔𝑖𝑛𝑎𝑙 𝑝.𝑓. 𝑜𝑓 𝑌
Note that conditional expectations have all the usual properties of unconditional
variances.
For example:
𝐸[ (𝑎𝑋 + 𝑏) |𝑌] = 𝑎 𝐸[𝑋|𝑌] + 𝑏
𝐸[ (𝑋1 + 𝑋2 ) |𝑌] = 𝐸[𝑋1 |𝑌] + 𝐸[𝑋2 |𝑌]
1
For discrete random variables 𝑋 and 𝑌, the Theorem of Total Expectation yields the
following:
We can use the result above to compute expectations by conditioning, i.e. find 𝐸[𝑋] by
conditioning on another random variable 𝑌.
We have already used this method – see the examples in Lecture 3. We now look at
some more examples.
Example: A miner is trapped in a mine containing three doors. The first door leads to a
tunnel that takes him to safety after two hours of travel. The second door leads to a
tunnel that returns him to the mine after three hours of travel. The third door leads to a
tunnel that returns him to his mine after five hours. The miner is at all times equally
likely to choose any one of the doors. His current choice of door is independent of his
previous choices. What is the expected length of time until the miner reaches safety?
Let 𝑋 be the time until the miner reaches safety (in hours).
We will find 𝐸[𝑋] by conditioning on 𝑌 and using the Theorem of Total Expectation.
2
1
Now, 𝑃(𝑌 = 𝑖) = 𝑃(𝑚𝑖𝑛𝑒𝑟 𝑐ℎ𝑜𝑜𝑠𝑒𝑠 𝑑𝑜𝑜𝑟 𝑖) = ; 𝑖 = 1, 2, 3; since the miner is equally
3
likely to choose any one of the doors.
Given: 𝐸[𝑋|𝑌 = 1] = 2, since door 1 takes him to safety after two hours of travel.
𝐸[𝑋|𝑌 = 2] = 3 + 𝐸[𝑋]
3
𝐸[𝑋|𝑌 = 3] = 5 + 𝐸[𝑋]
1 1 1
𝐸[𝑋] = (2) + ( 3 + 𝐸[𝑋] ) + ( 5 + 𝐸[𝑋] )
3 3 3
4
Before examining the remaining examples, we will review the Geometric distribution.
Suppose we have repeated, independent Bernoulli trials (i.e. outcome of each trial is
either success or failure), each with a probability of success 𝑝.
Then 𝑁~𝐺𝑒𝑜𝑚𝑒𝑡𝑟𝑖𝑐(𝑝)
1 1−𝑝
It can be shown that: 𝐸[𝑁] = , 𝑉𝑎𝑟[𝑁] =
𝑝 𝑝2
Let 𝑞 = 1 − 𝑝 = probability of failure. Suppose the experiment is: repeat the trials until
the first failure is obtained.
5
Example:
A coin that comes up heads with probability 𝑝 is continually flipped until the pattern
H, T appears. (That is, you stop flipping when the most recent flip lands tails, and the
flip immediately preceding it lands on heads.) Let 𝑋 denote the number of flips made
and let 𝑞 = 1 − 𝑝.
1 𝑞
Show that 𝐸[𝑋] = 1 + +
𝑞 𝑝
Proof:
Let 𝑌 be the result of the first flip. We will find 𝐸[𝑋] by conditioning on 𝑌 and using
the Theorem of Total Expectation.
𝑃(𝑌 = 𝐻) = 𝑝, 𝑃(𝑌 = 𝑇) = 𝑞
6
𝐸[𝑋] = 𝐸[𝑋|𝑌 = 𝐻] 𝑃(𝑌 = 𝐻) + 𝐸[𝑋|𝑌 = 𝑇] 𝑃(𝑌 = 𝑇)
7
1
𝐸[𝑋|𝑌 = 𝐻] = 1 + (2)
𝑞
First flip is T First flip: T. The pattern is ruined. Procedure starts over.
(given) We must continue flipping until the pattern H,T has been
obtained, i.e. the procedure starts over, as the flips are
independent.
1 𝑞
Solve for 𝐸[𝑋] to obtain 𝐸[𝑋] = 1 + + ∎
𝑞 𝑝
8
Example (Ross, Chapter 3, Page 177, Exercise 27):
A coin that comes up heads with probability 𝑝 is continually flipped until the pattern
T, T, H appears. (That is, you stop flipping when the most recent flip lands heads, and
the two flips immediately preceding it land on tails.)
Find an equation involving 𝐸[𝑋], 𝑝 and 𝑞. You do not need to solve the equation.
Let 𝑌 be the result of the first flip. We will find 𝐸[𝑋] by conditioning on 𝑌 and using
the Theorem of Total Expectation.
9
𝐸[𝑋|𝑌 = 𝐻] = 1 + 𝑒𝑥𝑝𝑒𝑐𝑡𝑒𝑑 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑓𝑙𝑖𝑝𝑠 𝑢𝑛𝑡𝑖𝑙 𝑇, 𝑇, 𝐻 𝑎𝑝𝑝𝑒𝑎𝑟𝑠
First flip is First flip: H. The pattern is ruined. Procedure starts over.
H (given) We must continue flipping until the pattern T,T,H has
been obtained, i.e. the procedure starts over, as the flips
are independent.
To find 𝐸[𝑋|𝑌 = 𝑇], conditioning on the result of the second flip and use the Theorem of
Total Expectation.
10
𝐸[𝑋|𝑌 = 𝑇, 𝑍 = 𝐻] = 𝐸[𝑋 | 𝑓𝑖𝑟𝑠𝑡 𝑡𝑤𝑜 𝑓𝑙𝑖𝑝𝑠 𝑎𝑟𝑒 𝑇, 𝐻]
First two First two flips: T,H. The pattern is ruined. Procedure starts
flips are T,H over.
(given) We must continue flipping until the pattern T,T,H has
been obtained, i.e. the procedure starts over, as the flips
are independent.
11
𝐸[𝑋|𝑌 = 𝑇, 𝑍 = 𝑇] = 𝐸[𝑋 | 𝑓𝑖𝑟𝑠𝑡 𝑡𝑤𝑜 𝑓𝑙𝑖𝑝𝑠 𝑎𝑟𝑒 𝑇, 𝑇]
1
𝐸[𝑋|𝑌 = 𝑇, 𝑍 = 𝑇] = 2 + (5)
𝑝
12
Subs. (4) and (5) into (3):
1
𝐸[𝑋|𝑌 = 𝑇] = 𝑝 (2 + 𝐸[𝑋]) + 𝑞 (2 + ) (6)
𝑝
1
𝐸[𝑋] = 𝑝 ( 1 + 𝐸[𝑋] ) + 𝑞 [ 𝑝 (2 + 𝐸[𝑋]) + 𝑞 (2 + ) ]
𝑝
Exercise (Ross, Chapter 3, Page 177, Exercise 24):: A coin, having probability 𝑝 of
landing heads, is flipped repeatedly until at least one head and at least one tail have
been obtained. Note that the head and the tail do not have to be consecutive.
Let 𝑋 denote the number of flips made and let 𝑞 = 1 − 𝑝. Find 𝐸[𝑋] in terms of 𝑝 and 𝑞.
1 1
Answer: 𝐸[𝑋] = 𝑝 (1 + ) + 𝑞 (1 + )
𝑞 𝑝
13