Bayes’ Theorem Calculator

Update probabilities with new evidence. Enter priors and likelihoods to compute the posterior probability step‑by‑step.

Interactive Bayes’ Theorem Calculator

Examples: “Disease”, “Spam email”, “Positive class”.

Examples: “Positive test”, “Contains word ‘free’”.

Prior

As decimal (0–1). 0.01 = 1% prevalence.

Sensitivity

Probability of evidence if A is true.

False positive

Probability of evidence if A is false.

What is Bayes’ theorem?

Bayes’ theorem is a rule for updating probabilities when you observe new evidence. It connects:

  • P(A): prior probability of a hypothesis A
  • P(B|A): probability of evidence B if A is true (likelihood)
  • P(B): overall probability of the evidence
  • P(A|B): updated probability of A after seeing B (posterior)

Basic form

\( P(A \mid B) = \dfrac{P(B \mid A)\,P(A)}{P(B)} \)

Two‑case form (A vs ¬A)

\[ P(A \mid B) = \dfrac{P(B \mid A)\,P(A)}{P(B \mid A)\,P(A) + P(B \mid \neg A)\,P(\neg A)} \]

How this calculator works

  1. You name the hypothesis A (e.g. “Disease”) and evidence B (e.g. “Positive test”).
  2. You enter:
    • P(A) – prior probability of A
    • P(B|A) – probability of B if A is true
    • P(B|¬A) – probability of B if A is false
  3. The calculator computes:
    • P(¬A) = 1 − P(A)
    • P(B) using the law of total probability
    • P(A|B) and P(¬A|B) using Bayes’ theorem
  4. It also builds a frequency table (out of N people/emails/etc.) so you can see counts instead of just abstract probabilities.

Worked example: medical test

Suppose:

  • Prevalence of a disease: \(P(A) = 0.01\) (1%)
  • Test sensitivity: \(P(B|A) = 0.95\) (95% chance of a positive if diseased)
  • False positive rate: \(P(B|¬A) = 0.05\) (5% chance of a positive if healthy)

1. Compute the prior complement

\(P(\neg A) = 1 - P(A) = 1 - 0.01 = 0.99\)

2. Compute the evidence probability

Using the law of total probability:

\[ P(B) = P(B|A)P(A) + P(B|\neg A)P(\neg A) = 0.95 \cdot 0.01 + 0.05 \cdot 0.99 = 0.0095 + 0.0495 = 0.059 \]

3. Apply Bayes’ theorem

\[ P(A|B) = \dfrac{0.95 \cdot 0.01}{0.059} = \dfrac{0.0095}{0.059} \approx 0.161 \]

So even with a “good” test, a positive result means about a 16.1% chance of actually having the disease, because the disease is rare.

Common interpretations

  • Prior \(P(A)\): what you believed before seeing the data.
  • Likelihood \(P(B|A)\): how compatible the data is with the hypothesis.
  • Posterior \(P(A|B)\): what you believe after combining prior and data.

Typical use cases

  • Medical testing: disease probability after a positive/negative test.
  • Spam filtering: probability an email is spam given certain words.
  • Machine learning: Naive Bayes classifiers, Bayesian inference.
  • Risk assessment: updating risk estimates after new signals.

FAQ

Do I have to enter decimals or percentages?

You can use either. Turn on “Enter values as percentages” to type 1, 5, 95 instead of 0.01, 0.05, 0.95. The calculator automatically converts them internally.

What if I only know sensitivity and specificity?

Sensitivity is \(P(B|A)\). Specificity is \(P(\neg B|\neg A)\), so the false positive rate is \(P(B|\neg A) = 1 - \text{specificity}\). Enter those along with the prevalence \(P(A)\).

Can Bayes’ theorem handle multiple pieces of evidence?

Yes. In many models you update sequentially: first compute \(P(A|B_1)\), then treat that as the new prior and update with \(B_2\), and so on. This calculator focuses on a single evidence variable B for clarity.