Home ↓
CalculatorsVerified

Math & Geometry

Bayes’ Theorem Calculator (Test Results and Base Rates)

Bayes’ theorem, named after the 18th-century minister and mathematician Thomas Bayes, tells us how to update a probability in the light of new evidence. It is central to medicine, spam filtering, forensic science, machine learning and everyday reasoning, and it explains one of the most common errors people make with tests: ignoring the base rate. Imagine a condition that affects 1 percent of people and a test that detects 90 percent of true cases but also gives a positive result for 9 percent of people who do not have the condition. Many people guess that a positive result means about a 90 percent chance of having the condition. Bayes’ theorem shows the real answer is only about 9 percent. Out of 10,000 people, 100 have the condition and 90 of them test positive, but of the 9,900 without it, about 891 also test positive, so only 90 of 981 positives are true. The theorem calculates this directly: the probability of the condition given a positive result equals the sensitivity times the prior, divided by the overall probability of a positive result, which includes both true and false positives. Enter the base rate, or prior probability, the sensitivity of the test and its false-positive rate, which is one minus the specificity. The calculator returns the positive predictive value, the negative predictive value, the share of tests that come back positive, the specificity, the likelihood ratio and a table of what happens to 10,000 people. For medical decisions, the prior should reflect the group being tested, and results should be discussed with a clinician, who will consider symptoms and further tests.

%
%
%

How to use this calculator

  1. Enter the base rate or prior probability, such as the prevalence of a condition.
  2. Enter the sensitivity: the chance of a positive result when the condition is present.
  3. Enter the false-positive rate: the chance of a positive result when it is absent.
  4. Read the probability that a positive result is correct.
  5. Use the 10,000-person table to see where the numbers come from.

Why the base rate matters

When a condition is rare, even a small false-positive rate applied to the large healthy group produces more false alarms than there are true cases. This is called the base-rate fallacy when it is overlooked.

Testing people who already have symptoms raises the prior and so raises the positive predictive value of the same test, which is why tests are more conclusive in clinics than in mass screening.

Repeated tests

The result of one test becomes the prior for the next. After a positive result at 9.2 percent, a second independent positive with the same test would raise the probability to about 50 percent.

In practice, follow-up tests often use a different, more specific method, which raises the probability faster and reduces correlated errors.

Formula & method

P(A | +) = P(+ | A) P(A) ÷ [P(+ | A) P(A) + P(+ | not A) P(not A)]Specificity = 1 − false-positive rateNegative predictive value = P(not A | −)With rare conditions, most positives can be false even for accurate tests

P(A | +) = P(+ | A)·P(A) ÷ [P(+ | A)·P(A) + P(+ | ¬A)·P(¬A)]. NPV = P(¬A | −) = (1 − FP)(1 − P(A)) ÷ [(1 − FP)(1 − P(A)) + (1 − Se)P(A)].

Worked example

A condition with 1% prevalence, 90% sensitivity and 9% false positives

  1. True positives = 0.90 × 0.01 = 0.009.
  2. False positives = 0.09 × 0.99 = 0.0891.
  3. P(condition | positive) = 0.009 ÷ (0.009 + 0.0891) ≈ 9.2%.

Answer: Only about 9% of people with a positive result actually have the condition.

Frequently asked questions

Why is the result so low for a rare condition?

When few people have the condition, the small share of false positives among the many people without it can outnumber the true positives, so a positive result is less conclusive than the test’s accuracy suggests.

Where do I get the numbers?

Sensitivity and specificity come from studies of the test; the prior is the prevalence in the group being tested, which can differ greatly between screening and people with symptoms.

What is specificity?

The probability that the test is negative when the condition is absent, equal to one minus the false-positive rate.

What is a likelihood ratio?

Sensitivity divided by the false-positive rate; it tells how much a positive result multiplies the odds of the condition.

Is this only for medical tests?

No, the same reasoning applies to spam filters, fraud alerts, security screening and any test with errors.

Who was Thomas Bayes?

An English minister and mathematician whose essay on probability was published in 1763, after his death.