Statistics For Programmers - Bayes Theorem

Bayes Theorem is a fundamental concept in statistics and probability theory. It provides a way to update the probability of a hypothesis based on new evidence or information. It's particularly useful in situations where have some knowledge about the efficacy of a test or the prevalence of a condition in a population.

Bayes Theorem is expressed as follows:

\[ P(A|B) = \frac{P(B|A) \times P(A)}{P(B)} \]


  • \( P(A|B) \) is the probability of event A given event B
  • \( P(B|A) \) is the probability of event B given event A
  • \( P(A) \) is the prior probability of event A
  • \( P(B) \) is the prior probability of event B

Let's take a look at an example,

A population is experiencing an outbreak of a condition that affects 1% of the total population. In response, a test has been developed that correctly identifies the condition 95% of the time. However, the test incorrectly flags healthy individuals as having the condition 3% of the time.

Given this information, what is the probability that an individual has the condition if they test positive?

This post is for subscribers only

Already have an account? Sign in.

Subscribe to Another Dev's Two Cents

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.