Bayes' Theorem Calculator
Enter how common the condition is, how often the test catches it, and how often it fires without it. The calculator gives the chance a positive result is real.
P(A|B): chance a positive is real (PPV)
7.76%
P(B): chance of a positive result
10.3%
P(A|not B): chance a negative is wrong
0.223%
P(not A|not B): negative predictive value
99.78%
How it works
Bayes' theorem turns a probability around. A test's sensitivity tells you how likely a positive result is given the condition, P(B|A); what you want to know after a positive result is the reverse, how likely the condition is given the positive, P(A|B). The two differ, often enormously, because they depend on how common the condition is to begin with.
The easiest way to see it is to imagine 10,000 people, which is what the table does. The prior says how many of them have the condition; the sensitivity says how many of those test positive; the false-positive rate says how many of the rest also test positive. The posterior is simply the true positives divided by all the positives. When the condition is rare, the false positives from the large healthy group can outnumber the true positives from the small affected group, and most positive results are wrong.
The same arithmetic applies to anything with a base rate and an imperfect signal: spam filters, security alerts, quality inspection, or a witness who is right 80% of the time.
Formula
P(B) = P(B|A) P(A) + P(B|¬A) (1 − P(A)) P(A|B) = P(B|A) P(A) / P(B) P(A|¬B) = (1 − P(B|A)) P(A) / (1 − P(B)) P(¬A|¬B) = (1 − P(B|¬A)) (1 − P(A)) / (1 − P(B))
Example
A condition affects 1% of people. A screening test detects 80% of cases (sensitivity) and gives a false positive in 9.6% of people without it. In 10,000 people, 100 have the condition and 80 of them test positive; 9,900 do not, and 950 of them test positive anyway. A positive result is real in 80 of 1,030 cases, so P(A|B) = 7.76%, and P(B) = 10.30%.
A negative result is far more reassuring: only 20 of the 8,970 negatives are missed cases, so P(A|not B) = 0.223% and the negative predictive value is 99.78%.
Assumptions and limitations
- The prior, sensitivity and false-positive rate are the values you entered; the result is only as good as they are. Published test figures are typical values from study populations and may not apply to yours.
- The prior must be strictly between 0% and 100%; at 0% or 100% there is nothing to update.
- The table shows expected counts in 10,000 people, which may be fractional; they are rounded for display only.
- One test, one condition: repeated tests are only independent if their errors are, which is often not the case. A calculation is informational and is not medical advice; discuss any real test result with a clinician.
Frequently asked questions
Why is the chance a positive is real so low when the test is 80% accurate?
Because the condition is rare. Among 10,000 people only 100 have it, so at most 100 true positives are possible, while a 9.6% false-positive rate across the 9,900 without it produces about 950 false alarms. Most positives come from the big healthy group. As the prior rises, the posterior rises with it.
What is the difference between sensitivity and positive predictive value?
Sensitivity, P(B|A), is a property of the test: how often it flags people who have the condition. Positive predictive value, P(A|B), depends on the test and the population: how often a flagged person actually has it. The calculator converts the first into the second using the prior.
More in Math & Geometry calculators.