Concept map / Probability
Share
Probability and conditional probability
Use a simulated screening test to distinguish sensitivity, false-positive rate, and the probability of a condition after a positive result.
11,000 people, one screening test
A screening test catches 90% of the people who have a condition. It also flags 10% of the people who do not. You test positive. How likely is it that you have the condition? The test’s own numbers cannot say. You also need the base rate: how common the condition is.
Each square below is one of 1,000 people. Group them by test result and look only at the positives. The probability you want is the share of those squares that have the condition.
Of 1,000 people, 100 have the condition, and 90 of them test positive. Of the 900 without it, 90 also test positive. So 90 of the 180 positives, 50.0%, really have the condition. The 90% the test catches answers a different question.
The counts are expected values. The squares round them; the percentages do not.
2A rare condition and a positive test
A condition affects 1 person in 100. A screening test is positive for 90% of the people who have it and for 10% of the people who do not. Someone picked at random tests positive. How likely is it that they have the condition?
3Same numerator, different group
Write D for having the condition and + for a positive test. The bar reads “given”. P(D | +) is the share with the condition among people who test positive. P(+ | D) is the share who test positive among people with the condition. Both count the same true positives on top. They divide by different groups.
Point at a tile or a colored term to light up its squares in section 1.
With your settings: (90 / 1,000) ÷ (180 / 1,000) = 0.09 ÷ 0.18 = 50.0%.
The same fraction by Bayes’ rule
Bayes’ rule writes the fraction with the three sliders. The top is the chance of having the condition and testing positive. The bottom adds the chance of testing positive without it.
With your settings: 0.9 × 0.1 = 0.09 and 0.1 × 0.9 = 0.09, so P(D | +) = 0.09 / (0.09 + 0.09) = 50.0%.
4When the test tells you nothing
If the test is positive for the same share of people with and without the condition, the two are independent. The condition is then as common among the positives as among the negatives and everyone else. The bars show the share with the condition in each group, scaled to the largest. Move the sliders until all three match.
The base rate is 10.0%. A positive result moves the chance of having the condition to 50.0%. A negative result moves it to 1.2%. The condition and the test result are dependent: knowing one changes the chance of the other. Multiplying the separate shares gives the wrong answer here: P(D) × P(+) = 0.1 × 0.18 = 0.018, but P(D and +) = 0.09.
5Check yourself
The tasks use the three sliders in section 1 and tick themselves when you meet them.
- Keep a good test: sensitivity at least 90% and false alarm rate at most 10%. Find a base rate above zero at which fewer than 1 in 10 positives have the condition.Now: Base rate 10.0%, test 90% and 10%, P(has it | positive) = 50.0%
- With an imperfect test, get P(has it | positive) within half a percentage point of P(positive | has it). This happens when the missed cases equal the false alarms.Now: P(has it | positive) = 50.0%, P(positive | has it) = 90.0%; 10 missed, 90 false alarms
- Make the test worthless: some people test positive, some test negative, and a positive result leaves the chance of having the condition at the base rate.Now: Base rate 10.0%, P(has it | positive) = 50.0%
6Build the table in R
The snippet builds the lab’s starting table of 1,000 people and divides the true positives by all positives, which gives 0.5. The last lines use Bayes’ rule at base rates of 10%, 2% and 1%, giving 0.500, 0.155 and 0.083.
Compute the probability of the condition after a positive resultShow the code
# 1,000 people, 100 of whom have the condition, as on the page
n <- 1000
n_d <- 100
# Sensitivity, P(positive | condition)
sens <- 0.90
# False-positive rate, P(positive | no condition)
fpr <- 0.10
tp <- n_d * sens
fp <- (n - n_d) * fpr
matrix(c(tp, n_d - tp, fp, n - n_d - fp), 2,
dimnames = list(test = c("pos", "neg"),
group = c("condition", "none")))
# P(condition | positive): true positives over all positives
tp / (tp + fp)
# The same by Bayes' rule, at prevalences of 10%, 2% and 1%
ppv <- function(prev) {
sens * prev / (sens * prev + fpr * (1 - prev))
}
round(ppv(c(0.10, 0.02, 0.01)), 3)Uses base R only.
What a positive result means
- If everyone is equally likely to be picked, the probability of picking someone with the condition is the share who have it.
- P(D | +) divides the true positives by everyone who tests positive. Sensitivity, P(+ | D), divides the same true positives by everyone who has the condition.
- With 90% sensitivity and a 10% false alarm rate, a positive result means a 50.0% chance of the condition at a 10% base rate, 15.5% at 2% and 8.3% at 1%.
- When the condition and the result are independent, a positive result leaves the chance at the base rate, so the test tells you nothing.
- For a rare condition, false positives can outnumber true positives. Bayes’ rule turns this calculation into a general way to update a probability after seeing evidence.
Recommended reading
- Introductory Statistics 2eBarbara Illowsky and Susan DeanChapter 3, probability rules and independence