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.
Report a calculation error
Help us improve. Describe what is wrong with the calculation.
Result
| Voce | Valore |
|---|
Show full details
Share result
Disclaimer: this calculation is for informational purposes only. For important decisions, consult a qualified professional.
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
Comments (0)
Login to leave a comment.
No comments yet. Be the first!