Bayes’ theorem tells you how to update a probability when new evidence arrives. You start with a prior — how likely a hypothesis is before looking — and combine it with the likelihoods and , how often the evidence shows up when the hypothesis is true and when it is false. The result is the posterior : how likely is now that you have seen .
The theorem is a short line of algebra, but its consequences surprise almost everyone. The classic case is screening for a rare condition: a test that catches 90 % of cases and wrongly flags only 9 % of healthy people sounds reliable, yet when only 1 % of those tested are ill, most positive results are false alarms. Ignoring the prior in this way is called base-rate neglect.
This calculator covers four situations: the standard form with the law of total probability; the short form when is already known; a medical test preset (prevalence, sensitivity, false-positive rate); and a plain conditional probability calculator from and . Each result comes with a natural-frequency table — the same numbers expressed as counts of people — which research shows makes Bayesian reasoning far easier to follow.
How to use this calculator
- Choose what you know in What do you know?
- Standard form: enter the prior , the likelihood and , all as percentages.
- P(B) known: enter , and the overall probability . The calculator checks that the three numbers are compatible.
- Medical test: enter the prevalence, the sensitivity and the false-positive rate (100 % minus the specificity).
- Conditional probability: enter the joint probability and .
- Read the posterior, its complement, the likelihood ratio and the frequency table out of the population you chose (10,000 by default).
The formula
Bayes’ theorem:
Law of total probability for the denominator:
Conditional probability (the definition Bayes’ theorem is built on):
Odds form: posterior odds = prior odds × likelihood ratio, with . In a diagnostic setting is the sensitivity, the false-positive rate, and the posterior is the positive predictive value.
Worked example
The mammography problem (Gigerenzer & Hoffrage, 1995; the calculator’s default). 1 % of women screened have breast cancer, the test detects 80 % of cancers and gives a positive result in 9.6 % of women without cancer.
- , about 7.8%
In natural frequencies: of 1,000 women, 10 have cancer and 8 of them test positive; of the 990 without cancer, about 95 also test positive. Only 8 of roughly 103 positives are real.
Medical test preset (prevalence 1 %, sensitivity 90 %, false-positive rate 9 %), out of 10,000 people: 100 are ill and 90 of them test positive; 891 of the 9,900 healthy people test positive too. A positive result therefore means a 9.2% chance of illness — about 1 in 11 — while a negative result is reassuring: 9,009 of the 9,009 + 10 negatives are healthy, a negative predictive value of 99.89%.
Conditional probability calculator
A conditional probability is the probability of restricted to the cases where happened. When you know the joint probability, the computation is a single division: if 12 % of customers buy a phone case and a phone, and 30 % buy a phone, then . Choose Conditional probability in the first field for this.
Bayes’ theorem is what you need when you know the conditional probability in the other direction — instead of . Confusing the two is a common and costly error (the "prosecutor’s fallacy"): the probability of a positive test given illness is not the probability of illness given a positive test. For combinations of independent or mutually exclusive events, use the probability calculator.
Why natural frequencies help
Gigerenzer and Hoffrage showed in 1995 that people solve Bayesian problems far more often when the data are given as counts ("8 of 10 women with cancer test positive") than as percentages. The table under the result does exactly that: it splits your chosen population into the four cells of a 2 × 2 table. The posterior is simply the top-left count divided by the total of its column.
For a full evaluation of a test from observed counts — sensitivity, specificity, predictive values and likelihood ratios with confidence intervals — use the sensitivity and specificity calculator.
Frequently asked questions
What is the difference between P(A|B) and P(B|A)?
P(B|A) is how often B occurs among cases of A; P(A|B) is how often A occurs among cases of B. They are equal only when P(A) = P(B). Bayes’ theorem converts one into the other using the prior.
Why is the posterior so low for a rare condition?
Because healthy people vastly outnumber sick ones. A small false-positive rate applied to a huge healthy group yields more false alarms than the true positives coming from the small sick group.
What is the prior probability?
Your probability for A before considering the evidence B: a prevalence, a base rate, or a previous posterior. Applying Bayes’ theorem repeatedly, each posterior becomes the next prior.
What is the likelihood ratio?
P(B|A) divided by P(B|not A). It says how much more likely the evidence is under A than under not A. Multiplying the prior odds by it gives the posterior odds.
Can the result be used for a medical decision?
Only as an illustration. Real pre-test probabilities depend on symptoms, age and history, and test performance varies between populations; interpretation belongs with a clinician.
Sources
- OpenStax, Introductory Statistics 2e, §3.2 Independent and Mutually Exclusive Events
- OpenStax, Introductory Statistics 2e, §3.3 Two Basic Rules of Probability
- Gigerenzer G, Hoffrage U (1995), How to improve Bayesian reasoning without instruction: frequency formats, Psychological Review 102(4):684–704
Last updated: