Conditional probability and Bayes' theorem: disease testing
MathematicsProbabilityAges 17–18
Use it with your class: students open it from a link or a QR code, with no account needed.
A medical-testing problem: disease prevalence, sensitivity P(+|disease), and specificity P(−|healthy) are given. A tree diagram, a 2×2 table for N people, and a grid of 1000 colored dots show why the true probability of having the disease given a positive test, P(disease|+), is often much lower than the sensitivity; drag the sliders to watch the total probability formula and Bayes' theorem change. The Survey screen has an editable two-way table for two categorical variables with joint, marginal and row or column conditional relative frequencies, a segmented bar chart, a tree or Venn diagram, and a check of P(A|B) against P(A) to judge association or independence.
Lesson: Conditional probability, the law of total probability, and Bayes' theorem
What it shows
A medical test is described by its sensitivity P(+|B) and specificity P(−|B̄), but a patient needs P(B|+). The law of total probability gives P(+), and Bayes' theorem gives P(B|+) = P(B)·P(+|B)/P(+); when prevalence is low, false positives can outnumber true positives. The Survey screen applies the same ideas to a two-way table of counts: joint, marginal and conditional relative frequencies, a segmented bar chart and a tree diagram. Two variables are independent when P(A|B) = P(A), that is P(A ∩ B) = P(A)·P(B). The survey data are illustrative.
How to use
On Medical test (Bayes), set prevalence to 1%, sensitivity to 95% and specificity to 90%, estimate P(B|+), then compare with the tree, the table and the dot grid. On Survey: two-way table, pick a Data set, edit the counts, and switch between Counts, % of total, % of row and % of column. Click a cell to choose events A and B, compare the bars with the All bar, and read whether P(A|B) differs from P(A).
Parameters you can change
- Disease prevalence in the population P(B) 0.1–50 %
- Sensitivity P(+|B): positive given disease 50–100 %
- Specificity P(−|B̄): negative given no disease 50–100 %
- Number of people in the 2×2 table 1000–100000
- Screen Medical test (Bayes), Survey: two-way table
- Survey data set Curfew and chores, Hand used and coin result, Age and way to school, Screen time before bed and sleep
- Survey table shows Counts, Joint relative frequencies, Row relative frequencies, Column relative frequencies
- Diagram on the Survey screen Tree diagram, Venn diagram
Questions to explore
- With 1% prevalence, 95% sensitivity and 90% specificity, why is P(B|+) so low?
- How does P(B|+) change as the prevalence rises from 1% to 20%?
- Assuming the two tests are independent, a positive person is retested: with the first P(B|+) as prevalence, what is the new P(B|+)?