Get startedGet started for free

Calculating probabilities of two events

1. Calculating probabilities of two events

In this lesson, you will learn how to calculate the probability of two events.

2. Independence

Given two events, if the events are not affected by the order in which they happen and the occurrence of one event does not affect the probability of the other, then the events are independent.

3. Probability of A and B for independent events

Let's work with a fair coin.

4. Two coin flips

If we flip a coin twice, we get four possible outcomes.

5. Two coin flips (Cont.)

We can ask what the probability of each outcome is.

6. Two coin flips (Cont.)

For independent events, we use the multiplication rule.

7. Two coin flips (Cont.)

The probability of A and B...

8. Two coin flips (Cont.)

is the probability of A times the probability of B.

9. Two coin flips (Cont.)

For instance, we get 0.25 for two tails.

10. Measuring a sample

Generating a sample of two fair coin flips, we get the number of heads for each throw. We can count how many times each outcome repeats using the function find_repeats. To use find_repeats, you must import it from scipy dot stats. You pass the data to the function to get how many times each outcome in the data repeats. You can see in the counts array that 2 tails repeats 249 times in the 1,000 throws.

11. Two coin flips

Using a biased coin with 80% probability of heads...

12. Two coin flips (Cont.)

we see that there is a 4% chance of getting two tails.

13. Measuring a biased sample

The relative frequency is the number of favorable trials divided by the total trials. To get the relative frequency from data, you can import the scipy dot stats dot relfreq function and specify the data and numbins as parameters. In our case, numbins is 3 for the three possible outcomes of two tails, one heads and one tails, or two heads. In the frequency array the relative frequency of 0 (two tails) is almost 4%.

14. Joint probability calculation

Moving on to a different example, we are provided with the probability of failure for an engine and a gear box. What is the probability of both failing? The probability of failure for the engine is 1% and for the gear box it's 0.5%, assuming independence. We multiply the two probabilities to get 0.00005. Now let's work with the probability of A or B.

15. P(A or B) with cards

Consider a deck of cards. Calculate the probability of getting a Jack or a King.

16. P(A or B) with cards (Cont.)

We add the probability of getting a Jack, 4 divided by 52...

17. P(A or B) with cards (Cont.)

with the probability of getting a King, which is the same. There is no overlap between those two events. This means there are no common elements in drawing a King or a Jack.

18. P(A or B) with cards (Cont.)

After some calculation, we see that the probability of drawing either a Jack or a King is 2 over 13.

19. P(A or B) with cards (Cont.)

Visually, you can see the result of such a probability.

20. Probability of A or B

To calculate the probability of A or B more generally, let's consider an event A...

21. Probability of A or B (Cont.)

and an event B without overlap with A. That means there are no common elements in the events.

22. Probability of A or B (Cont.)

The probability of A or B...

23. Probability of A or B (Cont.)

is the probability of A...

24. Probability of A or B (Cont.)

plus the probability of B. In this sense, the probability is additive.

25. P(A or B) with overlap

For overlapping events, such as the probability of drawing a Jack and a heart, the procedure is slightly different.

26. P(A or B) with overlap (Cont.)

We add the probability of getting a Jack, which is 4 divided by 52...

27. P(A or B) with overlap (Cont.)

with the probability of getting a heart, which is 13 divided by 52...

28. P(A or B) with overlap (Cont.)

and we subtract the overlap.

29. P(A or B) with overlap (Cont.)

This is the probability of getting both a Jack and a heart, which is 1 over 52.

30. P(A or B) with overlap (Cont.)

The result is 4 divided by 13.

31. Diagram of P(A or B)

More generally, let's consider an event A...

32. Diagram of P(A or B) (Cont.)

and an event B which overlaps with A.

33. Diagram of P(A or B) (Cont.)

The probability of A or B...

34. Diagram of P(A or B) (Cont.)

is the probability of A...

35. Diagram of P(A or B) (Cont.)

plus the probability of B.

36. Diagram of P(A or B) (Cont.)

But we have to subtract the overlap...

37. Diagram of P(A or B) (Cont.)

so we subtract the probability of A and B.

38. Diagram of P(A or B) (Cont.)

That is the formula to calculate the probability of A or B in general.

39. P(Jack or Heart) calculation in Python

In Python, you create the variables with the probabilities, add P underscore Jack and P underscore Hearts, subtract P underscore Jack underscore n underscore Hearts, and print the result. The probability of getting a Jack or a heart is 30%.

40. Let's calculate probabilities of two events

Let's calculate the probabilities of two events.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.