Updating with priors

We see 14 out of 20 flips are heads, and start with a 80% chance the coin is fair and a 20% chance it is biased to 75%.

You'll solve this case with simulation, by starting with a "bucket" of 10,000 coins, where 8,000 are fair and 2,000 are biased, and flipping each of them 20 times.

This exercise is part of the course

Foundations of Probability in R

View Course

Exercise instructions

  • Simulate 8,000 trials of flipping a fair coin 20 times and 2,000 trials of flipping a biased coin 20 times. Save them as fair_flips and biased_flips, respectively.
  • Find the number of cases that resulted in 14 heads from each coin, saving them as fair_14 and biased_14 respectively.
  • Find the fraction of all coins that resulted in 14 heads that were fair: this is an estimate of the posterior probability that the coin is fair.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Simulate 8000 cases of flipping a fair coin, and 2000 of a biased coin
fair_flips <-
biased_flips <-

# Find the number of cases from each coin that resulted in 14/20
fair_14 <-
biased_14 <-

# Use these to estimate the posterior probability