1. Probability of A or B
In the last exercises, you learned a rule for finding the probability that event A and event B happened. Now you'll learn how to calculate the probability that either event A or B happens. For example, suppose I flip this coin twice: what is the probability that at least one of the flips is heads?
2. Probability of A or B
You can imagine this as two overlapping circles in a Venn diagram. One circle represents whether event A happens, such as the first flip being heads, and one whether B happens, such as the second flip being heads. The probability that either happens is the total region.
To find that overall probability, you can start by adding up the areas of the two circles. But then you'll be double counting the region where they overlap where they both happen, so you have to subtract that as well.
This means that the probability of A or B happening is the probability of A, plus the probability of B, minus the overlap- the probability of both A and B. In the last lessons you learned that the probability of A and B, as long as A and B are independent, is the probability of A times the probability of B.
So if A and B are independent flips of a fair coin, we can take the probability of the first being heads - 50%- plus the probability of the second being heads - 50% - and subtract the probability they both are heads - point-5 times point-5.
3. Simulating two events
Let's try this in a simulation. We can start by simulating one hundred thousand fair coin flips for A, and one hundred thousand fair coin flips for B. Then we want to compare pairs of them.
To do this, we'll introduce the "or" logical operator, which in R is represented by a vertical pipe. On most keyboards you'll find that pipe above the return or enter key. Then much as we did for "and", we'll take the mean to estimate the probability of either happening.
Here you can see that it's about 75%. This matches the number we earlier got from the formula: point-5 plus point-5 minus point-5 times point-5.
This also works if our coins are biased. If event A has a 20% probability, and event B has a 60% probability, what is the probability that either event happens? This simulation shows that it's about 68%. This also matches what we would get from our rule: point-2 plus point-6 minus point-2 times point-6.
4. Three coins
One advantage of a simulation approach is that it extends to cases where mathematical solutions would get cumbersome. For example, suppose we have three coins, and want to know the probability that any of them three of them is heads. that is, the probability A or B or C.
The formula for three events is a bit complicated- and you don't need to memorize it. But if you've simulated the events A, B, and C, you can simply combine all three with an "or" operator and then take the mean. You could even do this with four events, or five events. You'll try a problem like this in the exercises.
5. Let's practice!