Math

Bayes Theorem Calculator

Calculate posterior probability using Bayes' theorem. Enter prior probability, likelihood, and false positive rate to see step-by-step results.

Quick Answer

Bayes' theorem calculates updated probability after new evidence: P(A|B) = P(B|A) × P(A) / P(B). It converts a prior belief into a posterior probability given observed data.

Enter Probabilities

All values must be between 0 and 1 (or 0% and 100%).

Probability of event A

Probability of B given A is true

Probability of B given A is false

Results

Posterior Probability P(A|B)
15.3846%
= 0.153846
Prior P(A)
1.00%
P(¬A)
99.00%
P(B) Total
5.8500%
Prior Odds
0.0101
Likelihood Ratio
18.0000
Posterior Odds
0.1818

Prior vs Posterior Comparison

Prior P(A)1.00%
Posterior P(A|B)15.38%

The evidence updated the probability by a factor of 15.4x

About This Tool

The Bayes Theorem Calculator helps you compute posterior probabilities using one of the most powerful concepts in probability theory. Developed by Reverend Thomas Bayes in the 18th century, Bayes' theorem provides a mathematical framework for updating beliefs in light of new evidence. This tool takes three inputs — prior probability, likelihood (true positive rate), and false positive rate — and calculates the posterior probability with a complete step-by-step breakdown.

Understanding Bayes' Theorem

Bayes' theorem is expressed as P(A|B) = P(B|A) × P(A) / P(B), where P(A|B) is the posterior probability of event A given that B has occurred, P(B|A) is the likelihood of observing B when A is true, P(A) is the prior probability of A, and P(B) is the total probability of observing B. The denominator P(B) acts as a normalizing constant and is computed using the law of total probability: P(B) = P(B|A) × P(A) + P(B|¬A) × P(¬A). This decomposition is what makes the formula so practical — it connects the probability we want (posterior) with quantities we can often estimate directly (prior and likelihoods).

The Base Rate Fallacy

One of the most important applications of Bayes' theorem is exposing the base rate fallacy. Consider a medical test that is 99% accurate (both sensitivity and specificity). If the disease affects 1 in 10,000 people, a positive test result might seem almost certain to mean you have the disease. But applying Bayes' theorem reveals the posterior probability is only about 1% — because the vast number of healthy people who falsely test positive overwhelms the small number of truly sick people. This counterintuitive result demonstrates why understanding prior probability (the base rate) is essential for correct reasoning under uncertainty. Courts, doctors, and policy makers frequently fall prey to ignoring base rates when interpreting evidence.

Applications in Data Science and Machine Learning

Bayesian reasoning underpins many modern technologies. Naive Bayes classifiers use the theorem for spam filtering, sentiment analysis, and document classification. Bayesian inference is the foundation of probabilistic programming languages like Stan and PyMC. In A/B testing, Bayesian methods provide intuitive probability statements about which variant is better, unlike frequentist p-values. Bayesian optimization guides hyperparameter tuning in machine learning. Even large language models implicitly perform Bayesian-like updates when processing context. The ability to formally update beliefs with evidence makes Bayesian methods indispensable in modern AI and statistics.

Medical Diagnosis and Screening

In medicine, Bayes' theorem is critical for interpreting diagnostic tests. Sensitivity (true positive rate) and specificity (true negative rate) describe a test's accuracy, but they do not directly answer the patient's real question: "Given a positive result, what is the probability I actually have this condition?" That answer depends on the prevalence of the condition (the prior), which varies by population. A test with 95% sensitivity and 95% specificity yields very different posterior probabilities depending on whether the disease prevalence is 1% or 10%. This tool lets you plug in those numbers and see the actual probability, helping patients and clinicians make more informed decisions.

Bayesian vs. Frequentist Approaches

Bayesian statistics differs from the frequentist approach in fundamental philosophy. Frequentists define probability as long-run frequency and avoid assigning probabilities to hypotheses. Bayesians treat probability as a degree of belief and directly compute the probability that a hypothesis is true. In practice, this means Bayesian analysis incorporates prior knowledge, produces probability distributions over parameters (not just point estimates), and naturally handles small sample sizes by leveraging informative priors. The posterior distribution is more intuitive than a confidence interval: instead of "if we repeated this experiment infinitely, 95% of intervals would contain the true value," you can say "there is a 95% probability the parameter lies in this range."

Practical Tips for Using This Calculator

Start by clearly defining events A and B. Event A is typically the hypothesis you care about (e.g., having a disease, an email being spam, a defendant being guilty). Event B is the observed evidence (e.g., a positive test, certain keywords, eyewitness testimony). Estimate P(A) from base rates or domain knowledge. Estimate P(B|A) from how often the evidence appears when the hypothesis is true. Estimate P(B|¬A) from how often the evidence appears when the hypothesis is false. If you are unsure about the prior, try several values to see how sensitive the posterior is to your assumptions — this sensitivity analysis is a hallmark of good Bayesian practice.

Frequently Asked Questions

What is Bayes' theorem in simple terms?
Bayes' theorem is a formula that tells you how to update the probability of a hypothesis when you get new evidence. If you start with a belief about how likely something is (the prior), and then observe relevant evidence, Bayes' theorem calculates your new, updated probability (the posterior). It essentially quantifies how evidence should change your mind.
What does P(B|not A) mean and why does it matter?
P(B|not A) is the probability of observing the evidence B when the hypothesis A is false. This is the false positive rate. It matters enormously because it determines how much of the evidence is 'noise.' A test with a high false positive rate produces many misleading results, dramatically reducing the posterior probability even when the test is positive.
Can I use this for medical test interpretation?
Yes. Set P(A) to the disease prevalence, P(B|A) to the test's sensitivity (true positive rate), and P(B|not A) to 1 minus the specificity (false positive rate). The result P(A|B) is the positive predictive value, telling you the probability you actually have the disease given a positive test. Always discuss results with a healthcare professional.
What happens when the prior probability is very low?
When the prior is very low (e.g., a rare disease), even highly accurate tests can have low posterior probabilities. This is the base rate fallacy in action. For example, with a 1 in 10,000 prior and a 99% accurate test, a positive result only yields about a 1% chance of actually having the condition. The calculator shows this clearly in the step-by-step breakdown.
How is Bayes' theorem used in machine learning?
Bayes' theorem is the foundation of Naive Bayes classifiers (used in spam filtering and text classification), Bayesian networks (probabilistic graphical models), Bayesian optimization (for hyperparameter tuning), and Bayesian neural networks. It provides a principled way to combine prior knowledge with observed data, making it essential for probabilistic reasoning in AI systems.
What is the likelihood ratio and why is it useful?
The likelihood ratio is P(B|A) divided by P(B|not A). It measures how much more likely the evidence is if the hypothesis is true versus false. A likelihood ratio of 10 means the evidence is 10 times more likely under the hypothesis than under the alternative. Multiplying prior odds by the likelihood ratio gives posterior odds, providing an intuitive way to update beliefs.

Was this tool helpful?