Statistics

Bayes' Theorem

Last updated: March 2026 · Intermediate
Before you start

You should be comfortable with:

Real-world applications
πŸ’Š
Nursing

Medication dosages, IV drip rates, vital monitoring

Bayes’ theorem lets you reverse a conditional probability. If you know P(B∣A)P(B \mid A) β€” the probability of B given A β€” Bayes’ theorem tells you P(A∣B)P(A \mid B) β€” the probability of A given B. This is essential in medicine, quality control, and any situation where you need to update your beliefs based on new evidence.

The Formula

P(A∣B)=P(B∣A)β‹…P(A)P(B)P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)}

The denominator P(B)P(B) is the total probability of B, which can be expanded using the law of total probability:

P(A∣B)=P(B∣A)β‹…P(A)P(B∣A)β‹…P(A)+P(B∣Aβ€²)β‹…P(Aβ€²)P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B \mid A) \cdot P(A) + P(B \mid A') \cdot P(A')}

where Aβ€²A' denotes β€œnot A” (the complement of A).

Terminology:

  • P(A)P(A) = prior probability β€” what you believed before seeing the evidence
  • P(A∣B)P(A \mid B) = posterior probability β€” your updated belief after seeing the evidence
  • P(B∣A)P(B \mid A) = likelihood β€” how likely the evidence is if A is true
  • P(B)P(B) = total probability of the evidence β€” how likely the evidence is overall

Intuition: Why Bayes’ Theorem Matters

Imagine a medical test that is 99% accurate. You test positive. Are you 99% likely to have the disease?

Almost certainly not. The answer depends on how common the disease is. If the disease is rare (say, 1 in 1,000 people), then most positive test results will actually be false positives from the large number of healthy people being tested. Bayes’ theorem gives you the mathematical framework to calculate the actual probability.

This counterintuitive result is so important β€” and so commonly misunderstood β€” that it has its own name: the base rate fallacy. People naturally focus on the test’s accuracy and ignore the base rate (prevalence) of the condition.

Step-by-Step: The Medical Test Problem

Example 1: Disease Screening

A disease affects 1% of the population. A screening test has the following characteristics:

  • Sensitivity: P(+∣D)=0.95P(+ \mid D) = 0.95 β€” the test correctly detects 95% of people who have the disease
  • False positive rate: P(+∣Dβ€²)=0.10P(+ \mid D') = 0.10 β€” the test incorrectly flags 10% of healthy people (equivalently, specificity is 90%)

A randomly selected person tests positive. What is the probability they actually have the disease?

Define the events:

  • DD = has the disease, P(D)=0.01P(D) = 0.01
  • Dβ€²D' = does not have the disease, P(Dβ€²)=0.99P(D') = 0.99
  • ++ = tests positive

Apply Bayes’ theorem:

P(D∣+)=P(+∣D)β‹…P(D)P(+∣D)β‹…P(D)+P(+∣Dβ€²)β‹…P(Dβ€²)P(D \mid +) = \frac{P(+ \mid D) \cdot P(D)}{P(+ \mid D) \cdot P(D) + P(+ \mid D') \cdot P(D')}

Step 1: Calculate the numerator.

P(+∣D)β‹…P(D)=0.95Γ—0.01=0.0095P(+ \mid D) \cdot P(D) = 0.95 \times 0.01 = 0.0095

Step 2: Calculate each term in the denominator.

P(+∣D)β‹…P(D)=0.95Γ—0.01=0.0095P(+ \mid D) \cdot P(D) = 0.95 \times 0.01 = 0.0095

P(+∣Dβ€²)β‹…P(Dβ€²)=0.10Γ—0.99=0.099P(+ \mid D') \cdot P(D') = 0.10 \times 0.99 = 0.099

Step 3: Add to get the total probability of a positive test.

P(+)=0.0095+0.099=0.1085P(+) = 0.0095 + 0.099 = 0.1085

Step 4: Divide.

P(D∣+)=0.00950.1085β‰ˆ0.0876P(D \mid +) = \frac{0.0095}{0.1085} \approx 0.0876

Answer: Despite a positive test, there is only about an 8.8% chance the person actually has the disease.

Why so low? Out of every 1,000 people tested, about 10 have the disease and 990 do not. The test catches 10Γ—0.95=9.510 \times 0.95 = 9.5 true positives, but it also produces 990Γ—0.10=99990 \times 0.10 = 99 false positives. So roughly 9.5 out of 108.5 total positive results are genuine β€” that is about 8.8%.

The Tree Diagram Approach

A tree diagram provides an alternative visual method for Bayes’ theorem problems. Draw the prior probabilities as the first set of branches, then the test results as the second set, and multiply along each path to get joint probabilities.

Tree Diagram: Disease Screening with Bayes’ Theorem

P(D)=0.01P(D’)=0.99DD’0.950.050.100.90+ (true positive)- (false negative)+ (false positive)- (true negative)0.00950.00050.09900.8910

Reading the tree: Multiply along each complete path from root to leaf.

PathCalculationJoint Probability
Disease and Positive0.01Γ—0.950.01 \times 0.950.00950.0095
Disease and Negative0.01Γ—0.050.01 \times 0.050.00050.0005
No Disease and Positive0.99Γ—0.100.99 \times 0.100.09900.0990
No Disease and Negative0.99Γ—0.900.99 \times 0.900.89100.8910

Verification: All joint probabilities must sum to 1.

0.0095+0.0005+0.0990+0.8910=1.0000βœ“0.0095 + 0.0005 + 0.0990 + 0.8910 = 1.0000 \checkmark

To find P(D∣+)P(D \mid +), take the β€œDisease and Positive” path and divide by the total probability of a positive result:

P(D∣+)=0.00950.0095+0.0990=0.00950.1085β‰ˆ0.0876P(D \mid +) = \frac{0.0095}{0.0095 + 0.0990} = \frac{0.0095}{0.1085} \approx 0.0876

This confirms the formula-based result: about 8.8%.

How Prevalence Affects Results

The same test produces dramatically different results depending on how common the disease is. The table below uses the same test (sensitivity 95%, specificity 90%) with varying prevalence rates.

Prevalence P(D)P(D)P(+∣D)β‹…P(D)P(+ \mid D) \cdot P(D)P(+∣Dβ€²)β‹…P(Dβ€²)P(+ \mid D') \cdot P(D')P(+)P(+)P(D∣+)P(D \mid +)
0.1%0.95Γ—0.001=0.000950.95 \times 0.001 = 0.000950.10Γ—0.999=0.09990.10 \times 0.999 = 0.09990.100850.10085β‰ˆ0.9%\approx 0.9\%
1%0.95Γ—0.01=0.00950.95 \times 0.01 = 0.00950.10Γ—0.99=0.0990.10 \times 0.99 = 0.0990.10850.1085β‰ˆ8.8%\approx 8.8\%
5%0.95Γ—0.05=0.04750.95 \times 0.05 = 0.04750.10Γ—0.95=0.0950.10 \times 0.95 = 0.0950.14250.1425β‰ˆ33.3%\approx 33.3\%
10%0.95Γ—0.10=0.0950.95 \times 0.10 = 0.0950.10Γ—0.90=0.090.10 \times 0.90 = 0.090.1850.185β‰ˆ51.4%\approx 51.4\%
50%0.95Γ—0.50=0.4750.95 \times 0.50 = 0.4750.10Γ—0.50=0.050.10 \times 0.50 = 0.050.5250.525β‰ˆ90.5%\approx 90.5\%

Key insight: When a disease is very rare (0.1%), a positive result means less than a 1% chance of actually having the disease. When the disease is common (50%), the same positive result means a 90.5% chance. The test itself did not change β€” the prevalence (base rate) did.

This is why:

  • Screening tests work best on high-risk populations (higher prevalence)
  • A positive screening result in a general population is often followed by a more specific confirmatory test
  • Doctors target screenings to groups where the condition is more common

Bayes’ Theorem with More Than Two Categories

Bayes’ theorem extends naturally when there are more than two possible causes. If events A1,A2,…,AnA_1, A_2, \ldots, A_n are mutually exclusive and exhaustive:

P(Ak∣B)=P(B∣Ak)β‹…P(Ak)βˆ‘i=1nP(B∣Ai)β‹…P(Ai)P(A_k \mid B) = \frac{P(B \mid A_k) \cdot P(A_k)}{\sum_{i=1}^{n} P(B \mid A_i) \cdot P(A_i)}

Example 2: Three Factories

Three factories supply a retailer. Factory X makes 50% of products with a 3% defect rate, Factory Y makes 30% with a 4% defect rate, and Factory Z makes 20% with a 6% defect rate. A product is found to be defective. What is the probability it came from Factory Z?

Step 1: Calculate the numerator for Factory Z.

P(def∣Z)β‹…P(Z)=0.06Γ—0.20=0.012P(\text{def} \mid Z) \cdot P(Z) = 0.06 \times 0.20 = 0.012

Step 2: Calculate the total probability of a defect.

P(def)=(0.03Γ—0.50)+(0.04Γ—0.30)+(0.06Γ—0.20)P(\text{def}) = (0.03 \times 0.50) + (0.04 \times 0.30) + (0.06 \times 0.20)

=0.015+0.012+0.012=0.039= 0.015 + 0.012 + 0.012 = 0.039

Step 3: Apply Bayes’ theorem.

P(Z∣def)=0.0120.039β‰ˆ0.308P(Z \mid \text{def}) = \frac{0.012}{0.039} \approx 0.308

Answer: About 30.8% of defective products come from Factory Z. Despite making only 20% of products, Factory Z produces a disproportionate share of defects due to its higher defect rate.

Real-World Application: Nursing β€” Interpreting a Positive Drug Screen

Workplace drug testing is a practical Bayes’ theorem scenario that nurses and occupational health professionals encounter regularly.

A company requires drug screening for all employees. Here are the numbers:

  • Drug use prevalence among employees: 4% (P(D)=0.04P(D) = 0.04)
  • Test sensitivity: 97% β€” the test detects 97% of actual users (P(+∣D)=0.97P(+ \mid D) = 0.97)
  • Test specificity: 95% β€” the test correctly clears 95% of non-users (P(βˆ’βˆ£Dβ€²)=0.95P(- \mid D') = 0.95, so P(+∣Dβ€²)=0.05P(+ \mid D') = 0.05)

An employee tests positive. What is the probability they actually use drugs?

P(D∣+)=P(+∣D)β‹…P(D)P(+∣D)β‹…P(D)+P(+∣Dβ€²)β‹…P(Dβ€²)P(D \mid +) = \frac{P(+ \mid D) \cdot P(D)}{P(+ \mid D) \cdot P(D) + P(+ \mid D') \cdot P(D')}

=0.97Γ—0.040.97Γ—0.04+0.05Γ—0.96= \frac{0.97 \times 0.04}{0.97 \times 0.04 + 0.05 \times 0.96}

=0.03880.0388+0.048=0.03880.0868β‰ˆ0.447= \frac{0.0388}{0.0388 + 0.048} = \frac{0.0388}{0.0868} \approx 0.447

Answer: Only about 44.7% of positive results are true positives. More than half of positive test results in this scenario are false alarms.

This is why occupational health protocols require confirmatory testing (usually a more specific test like GC-MS) before any employment action is taken. A nurse or HR professional who understands Bayes’ theorem can explain to an anxious employee why a single positive screening result is not conclusive, and why the follow-up test matters.

Practice Problems

Test your understanding with these problems. Click to reveal each answer.

Problem 1: A rare disease affects 0.5% of the population. A test has 98% sensitivity and 96% specificity. If a person tests positive, what is the probability they have the disease?

P(D)=0.005P(D) = 0.005, P(Dβ€²)=0.995P(D') = 0.995, P(+∣D)=0.98P(+ \mid D) = 0.98, P(+∣Dβ€²)=0.04P(+ \mid D') = 0.04

P(D∣+)=0.98Γ—0.0050.98Γ—0.005+0.04Γ—0.995=0.00490.0049+0.0398=0.00490.0447β‰ˆ0.110P(D \mid +) = \frac{0.98 \times 0.005}{0.98 \times 0.005 + 0.04 \times 0.995} = \frac{0.0049}{0.0049 + 0.0398} = \frac{0.0049}{0.0447} \approx 0.110

Answer: About 11.0% β€” even with a highly accurate test, the rarity of the disease means most positive results are false positives.

Problem 2: Using the disease from Example 1 (prevalence 1%, sensitivity 95%, specificity 90%), a person tests negative. What is the probability they actually have the disease? That is, find P(Dβˆ£βˆ’)P(D \mid -).

P(βˆ’βˆ£D)=1βˆ’0.95=0.05P(- \mid D) = 1 - 0.95 = 0.05, P(βˆ’βˆ£Dβ€²)=0.90P(- \mid D') = 0.90

P(Dβˆ£βˆ’)=0.05Γ—0.010.05Γ—0.01+0.90Γ—0.99=0.00050.0005+0.891=0.00050.8915β‰ˆ0.00056P(D \mid -) = \frac{0.05 \times 0.01}{0.05 \times 0.01 + 0.90 \times 0.99} = \frac{0.0005}{0.0005 + 0.891} = \frac{0.0005}{0.8915} \approx 0.00056

Answer: About 0.056% β€” a negative result makes it extremely unlikely the person has the disease. This is reassuring.

Problem 3: A factory gets 40% of its parts from Supplier A (2% defect rate) and 60% from Supplier B (5% defect rate). A defective part is found. What is the probability it came from Supplier B?

P(B∣def)=0.05Γ—0.600.02Γ—0.40+0.05Γ—0.60=0.0300.008+0.030=0.0300.038β‰ˆ0.789P(B \mid \text{def}) = \frac{0.05 \times 0.60}{0.02 \times 0.40 + 0.05 \times 0.60} = \frac{0.030}{0.008 + 0.030} = \frac{0.030}{0.038} \approx 0.789

Answer: About 78.9% of defective parts come from Supplier B.

Problem 4: An email filter correctly identifies 99% of spam (sensitivity) and correctly passes 97% of legitimate email (specificity). If 20% of all incoming email is spam, what is the probability that a flagged email is actually spam?

P(S)=0.20P(S) = 0.20, P(Sβ€²)=0.80P(S') = 0.80, P(flag∣S)=0.99P(\text{flag} \mid S) = 0.99, P(flag∣Sβ€²)=0.03P(\text{flag} \mid S') = 0.03

P(S∣flag)=0.99Γ—0.200.99Γ—0.20+0.03Γ—0.80=0.1980.198+0.024=0.1980.222β‰ˆ0.892P(S \mid \text{flag}) = \frac{0.99 \times 0.20}{0.99 \times 0.20 + 0.03 \times 0.80} = \frac{0.198}{0.198 + 0.024} = \frac{0.198}{0.222} \approx 0.892

Answer: About 89.2% of flagged emails are actually spam. The relatively high prevalence of spam (20%) makes the filter more reliable than a rare-disease medical test.

Problem 5: A disease has 10% prevalence. The test has 90% sensitivity and 85% specificity. Find P(D∣+)P(D \mid +) and explain whether this test is reliable enough for screening.

P(D)=0.10P(D) = 0.10, P(Dβ€²)=0.90P(D') = 0.90, P(+∣D)=0.90P(+ \mid D) = 0.90, P(+∣Dβ€²)=0.15P(+ \mid D') = 0.15

P(D∣+)=0.90Γ—0.100.90Γ—0.10+0.15Γ—0.90=0.090.09+0.135=0.090.225=0.40P(D \mid +) = \frac{0.90 \times 0.10}{0.90 \times 0.10 + 0.15 \times 0.90} = \frac{0.09}{0.09 + 0.135} = \frac{0.09}{0.225} = 0.40

Answer: P(D∣+)=0.40P(D \mid +) = 0.40, or 40%. Only 40% of positive results are true positives. Whether this is β€œreliable enough” depends on context: if the follow-up test is low-cost and low-risk, a 40% hit rate may be acceptable for initial screening. If the follow-up is invasive or expensive, a more specific test might be preferable.

Key Takeaways

  • Bayes’ theorem reverses conditional probabilities: knowing P(B∣A)P(B \mid A), find P(A∣B)P(A \mid B).
  • The formula is: P(A∣B)=P(B∣A)β‹…P(A)P(B)P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)}.
  • Base rate (prevalence) matters enormously. A positive result from a highly accurate test can still be mostly wrong if the condition is rare.
  • The tree diagram approach provides a visual alternative: multiply along branches to get joint probabilities, then divide to get the posterior.
  • In medical contexts, sensitivity tells you P(+∣disease)P(+ \mid \text{disease}), but patients and clinicians need P(disease∣+)P(\text{disease} \mid +) β€” Bayes’ theorem bridges this gap.
  • Confirmatory testing exists because initial screening results have limited predictive value, especially in low-prevalence populations.
  • Bayes’ theorem extends to multiple categories by expanding the denominator to sum over all possible causes.

Return to Statistics for more topics in this section.

Last updated: March 29, 2026