Prior probability

1. Prior probability

In these exercises we've been determining whether a coin we got from Nick is fair or biased. We've treated it as if before we saw any flips, there's a 50% chance that the coin is fair, and a 50% chance that the coin is biased towards heads. But let's say I generally trust Nick. When he gave me this coin, I figured he probably wasn't trying to trick me. I'm just testing the coin to be completely safe. Let's say that when Nick gives me the coin, I think there's only 10% chance that it's biased, and a 90% chance that it's fair. This is called a prior probability, and it's an important part of Bayesian statistics.

2. Differently sized piles

Let's go back to the two piles of coins from the last lesson: one of the piles is fair, one of them biased, and we flip each one of them 20 times. We know that Nick got his coin from one of these two piles. And by comparing the sizes of the red bars- the cases where a coin resulted in exactly 14 heads- we were able to find a conditional probability. However, this time, instead of having two equally sized piles, let's start with 90,000 coins in the fair pile and only 10,000 biased coins in the other pile. This represents our prior probability, giving the fair coins an advantage. Notice that in the resulting histograms, the relative height of the red bars- those with 14 heads- has changed. In fact, even though each of the fair coins individually was less likely to result in 14 heads than a biased coin was, there were more fair coins that ended up with 14 than biased ones.

3. Simulating with differently sized piles

We can simulate these piles to find the probability that a coin with 14 heads is biased, given our prior probability of 10%. We first simulate 90,000 draws from the binomial where the coins are fair: notice that we changed the first argument, the number of draws, to 90,000. We see that three thousand, four hundred and ten of these draws resulted in 14 heads. We then simulate only 10,000 draws of biased coins, each with a 75% chance of heads. We see that one thousand seven hundred and six of them led to 14 heads. Now we can find our conditional probability. Given that we are using one of those coins that resulted in 14 heads, what fraction of those were biased? We find that it's about 33%. We originally thought there was a 10% chance the coin was biased, but after seeing 14 heads out of 20 flips, our probability has updated to 33%. This simulation approach works even if there are more than two possibilities for the probability of heads. For example, you could start with three piles of coins, one that has a 25% chance, one that has a 50% chance, and one that has a 75% chance. You'll try an example like that in the exercises.

4. Let's practice!