Statistics · medium

Explain Bayes' theorem with a real example.

Asked in Data Scientist interviews, in the Statistics round.

Short answer

Posterior is proportional to prior times likelihood. A 99% accurate test for a 1 in 1,000 condition still gives a positive result that is wrong about 90% of the time, because the false positives from the healthy majority outnumber the true positives.

How to answer it

Definition

A rule for updating a belief when evidence arrives. It converts what you knew before, the prior, into what you should believe now, the posterior, using how likely the evidence would be under each hypothesis.

Formula

P(A | B)  =  P(B | A) * P(A) / P(B)

posterior =  likelihood * prior / evidence

Example

A disease affects 1 in 1,000 people. The test catches 99% of cases and has a 5% false-positive rate. You test positive. What is the probability you have it?

Out of 100,000 people:

    100 have it        ->    99 test positive
 99,900 do not         -> 4,995 test positive   (5% of 99,900)

positives total = 99 + 4,995 = 5,094
P(disease | positive) = 99 / 5,094 = 1.9%

Output

A 99%-accurate test, and a positive result still means about a 2% chance.

Why it feels wrong

Because the base rate is doing the work. The disease is so rare that the 5% false positives from the enormous healthy group swamp the 99% true positives from the tiny sick group. Ignoring that is the base rate fallacy, and it is the reason this question gets asked.

Working in counts out of 100,000 rather than in probabilities makes it obvious and is much harder to get wrong under pressure.

Key points

FAQ

The 30-second answer

Bayes' theorem updates a prior belief with evidence to give a posterior. The example I would use is a rare disease: one in a thousand people have it, the test catches ninety-nine percent of real cases and has a five percent false-positive rate.
Out of a hundred thousand people, a hundred are sick and ninety-nine of them test positive. Ninety-nine thousand nine hundred are healthy and about five thousand of them also test positive. So a positive result means roughly a two percent chance of actually having it.
The point is that the base rate dominates. The healthy group is so much larger that its false positives swamp the true ones. And I would work it in counts rather than probabilities, because that makes it obvious and is much harder to fumble under pressure.

In the interview

Practice this for real