Bayes Theorem Calculator

Updating a Belief With New Evidence

Bayes' theorem is the formal rule for revising a probability once new evidence arrives. It starts with a prior belief about how likely something is, folds in how well the evidence fits that scenario versus the alternative, and produces a posterior probability — the updated belief given what was just observed. It is the mathematical backbone of medical diagnostic testing, spam filtering, and any situation where "positive test result" doesn't automatically mean "condition present."

The Formula

P(A|B) = [P(B|A) × P(A)] / P(B)
where P(B) = P(B|A) × P(A) + P(B|not A) × P(not A)

Worked Example: A Medical Screening Test

Consider a disease with 1% prevalence in a population (prior P(A) = 0.01), a test with 95% sensitivity (P(B|A) = 0.95), and a 5% false-positive rate (P(B|not A) = 0.05):

Bayesian update for a positive test result
QuantityValue
Prior probability, P(A)1%
P(B) — overall probability of a positive test5.90%
Posterior probability, P(A|B)16.10%

Computed directly from the calculator's formula.

Even with a 95%-sensitive test, a positive result only pushes the probability of actually having the (rare) condition up to about 16% — a result that consistently surprises people first encountering it, and the reason low-prevalence screening programs pair a positive result with a confirmatory second test.

Where This Calculation Matters

  • Medical diagnostics — interpreting a screening test result correctly requires combining test accuracy with how common the condition is in the population being tested, not just the test's sensitivity and specificity in isolation.
  • Spam and fraud filtering — Bayesian classifiers update the probability that a message is spam (or a transaction is fraudulent) based on features observed in the message or transaction.
  • Forensic and legal reasoning — evaluating how much a piece of evidence should shift the probability of a hypothesis, avoiding the common "prosecutor's fallacy" of treating P(evidence|innocent) as if it were P(innocent|evidence).

How to Use This Calculator

  1. Enter the prior probability P(A) — the base rate of the event or condition before any new evidence.
  2. Enter P(B|A) — the probability of the evidence given the event is true (e.g., test sensitivity).
  3. Enter P(B|not A) — the probability of the evidence given the event is false (e.g., false-positive rate).
  4. Select Calculate to get the posterior probability P(A|B).

Related Calculations

For basic probability rules underlying this formula, see the Probability Calculator. For repeated independent trials rather than a single evidence update, use the Probability of Success Calculator.

Principles of Bayesian Probability and Conditional Statistical Inference

A Bayes' theorem calculator computes conditional probabilities, updating the prior probability of an event or hypothesis (A) based on newly observed evidence or test data (B). In mathematical statistics, machine learning classifiers, medical diagnostic screening, and legal forensics, Bayes' Theorem provides the rigorous mathematical framework for dynamic evidential reasoning.

The Fundamental Bayes' Theorem Formulation

P(A | B) = [ P(B | A) × P(A) ] / P(B)
  • P(A | B) — Posterior Probability: The updated conditional probability that hypothesis A is true given that event B has occurred.
  • P(A) — Prior Probability: The initial baseline probability of hypothesis A before observing evidence B.
  • P(B | A) — Likelihood: The probability of observing evidence B given that hypothesis A is true.
  • P(B) — Marginal Probability of Evidence (Normalizing Constant): Total probability of observing evidence B across all possible states.

The Law of Total Probability Expansion

P(B) = [ P(B | A) × P(A) ] + [ P(B | ¬A) × P(¬A) ]
P(A | B) = [ P(B | A) × P(A) ] / [ ( P(B | A) × P(A) ) + ( P(B | ¬A) × P(¬A) ) ]

Medical Diagnostics: Positive Predictive Value (PPV)

Diagnostic Parameter Statistical Notation Clinical Diagnostic Definition
Disease Prevalence (Prior) P(D) Baseline disease frequency in the population
Test Sensitivity (True Positive Rate) P(+ | D) Probability test is positive when patient has disease
Test Specificity (True Negative Rate) P(- | ¬D) Probability test is negative when patient is disease-free
False Positive Rate P(+ | ¬D) = 1 - Specificity Probability healthy patient tests positive
Positive Predictive Value (PPV) P(D | +) Actual probability patient has disease given a positive test

Step-by-Step Worked Calculation Example

Example: The Classic Medical Diagnostic Screening Paradox

Problem: A rare medical disease has a population prevalence P(D) = 0.001 (0.1% or 1 in 1,000 people). A laboratory diagnostic test boasts 99.0% Sensitivity (P(+|D) = 0.99) and 95.0% Specificity (P(-|¬D) = 0.95 &implies; False Positive Rate P(+|¬D) = 0.05). If a randomly screened asymptomatic patient tests positive (+), calculate the exact probability that the patient actually has the disease (PPV = P(D|+)).

Step 1: Identify all probability terms:

P(D) = 0.001  |  P(¬D) = 1.0 - 0.001 = 0.999

P(+ | D) = 0.99  |  P(+ | ¬D) = 0.05

Step 2: Calculate Marginal Probability of a Positive Test (P(+)):

P(+) = ( 0.99 × 0.001 ) + ( 0.05 × 0.999 ) = 0.00099 + 0.04995 = 0.05094 (5.094% of tests are positive)

Step 3: Calculate Posterior Probability (P(D | +)):

P(D | +) = 0.00099 / 0.05094 = 0.01943 ≈ 1.94% Positive Predictive Value!

Conclusion: Despite a 99% accurate test, a positive result carries only a 1.94% chance of actual disease due to the low base prevalence (98% of positive tests are false positives!).

Bayes Factors and Evidence Strength Scales

In Bayesian hypothesis testing, the ratio of likelihoods evaluating hypothesis H1 against null hypothesis H0 is the Bayes Factor (BF10):

Posterior Odds = Prior Odds × Bayes Factor (BF10)
  • BF10 = 1 to 3: Anecdotal / Barely worth mentioning evidence.
  • BF10 = 3 to 10: Moderate positive evidence for H1.
  • BF10 = 10 to 30: Strong evidence.
  • BF10 > 100: Decisive / Overwhelming statistical evidence.

Naive Bayes Classifiers in Machine Learning

In natural language processing (NLP) and email spam filtering, Naive Bayes Classifiers apply Bayes' Rule assuming conditional independence across all feature words: P(Spam | Words) ∝ P(Spam) × ∏ P(Wordi | Spam), calculating the posterior probability that an incoming email is spam in milliseconds.

Markov Chain Monte Carlo (MCMC) Sampling in Bayesian Inference

In modern multi-parameter Bayesian data science, calculating high-dimensional normalizing integrals P(B) analytically is mathematically intractable. Data scientists utilize Markov Chain Monte Carlo (MCMC) Algorithms (such as the Metropolis-Hastings and Gibbs Sampler) to draw thousands of representative samples from the posterior probability distribution P(A|B), enabling robust parameter estimation in clinical drug trials and econometric modeling.

Conjugate Prior Distributions

In algebraic Bayesian analysis, pairing a Beta prior with a Binomial likelihood yields an exact Beta posterior distribution, allowing direct closed-form Bayesian updating without numerical integration.