Conditional Probability

Master conditional probability, multiplication rule, and reduced sample spaces.

22 min read
Intermediate

Introduction

Conditional probability captures how our beliefs update with new information. It's fundamental to Bayes' theorem, machine learning, and all statistical inference.

Learning Objectives:

  • Master conditional probability definition
  • Apply the multiplication rule
  • Understand reduced sample spaces

Conditional Probability

The conditional probability of AA given BB is:

P(AB)=P(AB)P(B),P(B)>0P(A | B) = \frac{P(A \cap B)}{P(B)}, \quad P(B) > 0

Read as "probability of AA given BB has occurred."

Intuition: When BB occurs, the sample space "shrinks" to BB. We ask: within this reduced space, what fraction contains AA?

python
import random

def simulate_conditional(n=10000):
    # Die roll: P(even | >3)
    count_B = 0  # >3
    count_A_and_B = 0  # even AND >3
    
    for _ in range(n):
        roll = random.randint(1, 6)
        if roll > 3:
            count_B += 1
            if roll % 2 == 0:
                count_A_and_B += 1
    
    p_A_given_B = count_A_and_B / count_B if count_B > 0 else 0
    
    print(f"P(even | >3) simulated: {p_A_given_B:.4f}")
    print(f"Theoretical: 2/3 = 0.6667 (outcomes {{4,5,6}}, even are {{4,6}})")

simulate_conditional()

Multiplication Rule

Rearranging the definition:

P(AB)=P(AB)P(B)=P(BA)P(A)P(A \cap B) = P(A | B) \cdot P(B) = P(B | A) \cdot P(A)

Use: Calculate joint probabilities from conditional ones.

Key Takeaways

  1. Definition: P(AB)=P(AB)/P(B)P(A|B) = P(A \cap B) / P(B)
  2. Multiplication rule: P(AB)=P(AB)P(B)P(A \cap B) = P(A|B) P(B)
  3. Reduced space: Conditioning shrinks sample space to BB

Next: Law of total probability and Bayes' theorem!

Interactive Playground

Experiment with these interactive tools to deepen your understanding.

🔮 Interactive: Bayes' Theorem Calculator

A disease affects 1% of the population. A test is 95% accurate for positive cases and has 5% false positive rate.

Bayes' Theorem
P(A|B) = P(B|A) × P(A) / P(B)
P(Has Disease|Tests Positive) = 0.95 × 0.010 / 0.059
P(Has Disease | Tests Positive)
16.1%
Update ratio: 16.1x the prior
Probability Tree (per 1000 cases)
1000 Total
Has Disease: 10
No Has Disease: 990
+: 10
-: 1
+: 50
-: 941

Of those who test positive (59), only 10 actually have the condition.

💡 Base Rate Neglect: Even with a highly accurate test, a low prior probability dramatically reduces the posterior. This is why false positives dominate when testing for rare events!

⭕ Interactive: Venn Diagram Visualizer

A only25%A∩B15%B only35%Neither: 25%AB
P(A ∪ B) = 75%
P(A|B) = 30%
P(B|A) = 37%
P(¬A ∩ ¬B) = 25%

💡 Conditional Probability: P(A|B) zooms into circle B and asks what fraction is also in A. Notice how P(A|B) changes as you adjust the intersection!

🔗 Interactive: Independence Tester

Generate data from independent or dependent events and see how the statistics differ.

Total trials: 0
P(A) = 0.0%
P(B) = 0.0%
Independence Test:
P(A ∩ B) observed:
0.0%
P(A) × P(B) expected:
0.0%
P(A|B):0.0%(should ≈ P(A) if independent)

💡 Key Insight: For independent events, P(A|B) = P(A). The intersection P(A ∩ B) equals the product P(A) × P(B). Generate dependent data to see how this breaks!