oldoc63 / learningDS

Learning DS with Codecademy and Books
0 stars 0 forks source link

Rules of Probability: Addition Rule #416

Open oldoc63 opened 2 years ago

oldoc63 commented 2 years ago

Probability is a way to quantify uncertainty. When we flip a fair coin, we say that there is 50% chance (probability=0.5) of it coming up tails. This means that if we flip INFINITELY many fair coins, half of them will come up tails. Similarly, when we roll a six-sided die, we say there is a 1 in 6 chance of rolling a 5.

What if we flip a coin in one hand and roll a die in the other at the same time. What is the probability that the coin comes up tails AND the die comes up as a five? Is there is a way to quantify the probability that these two different events BOTH occur? In this lesson, we will walk through different rules of probability that help us quantify the probability of multiple random events.

oldoc63 commented 2 years ago

Union, Intersection and Complement

Union

The union of two sets encompasses any element that exists in either one or both of them. We can represent this visually as a Venn diagram.

Image

oldoc63 commented 2 years ago

Let's say we have two sets, A and B. A represents rolling and odd number with a six-sided die (the set {1, 3, 5}. B represents rolling a number greater than 2 (the set {3, 4, 5, 6}. The union of these two sets would be everything in either set A, set B, or both: {1, 3, 4, 5, 6}. We can write the union of two events mathematically as (A or B).

oldoc63 commented 2 years ago

Intersection

The intersection of two sets encompasses any element that exists in both of the sets.

Image

oldoc63 commented 2 years ago

The intersection of the above sets (A represents rolling an odd number on a six sided die and B represents rolling a number greater than two) includes any value that appears in both sets: {3, 5}. We can write the intersection of two events mathematically as (A and B).

oldoc63 commented 2 years ago

Complement

The complement of a set consist of all possible outcomes outside of the set.

Image

oldoc63 commented 2 years ago

Consider set A from the above example (rolling an odd number from a six-sided die). The complement of this set would be rolling an even number: {2, 4, 6}. We can write the complement of set A as $A^C$. One key feature of complements is that a set and its complement cover the entire sample space. In this die roll example, the set of even numbers and odd numbers would cover all possible rolls: {1, 2, 3, 4, 5, 6}.

oldoc63 commented 2 years ago

Independence and Dependence

Imagine that we flip a fair coin 5 times and get 5 heads in a row. Does this affect the probability of getting heads on the next flip? Even though we may feel like it's time to see "tails", it is impossible for a past coin flip to impact a future one. The fact that previous coin flips do not affect future ones is called independence. Two events are independent if the occurrence of one event does not affect the probability of the other.

Are there cases where the previous events do affect the outcome of the next event? Suppose we have a bag of five marbles: two marbles are blue and three marbles are red. If we take one marble out of the bag, what is the probability that the second marble we take out is blue?

Image

oldoc63 commented 2 years ago

This describes two events that are dependent. The probability of grabbing a blue marble in the second event depends on whether we take out a red or a blue marble in the first event.

What if we had to put back the first marble? Is the probability that we pick a blue marble second independent or dependent on what we pick out first? In this case, the events would be independent.

oldoc63 commented 2 years ago

Why do we care if events are independent or dependent? Knowing this helps us quantify the probability of events that depends on preexisting knowledge. This helps researchers understand and predict complex processes such as: Effectiveness of vaccines, the weather on a particular day, betting odds for professional sports games.

oldoc63 commented 2 years ago

Mutually Exclusive Events

Two events are considered mutually exclusive if they cannot occur at the same time. Consider a single coin flip: the events "tails" and "heads" are mutually exclusive because we cannot get both tails and heads on a single flip.

We can visualize two mutually exclusive events as a pair of non-overlapping circles. They do not overlap because there is no outcome for one event that is also in the sample space for the other.

What about events that are not mutually exclusive? If event A is rolling an odd number and event B is rolling a number greater than two, these events are not mutually exclusive. They have an intersection of {3, 5}. Any event that have a non-empty intersection are not mutually exclusive.

oldoc63 commented 2 years ago

Addition Rule

Now, it's time to apply these concepts to calculate probabilities.

Let's go back to one of our first examples: event A is rolling an odd number on a six-sided die and event B is rolling a number greater than two. What if we want to find the probability of one or both events occurring? This is the probability of the union of A and B:

$$ P(A or B) $$

Image

oldoc63 commented 2 years ago

This animation gives a visual representation of the addition rule formula, which is:

$$ P(A or B) = P(A) + P(B) - P(A and B) $$

We subtract the intersection of events A and B because it is included twice in the addition of P(A) and P(B).

oldoc63 commented 2 years ago

What if the events are mutually exclusive? On a single die roll, if event A is that the roll is less than or equal to 2 and the event B is that the roll is greater than or equal to 5, then the events A and B cannot both happen.

Image

oldoc63 commented 2 years ago

For mutually exclusive events, the addition rule formula is:

$$ P(A or B) = P(A) + P(B) $$

This is because the intersection is empty, so we don't need to remove any overlap between the two events.

oldoc63 commented 2 years ago

Following, there is a function, prob_a_or_b() which calculates the addition rule. It takes three arguments:

In prob_a_or_b(), the probability of a and b as well as the probability of their intersection has been calculated in the following variables:

Using these variables, write a return statement that returns the probability of events a or b occurring.

oldoc63 commented 2 years ago

There are three different random events outlined through sets. The first one is below the following comment:

Call prob_a_or_b() using the following variables:

Be sure to wrap your function call in a print() statement. Add your line of code below the following comment:

oldoc63 commented 2 years ago

The second random scenario is below the following comment:

oldoc63 commented 2 years ago

The final random scenario is: