Mit18 05 s22 Pset02 Sol
Mit18 05 s22 Pset02 Sol
𝑃 (𝐹 𝐹 ) 1/4 1
𝑃 (𝐹 𝐹 |{𝐹 𝑀 , 𝐹 𝐹 }) = = = .
𝑃 ({𝐹 𝑀 , 𝐹 𝐹 }) 1/2 2
(b) Our cat Ariel had two kittens. At least one of them is male. What is the probability
that both kittens are males?
Solution: The event “at least one kitten is male” is {𝑀 𝑀 , 𝑀 𝐹 , 𝐹 𝑀 } so the probability
that both kittens are male is
𝑃 (𝑀 𝑀 ) 1/4 1
𝑃 (𝑀 𝑀 |{𝑀 𝑀 , 𝑀 𝐹 , 𝐹 𝑀 }) = = = .
𝑃 ({𝑀 𝑀 , 𝑀 𝐹 , 𝐹 𝑀 }) 3/4 3
1
18.05 Problem Set 2, Spring 2022 Solutions 2
Let 𝑊𝑏 = ‘witness sees a blue taxi’ and let 𝑊𝑔 = ‘witness sees a green car’. Further, let 𝑇𝑏
= ‘taxi is blue’ and let 𝑇𝑔 = ‘taxi is green’. With this notation we want to find 𝑃 (𝑇𝑏 |𝑊𝑏 ).
We will compute this using Bayes’ formula
𝑃 (𝑊𝑏 |𝑇𝑏 ) ⋅ 𝑃 (𝑇𝑏 )
𝑃 (𝑇𝑏 |𝑊𝑏 ) = .
𝑃 (𝑊𝑏 )
All the pieces are represented in the following diagram.
0.01 0.99
Random taxi 𝑇𝐵 𝑇𝐺
0.99 0.01 0.02 0.98
Witness sees
𝑊𝐵 𝑊𝐺 𝑊𝐵 𝑊𝐺
𝑃 (𝑊𝑏 ) = 𝑃 (𝑊𝑏 |𝑇𝑏 )𝑃 (𝑇𝑏 ) + 𝑃 (𝑊𝑏 |𝑇𝑔 )𝑃 (𝑇𝑔 ) = 0.99 × 0.01 + 0.02 × 0.99 = 0.99 × 0.03.
0.99 × 0.01 1
𝑃 (𝑇𝑏 |𝑊𝑏 ) = =
0.99 × 0.03 3
Our speech:
Ladies and gentlemen of the jury. The prosecutor tells you that the witness is nearly flawless
in their ability to distinguish whether a taxi is green or blue. They claims that this implies
that beyond a reasonable doubt the taxi involved in the hit and run was blue. However
probability theory shows without any doubt that a random taxi which the witness sees as
blue is actually blue only 1/3 of the time. This is considerably more than a reasonable
doubt. In fact it is more probable than not that the taxi involved in the accident was green.
If the probability doesn’t fit you must acquit!
Note: Confusing of 𝑃 (testimony|guilty) for 𝑃 (guilty|testimony) is known as the prosecutor’s
fallacy
You draw one card at random. If its rank is 1 you draw one more card; if its rank is two
you draw two more cards. Let 𝑋 be the sum of the ranks on the 2 or 3 cards drawn. Find
𝐸[𝑋]. (Note: all the draws are done without replacement.)
Solution: The following tree shows all the possible ways we can draw cards. The first draw
is the top row of nodes. The value of the draw is given in the circle. The probability of
that draw is given along the edge. Likewise for the second and third draws. At the end of
each path we give the value of 𝑋 resulting from those draws.
18.05 Problem Set 2, Spring 2022 Solutions 3
4/8 4/8
1 2
3/7 4/7 4/7 3/7
1 2 1 2
𝑋=2 𝑋=3
3/6 3/6 4/6 2/6
1 2 1 2
𝑋=4 𝑋=5 𝑋=5 𝑋=6
Problem 4. (25: 5,10,5,5 pts.) (Dice) There are four dice in a drawer: one D4 (4 sides),
one D6 (6-sides), and two D8 (8 sides). As usual, the sides of a die are numbered 1 to 𝑛,
where 𝑛 is the number of sides.
Your friend secretly grabs one of the four dice at random. Let 𝑆 be the number of sides on
the chosen die.
(a) What is the pmf of S?
Solution: Here is the pmf:
value 𝑠 4 6 8
pmf 𝑝(𝑠) 1/4 1/4 1/2
(b) Now, without showing it to you, your friend rolls the chosen die and tells you the result.
Let 𝑅 be the result of the roll.
Use Bayes’ rule to find 𝑃 (𝑆 = 𝑠 | 𝑅 = 3) for 𝑠 = 4, 6, 8. Which die is most likely if 𝑅 = 3?
Terminology: You are computing the pmf of ‘𝑆 given 𝑅 = 3’.
Solution: Bayes’ rule says
𝑃 (𝑅 = 3 | 𝑆 = 𝑠)𝑃 (𝑆 = 𝑠)
𝑃 (𝑆 = 𝑠|𝑅 = 3) = .
𝑃 (𝑅 = 3)
We summarize what we know in a tree. In the tree the notation 𝐷4 means the 4-sided die
(𝑆 = 4), likewise 𝑅3 means a 3 was rolled (𝑅 = 3). Because we only care about the case
𝑅 = 3 the tree does not include other possible rolls.
We have the following probabilities (you should identify them in the tree):
The law of total probability gives (again, see how the tree tells us this):
𝑃 (𝑅 = 3 | 𝑆 = 4) ⋅ 𝑃 (𝑆 = 4) (1/4) ⋅ (1/4) 3
𝑃 (𝑆 = 4 | 𝑅 = 3) = = =
𝑃 (𝑅 = 3) 1/6 8
𝑃 (𝑅 = 3 | 𝑆 = 6) ⋅ 𝑃 (𝑆 = 6) (1/6) ⋅ (1/4) 1
𝑃 (𝑆 = 6 | 𝑅 = 3) = = =
𝑃 (𝑅 = 3) 1/6 4
𝑃 (𝑅 = 3 | 𝑆 = 8) ⋅ 𝑃 (𝑆 = 8) (1/8) ⋅ (1/2) 3
𝑃 (𝑆 = 8 | 𝑅 = 3) = = = .
𝑃 (𝑅 = 3) 1/6 8
We see that the 4 and 8 sided dice are equally most likely given 𝑅 = 3.
(c) Which die is most likely if 𝑅 = 6? Hint: You can either repeat the computation in (b),
or you can reason based on your result in (b).
Solution: In a similar vein, we have
and
1 1 1 1 1 5
𝑃 (𝑅 = 6) = 0 ⋅ + ⋅ + ⋅ = .
4 6 4 8 2 48
So,
1/24 2 1/16 3
𝑃 (𝑆 = 4|𝑅 = 6) = 0, 𝑃 (𝑆 = 6|𝑅 = 6) = = , 𝑃 (𝑆 = 8|𝑅 = 6) = = .
5/48 5 5/48 5
The eight-sided die is more likely. Note, the denominator is the same in each probability,
i.e. the total probability 𝑃 (𝑅 = 6), so all we really had to check was the numerator.
(d) Which die is most likely if 𝑅 = 7? No computations are needed!
Problem 5. (10 pts.) (Seating arrangement and relative height) A total of 𝑛 people
randomly take their seats around a circular table with 𝑛 chairs. No two people have the same
height. What is the expected number of people who are shorter than both of their immediate
neighbors?
Solution: Label the seats 1 to 𝑛 going clockwise around the table. Let 𝑋𝑖 be the Bernoulli
random variable with value 1 if the person in seat 𝑖 is shorter than their neighbors. Then
18.05 Problem Set 2, Spring 2022 Solutions 5
𝑛
𝑋 = ∑𝑖=1 𝑋𝑖 represents the total number of people who are shorter than both of their
neighbors, and, by linearity of expected value,
𝑛 𝑛
𝐸[𝑋] = 𝐸 [∑ 𝑋𝑖 ] = ∑ 𝐸[𝑋𝑖 ]
𝑖=1 𝑖=1
Recall that this property of expected values holds even when the 𝑋𝑖 are dependent, as is
the case here!
Among 3 random people the probability that the middle one is the shortest is 1/3. Therefore
𝑋𝑖 ∼ Bernoulli(1/3), which implies 𝐸[𝑋𝑖 ] = 1/3. Therefore the expected number of people
shorter than both their neighbors is
𝑛
𝑛
𝐸[𝑋] = ∑ 𝐸[𝑋𝑖 ] = .
𝑖=1
3
}
(Should produce: 1, 4, 9, 16, 25.)
sum = 0
for (j in 1:5) {
sum = sum + j
}
print(sum)
(Should produce: 15.)
Use R to simulate the average length of the longest run in 50 flips of a fair coin. Do this
three times with 10000 trials each time and report the three results.
Solution: Here is my code with comments
nflips = 50
ntrials = 10000
total = 0 # We'll keep a running total of all the trials' longest runs
for (j in 1:ntrials) {
# One trial consists of 50 flips
trial = rbinom(nflips, 1, 0.5) # binomial(1, 0.5) = bernoulli(0.5)
# rle() finds the lengths of all the runs in trials. We add the max to total
total = total + max(rle(trial)$lengths)
}
# The average maximum run is the total/ntrials
ave_max = total/ntrials
print(ave_max)
My three runs of this code produced ave_max = 5.9863, 5.9696, 5.9804
(d) A small modification of your code will let you estimate the probability of a run of 8 or
more in 50 flips. Do this three times with 10000 trials each time. Report the three results.
Solution: Instead of keeping a total we keep a count of the number of trials with a run of
8 or more
nflips = 50
ntrials = 10000
# We'll keep count of all the trials with a run of 8 or more
count = 0
for (j in 1:ntrials) {
trial = rbinom(nflips, 1, 0.5) # binomial(1, 0.5) = bernoulli(0.5)
count = count + (max(rle(trial)$lengths) >= 8)
}
# The probability of a run of 8 or more is count/ntrials
prob8 = count/ntrials
print(prob8)
My run of this code produced prob8 = 0.1596, 0.1637, 0.1632
MIT OpenCourseWare
https://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.