How to use the bayes theorem calculator
- Enter the prior P(A), the base rate of A before you look at the evidence B, as a percent from 0 to 100.
- Enter the sensitivity P(B | A), how often B shows up when A is true.
- Enter the other error rate either as the false-positive rate P(B | not A) or as the specificity, which is 100% minus the false-positive rate.
- Read P(A | B), the chance A is true once B has been observed, along with P(B) and a count table for 10,000 people.
Formula
P(B) = P(B | A) x P(A) + P(B | not A) x P(not A)
P(A | B) = P(B | A) x P(A) / P(B)
P(A | not B) = (1 - P(B | A)) x P(A) / (1 - P(B))
Bayes theorem reverses a conditional probability. You know how likely B is when A is true, and you want how likely A is once B has been seen. The denominator P(B) adds up every way B can happen, true cases and false alarms alike.
Worked example
A condition affects 1% of a group. A screening test is positive for 90% of people who have it and for 9% of people who do not. Out of 10,000 people, 100 have the condition and 90 of them test positive. Of the 9,900 without it, 891 test positive as well.
That makes 981 positives, so P(B) = 9.81%, and only 90 of those 981 are true cases: P(A | B) = 9.1743%. A positive result is far from certain even though the test finds 90% of cases, because the condition is rare and false alarms from the large healthy group outnumber the true cases. This is arithmetic on example rates, not medical advice.
Base rate neglect
People often read a sensitivity of 90% as meaning a positive result is 90% likely to be right. Those are different questions. Sensitivity answers how often B appears when A is true. P(A | B) answers how often A is true when B appears, and it depends heavily on the base rate. When A is rare, a small false-positive rate applied to a very large group can produce more false alarms than true hits.
The count table makes this visible. Compare the true positives in the first row with the false positives in the second row. Move the prior up and down and watch how the balance shifts.
Sensitivity, specificity and false positives
Sensitivity is the true positive rate. Specificity is the share of people without A who correctly show no B. The false-positive rate is 100% minus the specificity. Enter whichever your source reports, and the calculator converts it for you. The numbers must come from a source you trust, since this tool has no data of its own.
Edge cases
If P(B) is 0, which happens when both the sensitivity and the false-positive rate are 0, B can never occur and P(A | B) has no meaning, so the calculator says Undefined. A prior of 0% always gives 0% and a prior of 100% always gives 100%, because evidence cannot change a certainty.
Assumptions and limits
- Inputs are percentages from 0 to 100. Values outside that range are rejected, never clipped.
- The test or evidence is assumed to behave the same way for everyone, with fixed sensitivity and false-positive rates.
- Counts for 10,000 people are expected values and are shown with up to two decimals instead of being rounded to whole people.
- Repeated tests, dependence between tests and uncertainty in the rates are not modeled.
Frequently asked questions
What is the difference between P(A | B) and P(B | A)?
P(B | A) is the chance of seeing B when A is true. P(A | B) is the chance that A is true once B is seen. Mixing them up is the classic error that Bayes theorem corrects.
Why is my result so much lower than the sensitivity?
Because the prior is small. When A is rare, false alarms from the large group without A can outnumber true positives from the small group with A.
How do I use specificity instead of the false-positive rate?
Switch the selector to specificity. The false-positive rate is then taken as 100% minus the specificity you enter.
Can I chain two tests?
You can reuse the answer as the prior for a second test if the tests are independent given A. The result is an approximation if they are not, which this tool does not check.
Is this a medical calculator?
No. It does arithmetic on rates you supply, and a real decision about health needs a professional who knows the actual test and the person.