Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Conditional Probability and the Multiplication Rule for Independent Events

Hello! In the previous lesson, you counted rows satisfying or , subtracting the overlap so those rows were not counted twice. This time, the overlap itself is the focus. How do you calculate the chance of both events—and what changes when you already know that one has occurred?

You will estimate conditional probabilities from the same small dataset, derive the multiplication rule from those counts, and see when independence permits a simpler calculation. This is the groundwork for reasoning about repeated yes/no outcomes later in the course.


Conditioning changes the denominator

Suppose a row has category alpha and a Boolean flag. Let mean “category is alpha” and mean “flag is True.” The question “What is the probability of , given ?” asks you to consider only rows where holds. Its notation is , read “probability of given .”

Watch how narrowing the set of eligible observations changes the denominator. The second clip distinguishes this question from both its reverse and the probability of the overlap.

Conditional Probability - Stanford, Probability for AI

In “Conditional Probability - Stanford, Probability for AI,” Code in Place develops conditional probability by counting within a selected group. Watch for which observations remain eligible after a condition is given.

In the movie-watching example, start at the selected group: the presenter counts viewers of one film, then asks what fraction of those viewers also watched another. Next, watch three questions to compare the two possible conditioning directions with the probability of watching both films.

Return to the twelve fully observed rows from the previous lesson. Four have category alpha, six have a True flag, and two have both. If one row is selected uniformly from these twelve, then

The denominator is four, not twelve: you were told the selected row belongs to . Reversing the condition gives a different question:

The numerator is the same overlap, but the eligible group changes. Neither conditional probability is the joint probability , which uses all twelve rows as its denominator.

In general, provided ,

Conditioning does not mean that caused . It means that the probability is calculated within outcomes where is known to hold. If , this ordinary conditional probability is undefined: there is no eligible group to divide by.

You can see the denominator change directly in pandas:

import pandas as pd

df = pd.DataFrame({
    "category": ["alpha"] * 4 + ["beta"] * 3 + ["gamma"] * 5,
    "flag": [
        True, True, False, False,       # alpha
        True, False, False,             # beta
        True, True, True, False, False  # gamma
    ]
})

a = df["category"].eq("alpha")
b = df["flag"]

print(b.loc[a].mean())    # P(B given A): 2 / 4 = 0.5
print(a.loc[b].mean())    # P(A given B): 2 / 6
print((a & b).mean())     # P(A and B):   2 / 12

b.loc[a] selects the flag values among alpha rows; taking their mean finds the share that are True. Before computing a conditional share in a larger dataset, make sure the eligible rows have enough nonmissing information to classify both events. Otherwise, a silently changing denominator can answer a different question.


The general multiplication rule

The definition of conditional probability can be rearranged. Multiplying both sides of the preceding equation by gives

This is the general multiplication rule. It says: take the chance of reaching , then take the chance of within . It applies whether the events are independent or dependent. You can equally well start with :

The video below derives both versions and introduces the special case of independence. Pay particular attention to the conditional probability in the general rule; it must not be replaced with an unconditional probability without justification.

Multiplication & Addition Rule - Probability - Mutually Exclusive & Independent Events

“Multiplication & Addition Rule - Probability - Mutually Exclusive & Independent Events,” from The Organic Chemistry Tutor, connects the conditional-probability definition to the multiplication rule and shows exactly what independence simplifies.

Watch both orders for the two ways to calculate an intersection. Continue with independence, noting which conditional factor becomes an ordinary event probability.

Our row counts make the algebra tangible. Starting with , four of the twelve rows qualify; within those four, two have the flag:

Starting with gives the same result: . The intermediate denominators differ, but both calculations count the same two rows out of twelve.

Notice the distinction from the previous lesson. For or , you used the addition rule and corrected for overlap. For and , you can calculate the overlap by multiplying one event’s probability by the appropriate conditional probability. Simply multiplying and is not the general rule.


When can the conditional factor be simplified?

Events and are independent if knowing whether one occurred does not change the probability of the other. For , a way to check the definition is

Substituting this equality into the general rule yields the independence shortcut:

In the twelve-row distribution, alpha and a True flag happen to satisfy it exactly: , while . You can verify it from the other direction too: .

Now let mean “category is beta.” One of the three beta rows has a True flag, so

These events are not independent. The general rule correctly gives

Using the independence shortcut without checking would instead give .

c = df["category"].eq("beta")

print(b.loc[c].mean())       # P(B given C): 1/3
print(b.mean())              # P(B):         1/2
print((c & b).mean())        # Joint share:  1/12
print(c.mean() * b.mean())   # Incorrect shortcut here: 1/8

An exact equality in a small table describes the distribution formed by selecting uniformly from these twelve rows. If the rows are a sample from a larger population, that equality alone does not establish population independence. Conversely, a difference in a sample might partly reflect sampling variation. For a probability model, independence is an assumption about how outcomes are generated, or a property established from that model—not merely a convenient instruction to multiply.

It also differs sharply from mutual exclusivity. alpha and beta are mutually exclusive categories: a row cannot have both. Since both categories have positive probability, learning that a row is alpha changes the chance it is beta from to zero. Thus they are not independent.

Repeated draws make the role of the sampling mechanism especially clear. Read the comparison of drawing two aces with and without replacing the first card:

2.3 Multiplication · Probability For Data Science

Read the “Two Aces in Two Cards” example in Probability For Data Science to see why finding the chance of both draws still calls for the general multiplication rule, while replacement changes the second factor.

In Section 2.3, “Multiplication,” find the subsection “Example 1: Two Aces in Two Cards.” Read the two-draw comparison, beginning with the deck description and ending after the explanation that an intersection requires multiplication. Focus on the chance of a second ace given a first ace in each sampling setup.

Without replacement, a first ace leaves three aces among 51 cards, so the chance of two aces is . With replacement, the deck is restored before the second draw, so it is . You multiply in both cases. Independence determines whether the conditional second factor equals the original ace probability.

A small simulation can check the contrast. Here first records whether the first card is an ace. For the draw without replacement, the second-ace chance is after an ace but after a non-ace.

import numpy as np

rng = np.random.default_rng(42)
trials = 50_000

first = rng.random(trials) < 4 / 52

second_with_replacement = rng.random(trials) < 4 / 52
second_without_replacement = (
    rng.random(trials) < np.where(first, 3 / 51, 4 / 51)
)

print((first & second_with_replacement).mean())
print((first & second_without_replacement).mean())

print((4 / 52) * (4 / 52))  # Theoretical: with replacement
print((4 / 52) * (3 / 51))  # Theoretical: without replacement

The simulated shares should be near, not necessarily equal to, their theoretical values. The conditional second-draw probabilities—not the mere fact that there are two draws—explain the difference.


Key takeaways

A conditional probability restricts the denominator to outcomes satisfying the given event. Thus and generally differ, even though they refer to the same overlap.

For an intersection, the rule that always applies is

Only when the events are independent can you replace with . Check the event definitions or the sampling mechanism before making that replacement; mutually exclusive positive-probability events are not independent.

Next, you will use a different shortcut—the complement rule—to calculate chances such as “at least one success” without listing every way it could happen.

Can't find a good explanation? Sign up and we'll make it for you

Sign up