Imagine a condition that affects 1 person in 100. A test has 99% sensitivity and 99%
specificity: it detects 99% of people who have the condition and correctly clears 99% of
people who do not. Your result is positive. The probability that you actually have the
condition is not 99%. With these numbers, it is about 50%. Bayes' rule
explains why.
Start with the four quantities
- Prior or base rate: how common the condition is before seeing the test.
- Sensitivity: P(positive | condition), the true positive rate.
- Specificity: P(negative | no condition), the true negative rate.
- Posterior: P(condition | positive), the probability you want after seeing the result.
Sensitivity and specificity describe the test after the true condition is known. The posterior
reverses the conditioning: it asks about the condition after the test result is known. Bayes'
rule performs that reversal by including the prior.
Why the answer is about 50%
Count 10,000 people. With a 1% prior, 100 have the condition and 9,900 do not. At 99%
sensitivity, 99 of the 100 affected people test positive. At 99% specificity, 1% of the 9,900
unaffected people also test positive, which is 99 false positives. The positive group therefore
contains 99 true positives and 99 false positives. The posterior is
99 / (99 + 99) = 0.50.
Bayes' rule can be understood as group counting. A small false positive rate applied to a very
large unaffected group can produce as many positive results as a high sensitivity applied to a
small affected group.
The two main levers
Two controls have especially strong effects on the posterior:
- The prior. Make the condition rarer while holding test quality fixed. The
false positives come from a much larger group, so the posterior usually falls.
- The specificity. Hold the prior fixed and increase specificity. The false
positive rate,
1 − specificity, shrinks, often raising the posterior sharply for
rare conditions.
The spam scenario uses the same structure
Select the spam-filter scenario. Spam is usually more common than a rare medical condition, so
the prior changes. The costs also change: a false positive sends a legitimate message to junk,
while a false negative lets spam through. The probability calculation has the same form even
though the interpretation and decision costs differ.
What this model leaves out
Real diagnostic tests often produce continuous measurements rather than a single positive or
negative label. Changing the decision threshold trades sensitivity against specificity. Multiple
test results may also be dependent, so they cannot always be multiplied as though each were new,
independent evidence. Real spam filters combine many features. The applet isolates the base-rate
mechanism before those complications are added.
For teachers
Curriculum: Conditional probability and Bayes' rule. Distinguish
P(test | condition) from P(condition | test), interpret a confusion matrix, and explain why
base rates matter.
Pre-exploration prompts:
- If a test is 99% sensitive and 99% specific, what else must you know before interpreting a positive result?
- How are sensitivity and specificity different from the probability that one positive result is correct?
- Why can a low false positive rate still create many false alarms?
Post-exploration prompts:
- Set prior, sensitivity, and specificity to 1%, 99%, and 99%. Reconstruct the result with 10,000 people.
- Lower the prior to 0.1% while keeping test quality fixed. Which count changes most?
- Hold the prior at 1% and raise specificity. Why is this control so influential?
- Switch to spam filtering. Which probability structure stays the same, and which decision costs change?
Misconceptions to test: test accuracy equals the posterior; a positive result
means the condition is probably present; Bayes' rule is detached from ordinary counting.
设想某种情况在 100 人中影响 1 人。某项检测的灵敏度和特异度都为 99%:它能检出 99% 的患病者,也能正确排除 99% 的未患病者。你的检测结果为阳性。你真正患有该情况的概率并不是 99%。按照这些数值,答案约为 50%。贝叶斯定理解释了原因。
先明确四个量
- 先验概率或基率:在看到检测结果之前,该情况有多常见。
- 灵敏度:P(阳性 | 患病),也就是真阳性率。
- 特异度:P(阴性 | 未患病),也就是真阴性率。
- 后验概率:P(患病 | 阳性),即看到结果后真正想求的概率。
灵敏度和特异度描述的是在真实情况已知时检测如何表现。后验概率把条件反过来:在检测结果已知时,真实情况有多可能。贝叶斯定理通过加入先验概率完成这种条件转换。
为什么答案约为 50%
以 10,000 人为例。先验概率为 1%,因此 100 人患病,9,900 人未患病。灵敏度为 99%,所以 100 名患病者中有 99 人检测为阳性。特异度为 99%,意味着 9,900 名未患病者中有 1% 也会检测为阳性,即 99 个假阳性。因此阳性人群中有 99 个真阳性和 99 个假阳性。后验概率为 99 / (99 + 99) = 0.50。
贝叶斯定理可以理解为对不同人群进行计数。即使假阳性率很低,只要它作用于一个非常大的未患病人群,产生的阳性数量也可能与小型患病人群中的真阳性一样多。
两个主要杠杆
下面两个控制量对后验概率尤其重要:
- 先验概率。保持检测质量不变,让该情况变得更罕见。假阳性来自更大的人群,因此后验概率通常会下降。
- 特异度。保持先验概率不变并提高特异度。假阳性率
1 − 特异度 会降低,这通常会显著提高罕见情况的后验概率。
垃圾邮件情境使用相同结构
选择垃圾邮件过滤情境。垃圾邮件通常比罕见疾病更常见,因此先验概率不同。错误的代价也不同:假阳性会把正常邮件送入垃圾箱,假阴性则会让垃圾邮件通过。概率计算的结构相同,解释和决策成本却不同。
这个模型省略了什么
真实诊断检测通常产生连续测量值,而不是单一的阳性或阴性标签。改变判断阈值会在灵敏度和特异度之间形成权衡。多次检测结果也可能相互依赖,因此不能总把它们当作独立的新证据直接相乘。真实垃圾邮件过滤器会组合大量特征。本工具先单独呈现基率机制,再让学习者理解这些更复杂的情况。
教师指导
课程目标:条件概率与贝叶斯定理。区分 P(检测 | 真实情况) 与 P(真实情况 | 检测),解释混淆矩阵,并说明基率为什么重要。
探索前问题:
- 如果某项检测的灵敏度和特异度都是 99%,在解释阳性结果前还必须知道什么?
- 灵敏度和特异度与某一次阳性结果正确的概率有什么不同?
- 为什么很低的假阳性率仍可能产生许多误报?
探索后问题:
- 把先验概率、灵敏度和特异度设为 1%、99% 和 99%,用 10,000 人重新计算结果。
- 保持检测质量不变,把先验概率降到 0.1%。哪一组人数的变化最关键?
- 把先验概率保持在 1%,提高特异度。为什么这个控制量影响如此大?
- 切换到垃圾邮件过滤。哪些概率结构保持不变,哪些决策成本发生变化?
需要检验的误解:检测准确率等于后验概率;阳性就意味着很可能患病;贝叶斯定理与普通计数无关。