Bayes’ theorem calculator
Enter the test and how common the condition is, get the odds a result is right.
What is Bayes’ theorem?
P(A | B) = P(B | A) × P(A) ÷ P(B). It turns the chance of a result given a condition into the chance of the condition given the result.
How does it apply to a medical test?
With prevalence p, sensitivity (true-positive rate) and specificity (true-negative rate), the chance that a positive result is a true positive — the positive predictive value — is p × sensitivity ÷ [p × sensitivity + (1 − p) × (1 − specificity)].
Example
A test with 90% sensitivity and 90% specificity for a condition that 1% of people have: of 10,000 people, 90 of the 100 who have it test positive, and so do 990 of the 9,900 who do not. Only 90 of 1,080 positives — 8.3% — are true.
Why is the result so low?
When a condition is rare, false positives from the large healthy group outnumber the true positives. The same test is far more informative where the condition is common.
What is the negative predictive value?
The chance that a negative result is truly negative. In the example it is 8,910 ÷ 8,920 = 99.9%.
What is the difference between sensitivity and positive predictive value?
Sensitivity is the chance of a positive result given that the person has the condition. The positive predictive value is the chance of having the condition given a positive result. They answer opposite questions, and confusing the two is a common error. The second one also depends on how common the condition is.
Can I use it for something other than a medical test?
Yes. Anything with a base rate and a signal works the same way, such as a spam filter that catches 95% of spam but also flags some real mail, or a smoke alarm. Enter the base rate as the prevalence, the hit rate as the sensitivity and the correct-rejection rate as the specificity.
How the calculation works
The calculator turns the three percentages into counts for a large group. The people with the condition are the prevalence times the group size; the sensitivity says how many of them test positive. The people without the condition are the rest; the specificity says how many of those test negative, and the remainder are false positives. The positive predictive value (PPV) is true positives divided by all positives. The negative predictive value (NPV) is true negatives divided by all negatives. This is Bayes' theorem written with counts.
Worked example
Take a test with 95% sensitivity and 98% specificity. If 0.5% of people have the condition, a positive result is correct only 19.3% of the time. If 2% have it, the PPV is 49.2%. If 20% have it, as in a group already selected for symptoms, the same test has a PPV of 92.2%. The test itself did not change; only the prevalence did. The NPV stays high at 99.9% for the 2% case.
Common mistakes
- Ignoring the base rate. A positive result from an accurate test is still likely to be false when the condition is rare. This is the base rate fallacy.
- Mixing percent and fraction. The inputs here are percentages; the formula in the text uses fractions between 0 and 1.
- Assuming a second positive test is independent. Repeating the same test on the same person may repeat the same error, so the combined odds can be weaker than the formula suggests.
Sources and related calculators
Method: conditional probability and Bayes' theorem as covered in OpenStax Introductory Statistics, chapter 3 (Probability Topics). Related: probability calculator, binomial probability calculator and odds calculator.