Bayes' Theorem Calculator

Apply Bayes' theorem to update probabilities with new evidence — compute posterior probability, likelihood ratios, and confusion matrices for medical tests.

About the Bayes' Theorem Calculator

Bayes' theorem calculator updates your belief about a hypothesis after observing new evidence. Given a prior probability (base rate), the likelihood of the evidence under the hypothesis, and the likelihood under the alternative, it computes the exact posterior probability.

This tool is indispensable for medical test interpretation, spam filtering, forensic analysis, and any situation where you need to reason about uncertainty. A common application is determining whether a positive medical test truly indicates disease — the answer depends critically on the base rate (prevalence), which most people underestimate.

The calculator supports two input modes: a medical-test mode using sensitivity and specificity, and a general mode using raw conditional probabilities. It outputs the posterior probability, likelihood ratios, a confusion matrix scaled to 10,000 individuals, and a sensitivity analysis showing how the posterior changes across different priors. Check the example with realistic values before reporting. Use the steps shown to verify rounding and units. Cross-check this output using a known reference case.

Why Use This Bayes' Theorem Calculator?

Bayes' theorem is arguably the most important formula in applied probability. Doctors, data scientists, engineers, and lawyers all need to update beliefs based on evidence, yet human intuition is notoriously poor at this task — especially when base rates are low.

This calculator makes Bayesian reasoning accessible and visual, helping you avoid the base rate fallacy and make better decisions under uncertainty.

How to Use This Calculator

  1. Choose medical test mode (sensitivity/specificity) or general mode (raw conditional probabilities).
  2. Enter the prior probability P(A) — the base rate or prevalence before observing evidence.
  3. In medical mode, enter sensitivity (true positive rate) and specificity (true negative rate).
  4. In general mode, enter P(B|A) and P(B|¬A) directly.
  5. Read the posterior probability P(A|B) from the output — this is the updated probability after positive evidence.
  6. Review the confusion matrix to understand true/false positives in a population of 10,000.
  7. Check the sensitivity analysis table to see how different base rates change the result.

Formula

P(A|B) = [P(B|A) × P(A)] / [P(B|A) × P(A) + P(B|¬A) × P(¬A)]. Positive Likelihood Ratio = Sensitivity / (1 − Specificity). Posterior Odds = Prior Odds × LR+.

Example Calculation

Result: P(Disease | Positive Test) ≈ 0.0876 (8.76%)

With 1% prevalence, 95% sensitivity, and 90% specificity: P(+) = 0.95×0.01 + 0.10×0.99 = 0.1085. Posterior = (0.95×0.01)/0.1085 ≈ 8.76%. Even with a positive test, there's only about a 9% chance of actually having the disease.

Tips & Best Practices

The Base Rate Fallacy

The most famous illustration of Bayes' theorem is the medical screening paradox. A disease affecting 1% of the population is screened with a 95% sensitive, 90% specific test. Most people guess a positive result means ~95% chance of disease. The actual answer is under 9%. This counterintuitive result occurs because false positives from 99% of healthy individuals vastly outnumber true positives from 1% of sick individuals.

Bayesian vs. Frequentist Thinking

Frequentist statistics evaluates the probability of data given a fixed hypothesis. Bayesian statistics flips this — it evaluates the probability of a hypothesis given observed data. Bayes' theorem is the mathematical bridge between these perspectives.

Serial Testing and Prior Updating

In clinical practice, a second test isn't independent — the patient's prior has been updated by the first test. Use the posterior from the first positive test as the prior for the second test. Two consecutive positives with independent tests dramatically increase the posterior probability.

Frequently Asked Questions

What is Bayes' theorem in plain English?

It's a formula that tells you how to update your belief after seeing new evidence. If you think there's a 1% chance of something, and you get a positive signal, Bayes' theorem tells you the new (higher) probability.

Why is the posterior so low even with a 95% accurate test?

Because the base rate matters enormously. With 1% prevalence and 90% specificity, the 10% false positive rate applied to 99% of healthy people generates far more false positives than the 95% sensitivity finds true positives.

What's the difference between sensitivity and specificity?

Sensitivity is the probability a test is positive when disease is present (TP rate). Specificity is the probability a test is negative when disease is absent (TN rate). Both need to be high, but specificity matters more with rare conditions.

Can I use this for non-medical scenarios?

Absolutely. Use general mode and supply any P(B|A) and P(B|¬A). Common uses include spam detection, fraud analysis, DNA evidence evaluation, and machine learning classification.

What is a likelihood ratio?

The positive likelihood ratio (LR+) is sensitivity divided by the false positive rate. It tells you how much a positive result increases the odds of the hypothesis. LR+ > 10 is strong evidence; LR+ < 2 is weak.

How do I interpret the confusion matrix?

It shows how 10,000 people would be classified. Green cells are correct (true positives and true negatives). Red cells are errors (false positives and false negatives). The ratio of TP to (TP+FP) is the PPV.

Related Pages