Statistics Conditional Probability
Conditional probability measures how the likelihood of an event changes once you already know that some other event has happened.
What Is Conditional Probability?
Conditional probability answers a very specific question: given that we already know something happened, how likely is another event? The plain probability that a random person owns a winter coat is different from the probability that someone living in a cold climate owns one — new information shifts the odds. We write this as P(A|B), read as 'the probability of A given B'.
The Conditional Probability Formula
The formula is P(A|B) = P(A ∩ B) / P(B), where P(A ∩ B) is the probability that both A and B happen, and P(B) is the probability that B happens at all. This only makes sense when P(B) is greater than zero — you cannot condition on an event that never occurs. In plain terms: out of all the times B happens, what fraction of those times does A also happen?
Example: Drawing a King Given a Face Card
total_cards = 52
kings = 4
face_cards = 12 # Jacks, Queens, Kings: 4 of each
p_a_and_b = kings / total_cards # P(King AND Face card) = P(King), since every king is a face card
p_b = face_cards / total_cards # P(Face card)
p_a_given_b = p_a_and_b / p_b
print(f"P(King | Face card) = {p_a_given_b:.4f}") # 0.3333- P(Exercises) = 120/200 = 0.60
- P(Sick) = 50/200 = 0.25
- P(Sick AND Exercises) = 20/200 = 0.10
- P(Sick | Exercises) = 0.10 / 0.60 ≈ 0.167 — noticeably lower than the overall 25%, which hints that exercise and sickness are related
Verifying the Table Calculation
exercises_and_sick = 20
exercises_total = 120
overall_sick = 50
population = 200
p_sick_given_exercise = exercises_and_sick / exercises_total
p_sick_overall = overall_sick / population
print(f"P(Sick | Exercises) = {p_sick_given_exercise:.3f}") # 0.167
print(f"P(Sick) overall = {p_sick_overall:.3f}") # 0.250Independent vs Dependent Events
Two events are independent when knowing one tells you nothing new about the other — mathematically, P(A|B) = P(A). If the conditional probability differs from the plain probability, the events are dependent: one influences the likelihood of the other, as we just saw with exercise and sickness.
Checking Independence with a Die Roll
outcomes = list(range(1, 7)) # a fair six-sided die
event_a = {2, 4, 6} # rolling an even number
event_b = {5, 6} # rolling a number greater than 4
p_a = len(event_a) / len(outcomes)
p_b = len(event_b) / len(outcomes)
p_a_and_b = len(event_a & event_b) / len(outcomes)
p_a_given_b = p_a_and_b / p_b
print(f"P(A) = {p_a:.3f}, P(A|B) = {p_a_given_b:.3f}") # both 0.500 -> independentExercise: Statistics Probability
How is the probability of an event found when outcomes are equally likely?