Probability

Conditional Probability and Bayes

↩ Back
01

Conditional Probability

Definition
Conditioning on an event

$P(A \mid B)$ reads "the probability of $A$ given $B$". Instead of comparing $A$ to the whole sample space $\Omega$, we compare it only to the part of $\Omega$ where $B$ happens.

$P(A \mid B) = \dfrac{P(A \cap B)}{P(B)}$
Rule
Multiplication rule

Rearranging the definition on the left gives a way to build a joint probability out of two simpler ones, one of them conditional on the other.

$P(A \cap B) = P(B) \cdot P(A \mid B)$

This extends to three or more events by conditioning on everything that came before.

$P(A \cap B \cap C) = P(A) \cdot P(B \mid A) \cdot P(C \mid A \cap B)$
Notation
Symbols introduced in this visual guide
SymbolMeaning
$P(A \mid B)$probability of $A$ given that $B$ has occurred
$A \perp B$$A$ and $B$ are independent
$\{B_1, \dots, B_n\}$a partition of $\Omega$: events that share no outcomes with each other, and that together include every outcome in the sample space
prior, $P(A)$what we believe about $A$ before seeing any evidence
likelihood, $P(B \mid A)$how likely the evidence $B$ is if $A$ is true
posterior, $P(A \mid B)$updated belief about $A$ after seeing the evidence $B$
Example
Two cards drawn without replacement
1
A standard deck has 52 cards, 4 of them kings. Draw one card, then draw a second one without putting the first back.
2
Let $A$ = "second card is a king" and $B$ = "first card is a king".
3
$P(A \cap B)$ is the probability that both cards are kings: $4$ choices for the first king out of $52$, then $3$ remaining kings out of $51$ for the second. $P(A \cap B) = \dfrac{4}{52} \times \dfrac{3}{51} = \dfrac{12}{2652} \approx 0.0045$.
4
$P(B)$ is just the probability the first card is a king: $P(B) = \dfrac{4}{52} \approx 0.077$.
5
Substituting both into the formula: $P(A \mid B) = \dfrac{P(A \cap B)}{P(B)} = \dfrac{0.0045}{0.077} \approx \dfrac{3}{51} \approx 0.059$.
6
This matches the direct count: once $B$ happens, only 3 kings remain among 51 cards, so $P(A \mid B) = \dfrac{3}{51}$, noticeably lower than the unconditional $P(A) = \dfrac{4}{52} \approx 0.077$.
02

Independence

Definition
Independent events

$A$ and $B$ are independent when finding out that one happened tells us nothing new about the other. Knowing $B$ occurred does not shift $A$'s probability at all.

$P(A \mid B) = P(A)$

Substituting this into the multiplication rule gives the usual test for independence.

$P(A \cap B) = P(A) \cdot P(B)$
Examples
Independent vs not independent
ScenarioEvent AEvent BP(A)P(A|B)Independent?
Two separate die rolls second die is 6 first die is 6 $\frac{1}{6} \approx 0.167$ $\frac{1}{6} \approx 0.167$ yes, equal
Drawing without replacement second card is a king first card is a king $\frac{4}{52} \approx 0.077$ $\frac{3}{51} \approx 0.059$ no, they differ
03

Law of Total Probability

Definition
Partition of the sample space

A partition is a group of events that satisfies two conditions:

  1. they can't happen at the same time
  2. together they cover the whole sample space, so the probability of their union is 1

Example

Every day the weather is classified as exactly one of three types.

1the day is sunny
2the day is cloudy
3the day is rainy

$\{\text{sunny}, \text{cloudy}, \text{rainy}\}$ is a partition.

Rule
Law of total probability

To find $P(A)$ when you don't know it directly, break the sample space into the branches of a partition $B_1, \dots, B_n$, then weight the probability of $A$ within each branch by how likely that branch is.

$P(A) = \sum_i P(A \mid B_i) \cdot P(B_i)$

With two branches, $B_1$ and $B_2$:

$P(A) = P(A \mid B_1) \cdot P(B_1) + P(A \mid B_2) \cdot P(B_2)$
Example
Two factories supply a warehouse

Two factories supply a warehouse. We want the probability that a randomly picked part is defective.

Factory 160% of parts, 2% defective
Factory 240% of parts, 8% defective

P(F1)probability that a part comes from Factory 1 = 0.6
P(F2)probability that a part comes from Factory 2 = 0.4
P(A|F1)probability that a part is defective, given it's from Factory 1 = 0.02
P(A|F2)probability that a part is defective, given it's from Factory 2 = 0.08

This calculates $P(A)$, the overall probability that a randomly picked part is defective:

$P(A) = 0.6 \times 0.02 + 0.4 \times 0.08 = 0.044$
04

Bayes' Theorem

Derivation
From the definition to Bayes' theorem

The definition of conditional probability works both ways: it can be written starting from $A$, or starting from $B$.

$P(A \cap B) = P(A) \cdot P(B \mid A)$
$P(A \cap B) = P(B) \cdot P(A \mid B)$

Equating both expressions we get Bayes' theorem:

$P(A \mid B) = \dfrac{P(B \mid A) \cdot P(A)}{P(B)}$

The denominator can be expanded with the law of total probability whenever $A$ and its complement form a partition.

$P(B) = P(B \mid A)P(A) + P(B \mid A^c)P(A^c)$
Example
A medical test is not the same as the disease

A disease affects part of the population, and a test can detect it, but not perfectly. We want the probability that a person actually has the disease, given that they tested positive.

D1% of the population has the disease
T | Dthe test is positive 90% of the time when the disease is present
T | Dcthe test is positive 5% of the time when the disease is absent (false alarm)

P(D)probability that a person has the disease = 0.01
P(T|D)probability of testing positive, given they have the disease = 0.9
P(T|Dc)probability of testing positive, given they don't have the disease = 0.05

First we need $P(T)$, the overall probability of testing positive, using the law of total probability:

$P(T) = P(T \mid D)P(D) + P(T \mid D^c)P(D^c) = 0.9 \times 0.01 + 0.05 \times 0.99 = 0.0585$

Now we can calculate $P(D \mid T)$, the probability that a person actually has the disease given a positive test:

$P(D \mid T) = \dfrac{P(T \mid D) \cdot P(D)}{P(T)} = \dfrac{0.9 \times 0.01}{0.0585} \approx 0.154 = 15\%$

Even after a positive result, there is only about a $15\%$ chance of actually having the disease, because false alarms from the huge healthy group outnumber true positives from the small sick group.

05

The Monty Hall Problem

Setup
Three doors, one car
1
A car sits behind one of three doors, goats behind the other two. You pick a door, say door 1.
2
The host, who knows where the car is, opens a different door that always reveals a goat.
3
You are offered a choice: stay with door 1, or switch to the remaining unopened door. Should you switch?
Reasoning
Why switching wins twice as often

Your first pick has a $\frac{1}{3}$ chance of being the car and a $\frac{2}{3}$ chance of being a goat. The host's move never changes those odds attached to your original door, it only tells you which of the other two doors to avoid.


StrategyWins the car whenProbability
Stayyour first pick was already the car$\frac{1}{3}$
Switchyour first pick was a goat, which is the more likely start$\frac{2}{3}$
Interactive
Play it yourself

Pick a door. The host will open one of the other two, always revealing a goat, then you decide: stay, or switch to the last unopened door.

1choose
2choose
3choose