... LIVE
🧠 Select Calculation Mode
📌 General Mode: P(A|B) = P(B|A) × P(A) / [P(B|A) × P(A) + P(B|A′) × P(A′)]
Enter probabilities as decimals (0 to 1) or percentages (0 to 100%).
0–1
Your initial belief that A is true. Enter as decimal 0–1.
Enter a value between 0 and 1.
0–1
Probability of observing B given A is true.
Enter a value between 0 and 1.
0–1
Probability of observing B when A is false.
Enter a value between 0 and 1.
📌 Medical Test Mode: Enter disease prevalence and test accuracy to get PPV, NPV, and likelihood ratios via Bayes theorem. Includes confusion matrix for 10,000 people screened.
0–1
Disease prevalence in the tested population (0.01 = 1%)
Enter prevalence between 0.0001 and 0.9999.
0–1
P(positive test | disease present)
Enter sensitivity between 0.0001 and 0.9999.
0–1
P(negative test | disease absent)
Enter specificity between 0.0001 and 0.9999.
Posterior Probability
⚠️ Disclaimer: Results assume all input probabilities are accurate. Medical interpretation requires clinical judgment. Disease prevalence in your specific tested population (not general population) should be used. Consult a qualified medical professional for diagnostic decisions.

Sources & Methodology

Bayes theorem formula verified against OpenStax Statistics and Stanford Encyclopedia of Philosophy. Medical test formulas (PPV, NPV, LR+, LR−) verified against NIST and standard biostatistics references. Confirmed manually: 1% prevalence, 95% sensitivity, 90% specificity → PPV = 8.76%.
📘
OpenStax Introductory Statistics — Chapter 3.5: Bayes’ Formula
Open-access Rice University textbook. Primary source for the Bayes theorem formula P(A|B) = P(B|A) × P(A) / P(B) and the total probability expansion P(B) = P(B|A)×P(A) + P(B|A′)×P(A′).
📊
BMJ Clinical Evidence — Sensitivity and Specificity (Altman & Bland, 1994)
Standard medical reference for sensitivity, specificity, PPV, and NPV formulas. Source for positive likelihood ratio = sensitivity / (1−specificity) and negative likelihood ratio = (1−sensitivity) / specificity.
All formulas verified:
P(A|B) = P(B|A) × P(A) / [P(B|A)×P(A) + P(B|A′)×P(A′)] PPV = Sensitivity × Prevalence / [Sensitivity×Prev + (1−Specificity)×(1−Prev)] LR+ = Sensitivity / (1−Specificity)   |   LR− = (1−Sensitivity) / Specificity Manual check: prev=0.01, sens=0.95, spec=0.90 → PPV=8.76% ✓

Bayes Theorem — Posterior Probability, Medical Tests & Complete Guide

Bayes theorem is the mathematical rule for updating probability beliefs when new evidence arrives. Named after Reverend Thomas Bayes (1701–1761) and formalized by Pierre-Simon Laplace in 1812, it answers: "Given that I observed B, how probable is A?" The answer is the posterior probability P(A|B), calculated from the prior P(A), likelihood P(B|A), and false positive rate P(B|A′).

The Bayes Theorem Formula — Full Derivation

Bayes theorem is derived directly from the definition of conditional probability. The key insight is that P(A and B) = P(B|A) × P(A) = P(A|B) × P(B). Rearranging gives:

P(A|B) = P(B|A) × P(A) / P(B) Where: P(B) = P(B|A) × P(A) + P(B|A′) × P(A′)
Complete worked example:
A disease has prevalence P(A) = 1% = 0.01. A test has sensitivity P(B|A) = 95% = 0.95 and false positive rate P(B|A′) = 10% = 0.10.
P(B) = 0.95 × 0.01 + 0.10 × 0.99 = 0.0095 + 0.0990 = 0.1085
P(A|B) = (0.95 × 0.01) / 0.1085 = 0.0095 / 0.1085 = 0.0876 = 8.76%
Despite 95% sensitivity, a positive test result means only 8.76% chance of disease. This is the base rate fallacy — low prevalence means false positives dominate.

PPV and NPV — Medical Test Interpretation via Bayes Theorem

In medical diagnostics, Bayes theorem directly determines the clinical usefulness of a test. The four outcomes of a diagnostic test relate directly to Bayesian quantities:

MeasureFormula (Bayes)Interpretation
PPV (Positive Predictive Value)P(Disease | Positive Test)Probability you have disease given positive result
NPV (Negative Predictive Value)P(No Disease | Negative Test)Probability you are disease-free given negative result
LR+ (Positive Likelihood Ratio)Sensitivity / (1−Specificity)How much a positive result increases disease odds
LR− (Negative Likelihood Ratio)(1−Sensitivity) / SpecificityHow much a negative result decreases disease odds
SensitivityP(Positive | Disease)Fixed test property — independent of prevalence
SpecificityP(Negative | No Disease)Fixed test property — independent of prevalence

Why Disease Prevalence Changes Everything — The Base Rate Fallacy

The most counterintuitive result from Bayes theorem is how dramatically disease prevalence affects PPV. Sensitivity and specificity are fixed test properties, but PPV is not. As prevalence drops, false positives dominate and PPV falls sharply:

PPV = (Sensitivity × Prevalence) / [(Sensitivity × Prevalence) + ((1−Specificity) × (1−Prevalence))]
Same test (95% sensitivity, 99% specificity) at different prevalences:
Prevalence 50% → PPV = 98.99%    (high prevalence: reliable positive result)
Prevalence 10% → PPV = 91.35%    (moderate prevalence: still useful)
Prevalence 1%  → PPV = 48.97%    (low prevalence: half of positives are false!)
Prevalence 0.1% → PPV = 8.70%     (very rare disease: 9 in 10 positives are false!)
Key lesson: Specificity must be extremely high to maintain useful PPV with rare diseases.
💡 Likelihood ratios are prevalence-independent. LR+ = sensitivity / (1−specificity). LR+ > 10 is strong evidence for disease. LR+ 2–5 is weak to moderate. LR− < 0.1 strongly rules out disease. LR− 0.1–0.2 is moderately helpful. Unlike PPV/NPV, likelihood ratios stay constant across different populations with different prevalences, making them ideal for comparing tests and for Bayesian updating.
Frequently Asked Questions
Bayes theorem calculates P(A|B) — the probability of A given that B occurred — using P(A) (prior probability), P(B|A) (likelihood), and P(B|A′) (false positive rate). Formula: P(A|B) = P(B|A)×P(A) / [P(B|A)×P(A) + P(B|A′)×P(A′)]. It is the mathematical foundation of Bayesian inference, used in medicine, spam filtering, machine learning, legal reasoning, and scientific research.
The posterior probability P(A|B) is your updated belief about A after observing evidence B. It combines the prior P(A) (initial belief) with the likelihood P(B|A) (how probable B is if A is true) and the false positive rate P(B|A′) (how probable B is if A is false). The posterior is always between 0 and 1 and quantifies how much the evidence should shift your belief.
Sensitivity is P(positive test | disease present) — a fixed test property. PPV is P(disease | positive test) — what you actually want to know clinically. PPV depends on both the test’s sensitivity/specificity AND disease prevalence. A test with 95% sensitivity can have PPV of only 8.76% if disease prevalence is 1% and false positive rate is 10%. Sensitivity and PPV are often confused, leading to misinterpretation of test results.
When disease is rare, even a small false positive rate generates many false positives because the healthy population is large. Example: 1% prevalence, 99% sensitivity, 99% specificity, 10,000 people. Diseased = 100. True positives = 99. Healthy = 9,900. False positives = 99 (1% of 9,900). PPV = 99/(99+99) = 50%. Half of all positives are false. This is the base rate fallacy — the base rate (prevalence) matters enormously.
LR+ = sensitivity / (1−specificity). LR− = (1−sensitivity) / specificity. LR+ measures how much a positive result increases disease odds. LR+ > 10: strong evidence for disease. LR+ 2–5: weak to moderate. LR− < 0.1: strongly rules out disease. LR− 0.2–0.5: moderate. Unlike PPV/NPV, likelihood ratios are independent of prevalence, making them useful for comparing tests across different populations.
The base rate fallacy is the cognitive error of ignoring prevalence when interpreting test results. People intuitively think that a test with 95% accuracy means a positive result gives 95% probability of disease. Bayes theorem shows this is only true when prevalence is 50%. With 1% prevalence and 5% false positive rate, PPV is about 16%. Studies show most physicians, and even statisticians, make this error without Bayesian reasoning.
Bayesian updating revises probability as evidence accumulates. Start with prior P(A). After observing evidence B1, calculate posterior P(A|B1) using Bayes theorem. This posterior becomes the new prior. After observing B2, apply Bayes again to get P(A|B1 and B2). Example: initially P(disease) = 0.01. After positive test: PPV = 0.0876 (new prior). After second independent positive test: apply Bayes again with prior = 0.0876, same sensitivity and specificity.
The prior P(A) is your initial probability estimate before observing evidence. In medical testing, use disease prevalence in the specific patient population being tested, not overall population prevalence. A 60-year-old smoker has higher lung cancer prevalence than the general population. Choosing the right prior (reference class problem) is one of the most important and difficult aspects of Bayesian inference. Using too generic a prior can make results misleading.
The confusion matrix shows all four outcomes for a given population: TP (true positives), FP (false positives), FN (false negatives), TN (true negatives). In 10,000 people: TP = prevalence × n × sensitivity. FN = prevalence × n × (1−sensitivity). FP = (1−prevalence) × n × (1−specificity). TN = (1−prevalence) × n × specificity. PPV = TP/(TP+FP). NPV = TN/(TN+FN). The matrix makes abstract probabilities concrete and visible.
Naive Bayes spam filter works exactly like the medical test example. Prior P(spam) = base rate of spam. P(word|spam) = probability the word appears in spam emails = likelihood. P(word|not spam) = false positive rate. Posterior = P(spam|word) computed for each word. For multiple words, multiply likelihoods and apply Bayes iteratively (assumes word independence, hence “naive”). Despite the independence assumption being wrong, Naive Bayes works remarkably well and is the basis for many real-world spam filters.
Frequentist probability treats probability as the long-run frequency of outcomes in repeated experiments. Bayesian probability treats probability as a degree of belief that can be updated with evidence. Bayes theorem is the mathematical rule for Bayesian updating. Frequentist approaches avoid subjective priors and focus on p-values and confidence intervals. Bayesian approaches incorporate prior knowledge and produce posterior distributions. In practice, medical diagnosis, machine learning, and scientific inference increasingly use Bayesian methods because they naturally handle evidence updating.
NPV (Negative Predictive Value) = P(no disease | negative test). It answers: “If the test is negative, how confident are we there is no disease?” NPV is most useful in high-sensitivity tests used to rule out disease. A highly sensitive test with few false negatives gives very high NPV, meaning a negative result almost certainly rules out disease. The mnemonic: “Sensitive tests rule OUT disease when negative (SnNOut).” NPV also depends on prevalence: lower prevalence → higher NPV.
Related Statistics Calculators
Popular Calculators
🧮

Missing a Statistics Calculator?

Can’t find the statistical tool you need? Tell us — we build new calculators every week.