Home /permanent

Bayes Theorem

Photo by Daniel Sone / National Cancer Institute on Unsplash, cropped.

Bayes' theorem (or Bayes' rule) allows us to update the probability of an event based on new evidence.

It builds on Conditional Probability. The basic form is:

Posterior=Likelihood×PriorEvidence\text{Posterior} = \frac{\text{Likelihood} \times \text{Prior}}{\text{Evidence}}

The prior is the probability before considering the new evidence. The posterior is the updated probability after considering it.

Example: A Positive Disease Test

Let's say we want to compute the probability that a person has a disease, given that they test positive for it:

P(Disease∣Positive test)P(\text{Disease} \mid \text{Positive test})

We'll use these illustrative figures:

  • 1%1\% of the population has the disease: P(Disease)=0.01P(\text{Disease}) = 0.01.
  • The test returns a positive result for 90%90\% of people with the disease: P(Positive test∣Disease)=0.90P(\text{Positive test} \mid \text{Disease}) = 0.90.
  • The test also returns a positive result for 15%15\% of people without the disease: P(Positive test∣No disease)=0.15P(\text{Positive test} \mid \text{No disease}) = 0.15.

The 1%1\% figure is our prior. The 90%90\% figure is the likelihood of a positive result given the disease. The 15%15\% figure is the false-positive rate.

Using Bayes' theorem:

P(Disease∣Positive test)=P(Positive test∣Disease)×P(Disease)P(Positive test)P(\text{Disease} \mid \text{Positive test}) = \frac{P(\text{Positive test} \mid \text{Disease}) \times P(\text{Disease})}{P(\text{Positive test})}

The denominator is the probability of getting a positive test result overall, whether or not the person has the disease. This is what evidence means in the formula.

Calculating the Probability of a Positive Test

The only value we don't yet know is P(Positive test)P(\text{Positive test}).

A positive result can come from someone with the disease or someone without it. These cases are mutually exclusive and cover all positive results, so we can use the Addition Rule of Probability:

P(Positive test)=P(Positive test and Disease)+P(Positive test and No disease) \begin{aligned} P(\text{Positive test}) &= P(\text{Positive test and Disease}) \\ &\quad + P(\text{Positive test and No disease}) \end{aligned}

Then we apply the general multiplication rule to each term:

P(Positive test)=P(Positive test∣Disease)×P(Disease)+P(Positive test∣No disease)×P(No disease) \begin{aligned} P(\text{Positive test}) &= P(\text{Positive test} \mid \text{Disease}) \times P(\text{Disease}) \\ &\quad + P(\text{Positive test} \mid \text{No disease}) \times P(\text{No disease}) \end{aligned}

This is the law of total probability, which we used for total enumeration in Conditional Probability.

Since P(No disease)=1−0.01=0.99P(\text{No disease}) = 1 - 0.01 = 0.99, substituting our values gives:

P(Positive test)=0.90×0.01+0.15×0.99P(\text{Positive test}) = 0.90 \times 0.01 + 0.15 \times 0.99

P(Positive test)=0.009+0.1485=0.1575=15.75%P(\text{Positive test}) = 0.009 + 0.1485 = 0.1575 = 15.75\%

Updating the Probability of Disease

Now we can fill in the denominator:

P(Disease∣Positive test)=0.90×0.010.1575≈0.05714≈5.7%P(\text{Disease} \mid \text{Positive test}) = \frac{0.90 \times 0.01}{0.1575} \approx 0.05714 \approx 5.7\%

Under these assumptions, a positive result raises the probability of having the disease from 1%1\% to about 5.7%5.7\%.

The result is still relatively low because the disease is rare and false positives are common. In an imaginary population of 10,000 people with exactly these proportions, 90 people with the disease and 1,485 people without it would test positive. Only 90 of the 1,575 positive results would be from people with the disease.

General Form

For general events AA and BB, Bayes' theorem is:

P(A∣B)=P(B∣A)×P(A)P(B)P(A \mid B) = \frac{P(B \mid A) \times P(A)}{P(B)}

This requires P(B)>0P(B) > 0. If P(B)P(B) is not already known, we can expand it using the law of total probability:

P(A∣B)=P(B∣A)×P(A)P(B∣A)×P(A)+P(B∣Ac)×P(Ac)P(A \mid B) = \frac{P(B \mid A) \times P(A)}{P(B \mid A) \times P(A) + P(B \mid A^c) \times P(A^c)}

Here, AcA^c is the Complement Rule of AA, meaning that AA does not occur, and P(Ac)=1−P(A)P(A^c) = 1 - P(A). The expanded form assumes both cases have nonzero probability so their conditional probabilities are defined.

Use the shorter formula when the denominator is already known. Otherwise, calculate it separately or use the expanded form. Both approaches give the same result.