Probability of Defective Coin

You suspect that one of the 100 coins in a bag is 60% biased towards heads. You take one coin at random, flip it 50 times and get 30 heads. What is the probability that the coin you chose is biased?

Let’s do this Bayesian challenge step by step. Let B = biased, nB = not biased, and D = outcome (data). The probability that the coin is biased, given the data of 30 heads out of 100 flips,

\\ p(B|D) = \frac{P(D|B)*P(B)}{P(D|B)P(B) + P(D|nB)*P(nB)}

The likelihood, P(Data|B)

The first term of the numerator is called the likelihood. What is the likelihood of getting 30 heads in 50 flips if the coin is biased 60%? We know how to get that quantity – apply a binomial trial with a chance of 0.6 for success and 0.4 for failure. The term in the denominator, P(D|nB)*P(nB), the probability of 30 heads if the coin is not biased, means you make success and failure at 0.5.

Since you have the information that 1 in 100 coins is faulty, you chose 1/100 as the prior knowledge. The R code of the calculation is given below.

head_p <- 0.6
tail_q <- 1 - head_p
prior <- 1/100

flip   <- 50
success_head <- 30

prob_bias <- choose(flip, success_head)*(head_p^(success_head))*(tail_q^(flip-success_head))  

head_p <- 0.5
tail_q <- 1 - head_p
prior_no <- 1 - prior
prob_no_bias <- choose(flip, success_head)*(head_p^(success_head))*(tail_q^(flip-success_head))  

post <- (prob_bias*prior)/(prob_bias*prior + prob_no_bias*prior_no )
post

You get a probability of ca. 2.6%. You are not satisfied, and you flip another 50 times and get 35 heads. What is your inference now? Repeat the same calculation, but don’t forget to update your belief from 1 in 100 to 2.6 in 100.