Updating with three coins
Suppose instead of a coin being either fair or biased, there are three possibilities: that the coin is fair (50% heads), low (25% heads), and high (75% heads). There is a 80% chance it is fair, a 10% chance it is biased low, and a 10% chance it is biased high.
You see 14/20 flips are heads. What is the probability that the coin is fair?
This exercise is part of the course
Foundations of Probability in R
Exercise instructions
- Use the
rbinom()
function to simulate 80,000 draws from the fair coin, 10,000 draws from the high coin, and 10,000 draws from the low coin, with each draw containing 20 flips. Save them asflips_fair
,flips_high
, andflips_low
, respectively. - For each of these types, compute the number of coins that resulted in 14. Save them as
fair_14
,high_14
, andlow_14
, respectively. - Find the posterior probability that the coin was fair, by dividing the number of fair coins resulting in 14 from the total number of coins resulting in 14.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Simulate 80,000 draws from fair coin, 10,000 from each of high and low coins
flips_fair <-
flips_high <-
flips_low <-
# Compute the number of coins that resulted in 14 heads from each of these piles
fair_14 <-
high_14 <-
low_14 <-
# Compute the posterior probability that the coin was fair