Interactive demo · Probabilistic Machine Learning · Chapter 2

Bayes' rule for a diagnostic test

A test has a sensitivity p(Y=1|H=1) and a specificity p(Y=0|H=0), and the condition has a prevalence p(H=1), the prior. Bayes' rule turns these three numbers into the probability of being infected after a positive or a negative result. When the condition is rare, most positives are false positives, so a positive result can leave you far below 50%. The left panel is a mosaic of the whole population: the width of a column is the prior, the height of a block is the likelihood, and the posterior is the share of the positive row that is dark.

Prevalence p(H=1), log scale

Sensitivity p(Y=1|H=1)

Specificity p(Y=0|H=0)

Independent positive tests taken (shown in the readout)

Try these

Population of 100,000. Repeated tests are assumed conditionally independent given H, so each positive result multiplies the odds by the likelihood ratio sensitivity / (1 − specificity). Prevalences below 0.1% are drawn with a minimum column width so the infected strip stays visible.

In the lecture notes