How to use Bayes' theorem

Bayes' theorem calculates the probability of an event based on prior knowledge of conditions that might be related to the event. It applies when you know the probability of the evidence given a hypothesis, the prior probability of the hypothesis, and the overall probability of the evidence.

The setup

Identify the hypothesis HH and the evidence EE. State the known probabilities: the prior P(H)P(H), the likelihood P(EH)P(E|H), and the false positive rate P(EHc)P(E|H^c). If the total probability of the evidence P(E)P(E) is not given directly, calculate it using the Law of Total Probability: P(E)=P(EH)P(H)+P(EHc)P(Hc)P(E) = P(E|H)P(H) + P(E|H^c)P(H^c).

The steps

  1. Define events HH (hypothesis) and EE (evidence). 2. Extract P(H)P(H), P(EH)P(E|H), and P(EHc)P(E|H^c) from the problem statement. Calculate P(Hc)=1P(H)P(H^c) = 1 - P(H). 3. Compute the denominator P(E)P(E) using the Law of Total Probability. 4. Apply Bayes' formula: P(HE)=P(EH)P(H)P(E)P(H|E) = \frac{P(E|H)P(H)}{P(E)}.

Checking the result

Ensure 0P(HE)10 \le P(H|E) \le 1. Verify that if the evidence is more likely under the hypothesis than in general (P(EH)>P(E)P(E|H) > P(E)), then the posterior probability P(HE)P(H|E) must be greater than the prior probability P(H)P(H).

Common errors

Confusing the likelihood P(EH)P(E|H) with the posterior P(HE)P(H|E). Failing to use the Law of Total Probability for the denominator when the total probability of the evidence is not explicitly provided.

Worked example

A disease affects 1% of a population. A test for the disease is 99% accurate (both true positive and true negative rates are 0.99). If a person tests positive, what is the probability they actually have the disease?

Let DD be having the disease and TT be testing positive. We know: P(D)=0.01P(D) = 0.01, P(TD)=0.99P(T|D) = 0.99, and P(TcDc)=0.99P(T^c|D^c) = 0.99. Therefore, P(TDc)=10.99=0.01P(T|D^c) = 1 - 0.99 = 0.01 and P(Dc)=0.99P(D^c) = 0.99. We need P(DT)P(D|T). Step 1: Calculate the denominator P(T)=P(TD)P(D)+P(TDc)P(Dc)P(T) = P(T|D)P(D) + P(T|D^c)P(D^c). Substituting the values gives P(T)=(0.99)(0.01)+(0.01)(0.99)=0.0099+0.0099=0.0198P(T) = (0.99)(0.01) + (0.01)(0.99) = 0.0099 + 0.0099 = 0.0198. Step 2: Apply Bayes' theorem: P(DT)=P(TD)P(D)P(T)=0.00990.0198=0.5P(D|T) = \frac{P(T|D)P(D)}{P(T)} = \frac{0.0099}{0.0198} = 0.5. The probability is 50%.

FAQ

Run your own problem

References: OpenStax Introductory Statistics, Chapter 3 · Introduction to Probability by Bertsekas and Tsitsiklis, Chapter 1

See also