Learn
Lesson · Discrete Probability · Conditioning

Bayes' Theorem

P(A|B) = P(B|A)P(A)/P(B) converts one conditional into the other. Applied to a medical test with a rare disease, it produces an answer most people — including most doctors — get badly wrong.

P(A|B) = P(B|A)·P(A) / P(B) P(B) = P(B|A)P(A) + P(B|Ā)P(Ā) law of total probability P(A) is the PRIOR; P(A|B) is the POSTERIOR A rare condition means most positives are FALSE positives.
Reversing the conditional

Core ideas

What this lesson establishes

The theorem is one line of algebra. Its consequences are the reason this lesson exists.

1

It follows immediately from the definition

Both P(A|B)P(B) and P(B|A)P(A) equal P(A ∩ B), so they are equal to each other. Dividing gives the theorem.

2

The denominator needs the law of total probability

P(B) is usually computed by splitting on A and Ā, which is where the base rate enters the calculation.

3

The base rate dominates for rare events

A 99%-accurate test for a disease affecting 1 in 10 000 produces about 100 false positives for every true one.

The material

Bayes' theorem

The statement, the total-probability denominator, and the medical-test calculation.

Theorem · Law of total probability

If A₁, …, A_n partition S with each P(Aᵢ) > 0, then P(B) = Σᵢ P(B|Aᵢ)P(Aᵢ). The two-case form is P(B) = P(B|A)P(A) + P(B|Ā)P(Ā).

The sets B ∩ Aᵢ are disjoint with union B, so by additivity P(B) = Σ P(B ∩ Aᵢ), and each term is P(B|Aᵢ)P(Aᵢ) by the multiplication rule.

□

Theorem · Bayes' theorem

For events with P(A), P(B) > 0, P(A|B) = P(B|A)P(A) / P(B), where P(B) is normally expanded by the law of total probability.

P(A ∩ B) = P(A|B)P(B) and P(A ∩ B) = P(B|A)P(A). Setting the two equal and dividing by P(B) gives the result.

□

The medical test

A disease affects 1 in 1000 people. A test detects it in 99% of those who have it, and gives a false positive in 5% of those who do not. You test positive. What is the probability you have the disease?

P(D) = 0.001 prior — the base rate P(+ | D) = 0.99 sensitivity P(+ | D̄) = 0.05 false positive rate P(+) = P(+|D)P(D) + P(+|D̄)P(D̄) = 0.99 × 0.001 + 0.05 × 0.999 = 0.00099 + 0.04995 = 0.05094 P(D | +) = 0.00099 / 0.05094 ≈ 0.0194

About 2%. A positive result on a 99%-sensitive test leaves you 98% likely not to have the disease, because the test is applied to a population in which almost nobody does.

The same calculation in frequencies

Imagine 100 000 people: 100 have the disease → 99 test positive 99 900 do not → 4 995 test positive total positives = 5 094, of whom 99 actually have it 99 / 5094 ≈ 2%

The frequency version is the same arithmetic and is far easier to believe. It is worth doing both ways every time: the formula gives the number and the frequencies explain it.

The error the calculation prevents is base-rate neglect: reading P(+ | D) = 0.99 as though it were P(D | +). The two differ by the factor P(D)/P(+), and when the disease is rare that factor is enormous.

Interactive

Bayes calculation

A million people, four whole-number cells

One million people
true positivesfalse positives

Method

Applying Bayes

Write the prior down first; it is the number people forget.

1

Name the events and write the given conditionals

"Sensitivity" is P(+|D); "false positive rate" is P(+|D̄). Neither is the number you were asked for.

2

Write the prior

The base rate P(A). Omitting it is the error the whole lesson is about.

3

Expand the denominator

P(B) = P(B|A)P(A) + P(B|Ā)P(Ā). Both branches contribute, and for rare conditions the second dominates.

4

Sanity-check with frequencies

Take a population of 100 000 and count. If the two methods disagree, the arithmetic is wrong; if they agree, the surprising answer is right.

Bayes

Score 0 / 0

The same test, a common condition

Identical test, but the condition affects 30% of those tested.

P(D) = 0.30 P(+|D) = 0.99 P(+|D̄) = 0.05 P(+) = 0.99 × 0.30 + 0.05 × 0.70 = 0.297 + 0.035 = 0.332 P(D|+) = 0.297 / 0.332 ≈ 0.895 Compare with the rare case: P(D) = 0.001 ⟹ P(D|+) ≈ 0.019 SAME TEST. The prior moved from 0.001 to 0.30 and the answer moved from 2% to 89%.

This is why screening a whole population and testing a symptomatic patient are different acts with the same instrument. The test did not change; the population it was applied to did, and the posterior depends on both.

Common mistakes

1
Reporting the sensitivity as the answerP(+|D) = 0.99 is a property of the test. P(D|+) is what the patient wants and depends on the population as well.
2
Omitting the false-positive branch of the denominatorFor a rare condition that branch is almost all of P(B). Dropping it produces an answer near 1 instead of near 0.
3
Trusting the formula without the frequency checkThe frequency version takes thirty seconds and makes the surprising answer believable rather than merely computed.

Check your understanding

✓
Finish when you can do the calculation both ways.

Take a test with 95% sensitivity and 10% false positives for a condition affecting 2% of the population. Compute P(D|+) by the formula, then by counting a population of 10 000: you should find 190 true positives against 980 false ones, so about 16%. The agreement is the point.

Note: Bayes' theorem is also the foundation of a whole approach to statistics, in which the prior encodes belief before the data and the posterior encodes it afterwards. The mathematics here is the same; what is contested is where priors come from.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.