เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Updating with simulation

We see 11 out of 20 flips from a coin that is either fair (50% chance of heads) or biased (75% chance of heads). How likely is it that the coin is fair? Answer this by simulating 50,000 fair coins and 50,000 biased coins.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Foundations of Probability in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Simulate 50,000 cases of flipping 20 coins from a fair coin (50% chance of heads), as well as from a biased coin (75% chance of heads). Save these variables as fair and biased respectively.
  • Find the number of fair coins where exactly 11/20 came up heads, then the number of biased coins where exactly 11/20 came up heads. Save them as fair_11 and biased_11 respectively.
  • Find the fraction of all coins that came up heads 11 times that were fair coins- this is the posterior probability that a coin with 11/20 is fair.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Simulate 50000 cases of flipping 20 coins from fair and from biased
fair <- 
biased <- 

# How many fair cases, and how many biased, led to exactly 11 heads?
fair_11 <- 
biased_11 <- 

# Find the fraction of fair coins that are 11 out of all coins that were 11
แก้ไขและรันโค้ด