Bayes' Theorem Calculator

Bayes' Theorem Calculator

Update a probability in the light of new evidence. Enter how likely something was to begin with and how reliable the evidence is, and see how likely it is now, with the working shown as counts out of 10,000.

P(A | B) = P(B | A) × P(A) ÷ P(B)

How likely A is before the evidence, such as how common a disease is.

How often the evidence shows up when A is true (a test's sensitivity).

How often it shows up anyway when A is false (the false-positive rate).

As a decimal (0.25), a percentage (25%) or a fraction (1/4).

Enter the prior and the two evidence probabilities

What is Bayes' Theorem?

Bayes' theorem tells you how to update a probability when new evidence arrives. You start with a prior (how likely something was beforehand), weigh how much more often the evidence turns up when it's true than when it isn't, and end with a posterior.

Its most famous use is reading medical test results. A test that catches 95% of cases sounds decisive, but if the disease is rare, the healthy people who test positive by mistake can far outnumber the sick people who test positive correctly.

The same reasoning runs spam filters, forensic evidence, A/B tests and machine learning. It's the formal way to turn P(evidence | cause), which is what experiments measure, into P(cause | evidence), which is what you actually want to know.

Bayes' Theorem Formula

Formula as given in Blitzstein and Hwang; natural-frequency presentation after Gigerenzer and Hoffrage (1995). See Sources.

1. How often the evidence appears at all

P(B) = P(B | A) × P(A) + P(B | not A) × (1 − P(A))

True positives plus false positives: the law of total probability.

2. The share of those that are genuine

P(A | B) = P(B | A) × P(A) ÷ P(B)

3. The same thing in odds form

posterior odds = prior odds × likelihood ratio
likelihood ratio = P(B | A) ÷ P(B | not A)

The likelihood ratio measures how strong the evidence is on its own, separately from how likely A was to start with.

Worked Example: A Positive Screening Test

Given:
A disease affects 1% of people. The test catches 95% of cases and wrongly flags 5% of healthy people. You test positive.
Step 1:
Picture 10,000 people:
100 have it → 95 test positive · 9,900 don't → 495 test positive
Step 2:
All positives:
95 + 495 = 590 → P(B) = 0.059
Step 3:
Share that are genuine:
95 ÷ 590 = 0.161
Result:
P(disease | positive) = 16.1%

Most positives are false alarms, because the 5% error rate is applied to a far bigger healthy group. The positive still matters: it raised the chance sixteenfold, from 1% to 16%, which is why a second, independent test usually follows.

How the Prior Changes the Answer

The same 95% / 5% test from the worked example, used on groups where the disease is more or less common.

Posterior probability for different priors
PriorAfter a positiveAfter a negative
0.1%1.87%0.005%
1%16.1%0.053%
10%67.86%0.581%
50%95%5%

Common Bayes' Theorem Mistakes

  • Ignoring the base rate. Reading a 95% accurate test as a 95% chance of disease. The prior is what turns sensitivity into a real-world answer.
  • Entering specificity as the false-positive rate. A test with 95% specificity has a 5% false-positive rate. P(B | not A) = 1 − specificity.
  • Using a population prior for a high-risk person. Someone with symptoms or a family history has a higher prior than the general population, and the posterior rises with it.
  • Treating repeated tests as independent when they aren't. Chaining posteriors only works if the second test's errors are unrelated to the first's. Re-running the same test on the same sample rarely qualifies.

Bayes' Theorem FAQs

What is a prior?

Your best estimate of the probability before seeing the evidence. For a screening test it’s usually the prevalence in the group being tested.

What do I do after a second test?

Use the first posterior as the new prior. A second positive from an independent 95% / 5% test takes the example from 16.1% to about 78.5%.

What is the likelihood ratio?

P(B | A) ÷ P(B | not A): how many times more often the evidence appears when A is true. A ratio of 19 multiplies the prior odds by 19.

Why is a negative result so reassuring here?

When the prior is low and the test is sensitive, a negative leaves very little chance of disease: about 0.05% in the example. Negatives and positives carry different weight.

Is Bayes’ theorem only for medical tests?

No. Any time you want P(cause | evidence) from P(evidence | cause) it applies: spam filtering, fraud detection, forensic evidence, fault diagnosis.

Can I enter percentages?

Yes. 1%, 0.01 and 1/100 all mean the same.

What if P(B | not A) is zero?

Then the evidence never appears without A, so seeing it makes A certain. The likelihood ratio shows as infinite.

What’s the difference between Bayesian and frequentist statistics?

Both accept Bayes’ theorem. Bayesian statistics goes further and uses it to update beliefs about unknown quantities themselves, such as a drug’s true effect.

Sources

Related Tools