Bayes' Theorem Calculator
Calculate conditional probabilities using Bayes' theorem.
Initial probability of event A (0-100%)
Probability of B given A is true
Probability of B given A is false
Enter prior probability and likelihoods to calculate posterior
Use Bayes' theorem when you need to update a probability based on new evidence. If you know how likely the evidence is given your hypothesis, and you have a prior belief about that hypothesis, Bayes' theorem tells you what to believe after seeing the evidence.
What Is Bayes' Theorem?
Bayes' theorem relates conditional probabilities:
Where:
- = Posterior: Probability of A given B (what we want)
- = Likelihood: Probability of B given A
- = Prior: Initial probability of A
- = Evidence: Total probability of B
The Components Explained
Prior Probability P(A)
Your belief about A before seeing any evidence. This might come from:
- Previous studies
- Expert opinion
- Base rates in the population
Example: Before any testing, 1% of the population has a disease. P(Disease) = 0.01.
Likelihood P(B|A)
How likely is the evidence if A is true?
Example: If you have the disease, the test is positive 95% of the time. P(Positive|Disease) = 0.95.
Evidence P(B)
The total probability of observing B, calculated as:
Example: Total probability of a positive test = (true positives) + (false positives).
Posterior Probability P(A|B)
Your updated belief about A after seeing evidence B.
Example: Given a positive test result, what's the probability of actually having the disease?
Classic Example: Medical Testing
Scenario:
- Disease prevalence: 1% (prior)
- Test sensitivity: 95% (true positive rate)
- Test specificity: 90% (true negative rate, so false positive rate = 10%)
Question: You test positive. What's the probability you have the disease?
Calculation:
First, calculate P(Positive):
Then:
Result: Only 8.8% chance of having the disease despite a positive test!
This counterintuitive result occurs because the disease is rare. Most positive tests are false positives from the 99% without the disease.
The Odds Form
An alternative formulation using odds:
Or: Posterior Odds = Likelihood Ratio × Prior Odds
The likelihood ratio tells you how much the evidence should shift your beliefs.
Applications
Medical Diagnosis
Updating disease probability after test results:
- Positive test increases probability
- Negative test decreases probability
- Multiple tests can be chained
Spam Filtering
Naive Bayes classifiers:
- Prior: Base rate of spam emails
- Likelihood: Probability of words given spam/not-spam
- Posterior: Is this email spam?
Legal Reasoning
Evaluating evidence:
- Prior: Base rate of guilt
- Likelihood: How likely is this evidence if guilty vs. innocent?
- Posterior: Updated probability of guilt
Machine Learning
Bayesian inference for:
- Parameter estimation
- Model comparison
- Uncertainty quantification
Sequential Updates
Bayes' theorem can be applied repeatedly. Today's posterior becomes tomorrow's prior:
Each piece of evidence updates your beliefs.
Example: First test positive (8.8% probability), then second test positive → probability increases further.
Base Rate Neglect
A common error is ignoring the prior probability. In the medical example, people often guess ~95% probability after a positive test, focusing on test accuracy while ignoring disease rarity.
Key insight: When the condition is rare, even accurate tests produce many false positives.
Sensitivity vs. Specificity Trade-off
| Test Property | Definition | Bayes Impact |
|---|---|---|
| Sensitivity | P(Positive|Disease) | Affects true positive contribution |
| Specificity | P(Negative|No Disease) | Affects false positive rate |
For rare conditions, high specificity is crucial to avoid false positive flooding.
Historical Context
Thomas Bayes (1701-1761) was an English minister and mathematician. His theorem was published posthumously in 1763, edited by Richard Price.
Pierre-Simon Laplace independently developed and extended Bayesian methods, applying them to astronomical and demographic problems.
The "Bayesian vs. Frequentist" debate in statistics continues today, though modern practice often combines both perspectives.
Common Pitfalls
Assuming Independence
When combining multiple pieces of evidence, they must be conditionally independent given the hypothesis. Correlated evidence provides less information than expected.
Choosing Priors
Controversial in scientific applications:
- Informative priors incorporate existing knowledge
- Uninformative priors try to be "objective"
- Sensitivity analysis tests different priors
Ignoring Base Rates
Always ask: "How common is this in the population?" before interpreting test results.
Related Calculations
- Conditional Probability — P(A|B) basics
- Sensitivity and Specificity — Diagnostic test properties
- Odds Ratio Calculator — Odds-based measures
- Bayesian Proportion Estimator — Prior-to-posterior updating
Summary
Bayes' theorem updates probabilities based on new evidence. The posterior probability depends on the prior (base rate), the likelihood (how probable is the evidence if the hypothesis is true), and the total probability of the evidence. When conditions are rare, even accurate tests produce many false positives—a crucial insight for medical diagnosis, legal reasoning, and any situation where evidence must be weighed against base rates.