LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Foundations of Probability in R

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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
Code bearbeiten und ausführen