Course contentsShow
← Data Science
Lesson 109 of 2,1453. Probability FoundationsFree lesson

Medical Diagnostic Testing

Apply Bayes' Theorem to calculate the probability of disease given a positive test result.

Medical Diagnostic Testing

What you'll learn: How to use Bayes' Theorem to calculate the true probability of having a disease when your test comes back positive.

The Real-World Problem

Imagine you test positive for a rare disease. Should you panic? Surprisingly, even with an accurate test, the probability you actually have the disease might be quite low. This is where Bayes' Theorem becomes a life-saving tool.

Understanding the Setup

Medical tests aren't perfect. They have:

  • Sensitivity: probability the test is positive given you have the disease (true positive rate)
  • Specificity: probability the test is negative given you don't have the disease (true negative rate)
  • Prevalence: the base rate of the disease in the population

What you really want to know is: P(Disease | Positive Test) — the probability you have the disease given a positive result.

Applying Bayes' Theorem

Using Bayes' Theorem from our previous lessons:

P(Disease | Positive) = [P(Positive | Disease) × P(Disease)] / P(Positive)

Where P(Positive) comes from the Law of Total Probability:

  • P(Positive) = P(Positive | Disease) × P(Disease) + P(Positive | No Disease) × P(No Disease)

Example

Suppose:

  • Disease prevalence: 1% (0.01)
  • Test sensitivity: 90% (0.90)
  • Test specificity: 95% (0.95)

Even with a positive test:

  • P(Disease | Positive) = (0.90 × 0.01) / [(0.90 × 0.01) + (0.05 × 0.99)]
  • = 0.009 / (0.009 + 0.0495) = 0.009 / 0.0585 ≈ 15.4%

Despite 90% accuracy, only about 15% of positive results indicate actual disease — because the disease is rare!

Key Takeaway: Bayes' Theorem reveals that a positive medical test result doesn't guarantee disease; you must account for base rates (prevalence) and test accuracy to calculate the true probability.