A Positive Test Does Not Mean What You Think
Sarah takes a screening test for a rare disease. The doctor tells her the test is 95% accurate. She tests positive. Most people would assume she has a 95% chance of being sick. She does not. The actual probability is closer to 8.7%. The disease affects only 1 in 100 people, and that base rate changes everything. This counterintuitive result is the heart of Bayes' theorem, and it is why this calculator exists.
What This Calculator Does and Why It Matters
This tool computes posterior probability using Bayes' theorem. You provide a prior probability, a likelihood, and evidence, and it returns the updated probability along with a full step-by-step breakdown. It runs in two modes. Medical mode takes prevalence, sensitivity, and specificity, then computes the probability of having a condition after a positive test. General mode takes a prior P(A), a likelihood P(B|A), and a marginal P(B), then computes P(A|B) directly.
Bayes' theorem matters because it corrects one of the most common errors in human reasoning: ignoring base rates. Doctors, lawyers, and analysts make this mistake regularly. A test can be highly accurate and still produce mostly false positives when the condition is rare. The math reveals that, and the calculator shows you each step so you can verify the logic yourself. For related tools, see our Probability Calculator, the Confidence Interval Calculator, and the Statistics Calculator.
How the Calculation Works
Bayes' theorem relates three probabilities. The prior P(A) is your belief before seeing evidence. The likelihood P(B|A) is the probability of the evidence if A is true. The marginal P(B) is the total probability of the evidence under all hypotheses. The posterior P(A|B) is your updated belief after seeing the evidence. The formula is:
P(A|B) = P(B|A) · P(A) / P(B)
In the medical case, P(B) is not given directly. You compute it by adding the true positive contribution and the false positive contribution: P(B) = P(B|A) · P(A) + P(B|not A) · P(not A). Here P(B|not A) is the false positive rate, which equals 1 minus specificity. This is why a low prevalence shrinks the true positive term and lets false positives dominate.
The error people make is called the base rate fallacy. They focus on the test accuracy (the likelihood) and forget how common the condition is (the prior). When the prior is small, even a strong likelihood produces a small posterior because the denominator is inflated by false positives from the large healthy population. Bayes' theorem forces you to weigh both.
How to Use the Calculator
- Choose a mode at the top: Medical / Test or General.
- For Medical mode, enter the prior P(A) as the disease prevalence, the sensitivity (true positive rate), and the specificity (true negative rate). All values are decimals from 0 to 1.
- For General mode, enter the prior P(A), the likelihood P(B|A), and the marginal P(B).
- Read the posterior probability P(A|B) shown as both a decimal and a percentage on the right.
- Review the step-by-step breakdown to see the formula plugged in with your numbers.
- Use the Copy Result button to save the output for your notes or report.
Example Calculations
Example 1: Sarah's screening test. The disease prevalence is 1% (P(A) = 0.01). The test sensitivity is 95% (P(B|A) = 0.95). The specificity is 90% (P(not B | not A) = 0.90). First compute P(not A) = 0.99 and the false positive rate P(B|not A) = 1 - 0.90 = 0.10. Then P(B) = 0.95 · 0.01 + 0.10 · 0.99 = 0.0095 + 0.099 = 0.1085. Finally P(A|B) = 0.0095 / 0.1085 = 0.0876, or about 8.76%. Despite a positive test from a 95% sensitive screen, Sarah has less than a 9% chance of having the disease. The false positive probability P(not A | B) is 91.24%, meaning most positive results in this population are wrong.
Example 2: A spam filter. Suppose 30% of incoming email is spam (P(A) = 0.30). A particular word appears in 80% of spam emails (P(B|A) = 0.80) and in 10% of legitimate emails. Using General mode, you need P(B), the total probability the word appears. P(B) = 0.80 · 0.30 + 0.10 · 0.70 = 0.24 + 0.07 = 0.31. The posterior P(A|B) = 0.24 / 0.31 = 0.7742, or 77.42%. Seeing that word raises the probability the email is spam from 30% to 77%. A filter would likely flag it, but would combine many such words before deciding.
Real-World Scenarios
Medical diagnosis. Physicians order tests and must interpret them in context. A positive result on a rare condition often warrants a confirmatory test rather than immediate treatment. Bayes' theorem quantifies why. When prevalence is low, the positive predictive value drops even for excellent tests. This is why screening programs target populations with elevated risk, not the general public, to keep the prior high enough that positives are meaningful.
Spam filtering. Naive Bayes classifiers power many early spam filters. Each word contributes a likelihood ratio, and the filter multiplies them together (under a conditional independence assumption) to update the prior probability that a message is spam. The math is the same theorem, applied thousands of times per email. Modern filters add more features, but the core idea is Bayesian updating.
Workplace drug testing. Companies use drug tests with stated accuracy above 99%. But if usage in the workforce is around 2%, a positive result still leaves real doubt. Plugging prevalence 0.02, sensitivity 0.99, and specificity 0.99 into the calculator gives P(A|B) around 66.7%. One in three positive results is a false positive. That nuance matters for fairness in hiring and disciplinary decisions.
Common Mistakes to Avoid
- Base rate neglect. Ignoring the prior P(A) is the classic error. People treat a positive test as near-certain proof without asking how common the condition is. When the base rate is low, false positives dominate.
- Confusing P(A|B) with P(B|A). The probability of having the disease given a positive test is not the same as the probability of a positive test given the disease. They are related by the formula, but they are different numbers. Swapping them produces the 95% intuition that fails Sarah.
- Ignoring false positives. Specificity matters as much as sensitivity. A test that catches every true case but also flags many healthy people will flood you with false alarms. Always check both rates.
- Assuming independence. The naive Bayes extension assumes evidence variables are conditionally independent given the hypothesis. When they are correlated (two symptoms caused by the same underlying factor), multiplying their likelihoods overcounts the evidence and inflates the posterior.
Limitations
This calculator handles two-hypothesis problems: A versus not A. It does not directly compare multiple competing hypotheses, which requires normalizing across several posteriors. The medical mode assumes a single test with one sensitivity and one specificity. Real diagnostic workflows combine several tests, and the independence assumption may not hold. The calculator also depends on the quality of your prior. A wrong or outdated prevalence figure produces a misleading posterior, no matter how precise the arithmetic. For multi-hypothesis Bayesian inference, you need a more general tool that sums over all possible causes of the evidence.
Authoritative Research and Resources
The Stanford Encyclopedia of Philosophy entry on Bayes' theorem gives a rigorous philosophical and mathematical treatment, including the connection to confirmation theory and decision making under uncertainty.
For a practical introduction with worked examples, Khan Academy's Bayes' theorem lessons walk through the formula with medical testing and probability tables. The videos are a good starting point if the algebra feels abstract.
The National Institutes of Health article on understanding sensitivity, specificity, and predictive values explains how these concepts apply in clinical practice and why positive predictive value depends on prevalence. It is a useful read for anyone working with diagnostic tests.