Bayes’ Theorem Calculator
Bayes’ theorem updates the probability of a hypothesis after seeing new evidence: P(A | B) = P(B | A) × P(A) ÷ P(B). With a 1% prior, a 99% true-positive rate and a 5% false-positive rate, a positive result gives only a 16.67% chance that the condition is present.
Last updated · By S. Dilshan · Runs in your browser, nothing is uploaded
Step-by-Step Solution
What Is Bayes’ Theorem?
Bayes’ theorem is a rule for revising a belief in light of evidence. You begin with a prior, how likely something was before you saw any evidence. You then observe a result, such as a positive medical test, and the theorem tells you the posterior, the updated probability that the hypothesis is true given that evidence.
Its most important lesson is that the accuracy of a test is not the same as the probability that a positive result is correct. When the condition is rare, even an accurate test produces many false alarms compared with true detections, so a positive result can still be more likely wrong than right. People routinely get this wrong, which is why the theorem matters so much in medicine, security and spam filtering.
The Terms
| Term | Symbol | Meaning | In the default example |
|---|---|---|---|
| Prior | P(A) | Probability before the evidence (the base rate) | 1% |
| Sensitivity (true-positive rate) | P(B | A) | Chance of a positive result if A is true | 99% |
| False-positive rate | P(B | not A) | Chance of a positive result if A is false | 5% |
| Posterior | P(A | B) | Probability A is true given a positive result | 16.67% |
Bayes’ Theorem Formula
P(A)is the prior probability of the hypothesis.P(B | A)is the probability of the evidence if the hypothesis is true.P(B | not A)is the probability of the evidence if the hypothesis is false.P(B)is the total probability of seeing the evidence, found by the law of total probability.
A handy shortcut is the likelihood ratio, P(B | A) ÷ P(B | not A). It says how many times more likely the evidence is when the hypothesis is true than when it is false. Here it is 99 ÷ 5 = 19.8. Multiplying the prior odds by the likelihood ratio gives the posterior odds. See the probability calculator for the basic rules behind these terms.
Worked Example: A Medical Screening Test
A condition affects 1% of people. A test detects it 99% of the time when present, but also gives a positive result 5% of the time when it is absent. You test positive. What is the chance you have the condition?
- True positives: 0.99 × 0.01 = 0.0099.
- False positives: 0.05 × 0.99 = 0.0495.
- Total chance of a positive result: P(B) = 0.0099 + 0.0495 = 0.0594.
- Posterior: 0.0099 ÷ 0.0594 = 0.1667, or 16.67%.
The Same Problem in Natural Frequencies
Imagine 10,000 people. About 100 have the condition and 99 of them test positive. Of the 9,900 without it, 5% or 495 also test positive. So 594 people test positive, but only 99 of them are truly ill. 99 ÷ 594 = 16.67%. Most positives are false alarms.
How the Prior Changes the Answer
| Prior P(A) | Posterior P(A | positive) |
|---|---|
| 1% | 16.67% |
| 10% | 68.75% |
| 50% | 95.19% |
The same test is far more convincing when the condition is already likely, for example in someone with strong symptoms.
How to Use This Bayes’ Theorem Calculator
- Enter the prior probability P(A) as a percentage.
- Enter the true-positive rate P(B | A).
- Enter the false-positive rate P(B | not A).
- Read the posterior P(A | B), the total probability of the evidence, P(A and B), P(not A | B) and the likelihood ratio.
Use the sensitivity and false-positive rate of the actual test, and the base rate for a group similar to the person being tested, not for the population at large.
Real-World Uses of Bayes’ Theorem
- Medical diagnosis: interpreting screening and diagnostic tests.
- Spam filtering: estimating the probability that a message is spam given the words it contains.
- Fraud and security: judging whether an alert reflects a real threat.
- Law and forensics: weighing DNA or other evidence against the base rate (and avoiding the “prosecutor’s fallacy”).
- Machine learning: Naive Bayes classifiers and Bayesian updating are used across modern AI.
What Are the Most Common Mistakes With the Bayes’ Theorem Calculator?
- Base-rate neglect. Ignoring the prior is the classic error. A 99% accurate test does not mean a 99% chance you are ill.
- Swapping the conditionals. P(A | B) is not the same as P(B | A).
- Using the wrong prior. The base rate should match the group being tested.
- Mixing up error rates. The false-positive rate is not 1 minus the true-positive rate.
- Treating inputs as exact. Real sensitivity and false-positive rates are estimates with their own uncertainty.
- One test only. After a second independent test, apply Bayes again with the new posterior as the prior.
Where Can You Verify These Formulas?
The definitions and formulas on this page follow standard references. Check them against these sources:
Built and maintained by S. Dilshan. Found a mistake? Email [email protected] with the page address.
Frequently Asked Questions
What is Bayes’ theorem in simple terms?
It is a rule for updating the probability of a hypothesis after seeing evidence, by combining the prior probability with how likely the evidence would be if the hypothesis were true or false.
Why is the posterior so low when the test is 99% accurate?
Because the condition is rare. Out of many healthy people, the small false-positive rate still produces more false alarms than the true positives from the few people who are ill.
What is the difference between sensitivity and the posterior?
Sensitivity is the probability of a positive test given the condition, P(B | A). The posterior is the probability of the condition given a positive test, P(A | B). They are different quantities.
What is a prior probability?
It is your starting belief about how likely something is before considering new evidence, often a known base rate such as the prevalence of a disease.
What is the likelihood ratio?
It is the true-positive rate divided by the false-positive rate. It measures the strength of the evidence: the larger it is, the more a positive result should raise your belief.
Can I apply Bayes’ theorem repeatedly?
Yes. Treat the posterior from the first piece of evidence as the prior for the next, as long as the pieces of evidence are independent given the hypothesis.