Bayes Theorem Calculator: P(A|B), PPV, likelihood ratio

Compute posterior probability P(A|B), diagnostic test PPV/NPV and likelihood ratios. Four Bayes theorem modes with worked examples from medicine and statistics.

Calculation parameters
Was this calculator useful?

Bayes' theorem: the fundamental formula

Bayes' theorem, published posthumously in 1763 by Thomas Bayes and formalized by Pierre-Simon Laplace, is the central formula for updating a probability in light of new evidence: P(A|B) = P(B|A) · P(A) / P(B). P(A) is the prior probability, P(B|A) the likelihood of evidence B given A, P(B) the marginal probability of the evidence, and P(A|B) the posterior probability. It is the foundation of Bayesian inference, evidence-based medicine, spam filters and many machine learning algorithms.

Formula with total probability

When P(B) is not directly known we use the law of total probability: P(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A). Substituting: P(A|B) = [P(B|A)·P(A)] / [P(B|A)·P(A) + P(B|¬A)·(1−P(A))]. This is the most used operational form, since it only requires prior, true positive and false positive rates.

Diagnostic testing: PPV and NPV

In medical diagnostics the formula becomes: PPV = Sens·Prev / [Sens·Prev + (1−Spec)·(1−Prev)], where PPV (Positive Predictive Value) is the probability a patient is sick given a positive test, Sens is sensitivity (true positives / diseased), Spec specificity (true negatives / healthy), Prev the prevalence. Analogously NPV = Spec·(1−Prev) / [Spec·(1−Prev) + (1−Sens)·Prev]. Error rate (1−PPV) grows quickly for rare diseases.

Example: base rate fallacy

Test with Sens=99%, Spec=99% for a disease with 0.1% prevalence (1 in 1000). PPV = 0.99·0.001/[0.99·0.001 + 0.01·0.999] = 0.00099/0.01098 ≈ 9%. A positive test has only 9% probability of indicating real disease, 91% are false positives. This is the base rate fallacy: ignoring prevalence drastically overestimates post-test risk. Demonstrated by Kahneman and Tversky, Gigerenzer showed 70-80% of physicians err without training in natural frequencies.

Odds form: Bayes factor

The odds form is more elegant: odds(A|B) = odds(A) · LR, where odds(A) = P(A)/[1−P(A)], LR (likelihood ratio) = P(B|A)/P(B|¬A). For diagnostic tests LR+ = Sens/(1−Spec) and LR− = (1−Sens)/Spec. LR+ > 10 or LR− < 0.1 indicate a very informative test; LR ≈ 1 means useless. Example: a test with Sens=95%, Spec=90% → LR+ = 9.5, LR− = 0.056.

Sequential updating

Independent evidence combines multiplicatively: odds_final = odds_initial · LR₁ · LR₂ · ... · LRₙ. Useful in complex diagnostics, forensic DNA analysis, symptom and test combination. Requires conditional independence; otherwise correlation must be modeled.

Modern applications

Naïve Bayes in spam filtering and text classification (>99% accuracy on email); Bayesian networks in diagnostics (IBM, Microsoft, Apache); Bayesian inference in genetics (kinship, linkage); DNA forensics (likelihood ratio in identification); machine learning (Bayesian neural networks, Gaussian processes); econometrics and finance (parameter updating in VaR models); astronomy (transiting exoplanet detection). Amazon, Netflix and daily credit risk pricing use Bayes with thousands of features.

How to use

Select mode: Basic (P(A), P(B|A), P(B) → P(A|B)), Total (P(A), P(B|A), P(B|¬A) → P(A|B)), Diagnostic (Sens, Spec, Prev → PPV, NPV, LR), Odds (prior, LR → posterior). All values as decimals (0.05 = 5%).

The base-rate fallacy, in numbers

A complete example: a disease affects 1% of the population; the test has 99% sensitivity and 95% specificity. Among 10,000 people tested there are 100 diseased, of whom 99 test positive, and 9,900 healthy, of whom 495 test falsely positive. Whoever receives a positive result therefore has only 99/(99+495) ≈ 17% probability of actually being ill — not the 99% intuition suggests. This is why mass screening always includes a confirmatory test, and why the calculator shows the PPV next to sensitivity and specificity.

From theology to machine learning

Thomas Bayes was an English Presbyterian minister; his essay was published posthumously in 1763 by his friend Richard Price, and it was Pierre-Simon Laplace who gave the theorem its modern form. After a twentieth century dominated by frequentist statistics, the Bayesian approach returned to centre stage with modern computing: naive Bayes classifiers for spam, Bayesian networks for diagnostics, Bayesian searches at sea (USS Scorpion 1968, Air France 447 in 2011) and probabilistic machine learning.

Updated July 2026

Frequently Asked Questions

What does Bayes' theorem state?

P(A|B) = P(B|A)·P(A)/P(B): the probability of A given B is obtained by "inverting" the conditional probability with the prior P(A). Published posthumously in 1763 by the Reverend Thomas Bayes, it is the mathematical rule for updating beliefs in the light of new evidence, from the lab to the courtroom.

Why can an accurate test produce many false positives?

If the condition is rare, the few true positives drown among the false ones. With 1% prevalence, 99% sensitivity and 95% specificity: out of 10,000 people there are 99 true positives against about 495 false ones, so PPV ≈ 17%. This is the base-rate fallacy, the most common error in interpreting diagnostic tests.

What are PPV and NPV?

The positive predictive value (PPV) is the probability of truly having the condition given a positive test; the negative predictive value (NPV), of not having it given a negative test. Unlike sensitivity and specificity, they depend on prevalence: the same test has very different PPVs in mass screening and on a hospital ward.

What is the likelihood ratio?

LR+ = sensitivity/(1−specificity) tells how many times a positive result is more likely in the diseased than in the healthy. Post-test odds are obtained by multiplying pre-test odds by the LR. An LR ≥ 10 shifts the diagnosis substantially; between 0.5 and 2 the test is nearly useless. The calculator provides both LR+ and LR−.

What is the difference between probability and odds?

Odds are p/(1−p): a 75% probability equals odds of 3:1. The odds form of Bayes' theorem is the handiest for quick calculations: multiply the prior odds by the likelihood ratio and convert back with p = odds/(1+odds), exactly as the calculator's odds mode does.

How do I choose the prior?

In medicine the prior is the prevalence of the condition in the population the patient belongs to, taken from epidemiological data or registries. In general settings one uses historical frequencies or estimates to be updated. Today's posterior becomes tomorrow's prior as new evidence arrives.

Where is Bayes used beyond medicine?

In spam filters, in searches for wrecks at sea (the 2011 recovery of Air France flight 447 followed a Bayesian probability map), in recommender systems, in machine learning with the naive Bayes classifier, and in courtrooms to weigh forensic evidence such as DNA profiles.

Comments (0)

No comments yet. Be the first!