Probability — Topic 03

Bayes' Theorem
Updating Beliefs with New Evidence

A positive medical test doesn't mean you're sick. A negative one doesn't mean you're healthy. Bayes' Theorem is the mathematical machinery for reasoning correctly under uncertainty, combining what you knew before with what a new observation tells you.

P(A|B)Posterior Probability
10Worked Examples
4Real-World Applications
10Quiz Questions
Share this page
On This Page
  1. The Intuition, What Does Bayes Actually Do?
  2. Derivation from Conditional Probability
  3. The Law of Total Probability
  4. Bayesian Vocabulary, Prior, Likelihood, Posterior
  5. The Extended Form of Bayes' Theorem
  6. Tree Diagrams, Organising Bayesian Problems
  7. Fully Worked Examples
  8. Real-World Applications
  9. Common Mistakes
  10. 10-Question Quiz

§ 01The Intuition — What Does Bayes Actually Do?

Bayes' Theorem answers a single question: given that I have observed event B, how should I update my probability that event A is true?

Here is the classic scenario. A rare disease affects 1 in 1000 people. A diagnostic test for it is 99% accurate, it correctly identifies 99% of sick people and correctly clears 99% of healthy people. You test positive. Should you panic?

Most people's intuition says yes, 99% accurate sounds extremely reliable. But Bayes' Theorem reveals something surprising. Out of every 1000 people tested, roughly 1 is actually sick and tests positive, while roughly 10 healthy people also test positive (the 1% false-positive rate applied to the 999 healthy people). So of the ~11 positive results, only 1 is a true positive. Your probability of actually being sick, given a positive test, is only about 9%: not 99%.

This is not a flaw in the test. It is a mathematical consequence of the disease being rare. Bayes' Theorem is the tool that makes this calculation precise and general. It is used in medical diagnosis, spam filtering, courtroom evidence evaluation, machine learning, search engines, and scientific hypothesis testing.

Prerequisites This page assumes you are comfortable with basic probability (sample spaces, P(A), P(A ∪ B), P(A ∩ B)) and conditional probability (P(A|B) = P(A ∩ B)/P(B), the multiplication rule, and independence). If either of those feels shaky, review them first — Bayes' Theorem is a direct algebraic consequence of the conditional probability definition.

§ 02Derivation from Conditional Probability

The derivation of Bayes' Theorem requires nothing beyond the definition of conditional probability applied twice. Recall that for any two events A and B with P(B) > 0:

Conditional Probability — Definition
P(A | B) = P(A ∩ B) / P(B) P(B | A) = P(A ∩ B) / P(A)

Both expressions involve the same joint probability P(A ∩ B) in the numerator. Setting them equal gives Bayes' Theorem immediately.

From the second equation: P(A ∩ B) = P(B | A) · P(A). Substituting into the first:

Bayes' Theorem
P(A | B) = P(B | A) · P(A) / P(B)

Provided P(B) > 0. This is the complete theorem. Everything else (the law of total probability, extended form, Bayesian inference) is elaboration on how to compute P(B) in the denominator.

The theorem tells you how to "invert" a conditional probability: if you know P(B | A) (how likely is B given A?), you can find P(A | B) (how likely is A given B?): provided you also know P(A) and P(B). In most applications, P(B) is not given directly and must be computed using the law of total probability.

Why This Is Profound In many practical situations, P(B | A) is easy to measure directly — for example, "what fraction of sick people test positive?" (the sensitivity of the test). But the clinically useful quantity is P(A | B) — "given that this person tested positive, what is the probability they are sick?" Bayes' Theorem bridges the gap between what is easy to measure and what we actually want to know.

§ 03The Law of Total Probability

Bayes' Theorem requires P(B) in the denominator. When P(B) is not given directly, it can almost always be computed by conditioning on a partition of the sample space.

A set of events {A₁, A₂, …, Aₙ} is a partition of the sample space if the events are mutually exclusive (no two can happen simultaneously) and exhaustive (one of them must happen). For example, {Disease, No Disease} is a partition of the health-status space.

Law of Total Probability
P(B) = Σᵢ P(B | Aᵢ) · P(Aᵢ)

For the two-event case (A and its complement Aᶜ), this simplifies to:

P(B) = P(B | A)·P(A) + P(B | Aᶜ)·P(Aᶜ)

This is the most-used form. The full Bayes' formula with total probability expanded in the denominator is:

P(A | B) = P(B|A)·P(A) / [P(B|A)·P(A) + P(B|Aᶜ)·P(Aᶜ)]

This combined formula is what you actually use in practice. The numerator is the probability of the path "A happened, then B happened." The denominator is the total probability of B happening across all possible paths (whether A happened or not). Dividing gives the fraction of all B-outcomes that came from path A.

§ 04Bayesian Vocabulary — Prior, Likelihood, Posterior

Bayesian statistics introduces specific terminology for each component of the formula. Understanding these terms makes it much easier to set up problems correctly.

Prior — P(A)
Your belief about A before seeing evidence B
In the disease example: the base rate of the disease in the population (1 in 1000). This is what you know before any test result.
Likelihood — P(B | A)
How probable is the evidence B, assuming A is true?
In the disease example: the probability of testing positive if you have the disease (sensitivity = 99%). This is what makes the evidence informative.
Posterior — P(A | B)
Your updated belief about A after observing evidence B
In the disease example: the probability you actually have the disease, given the positive test. This is what Bayes computes — the prior updated by the evidence.
Marginal Likelihood — P(B)
Total probability of observing evidence B
Computed via the law of total probability. It normalises the formula so that probabilities sum to 1. Often called the "evidence" in Bayesian contexts.
Bayes' Theorem in Bayesian Language
Posterior ∝ Likelihood × Prior

The symbol ∝ means "proportional to", dividing by P(B) just normalises to make the posterior a valid probability. The essential message is: your new belief is your old belief multiplied by how well A explains the evidence, then rescaled.

§ 05The Extended Form of Bayes' Theorem

When the hypothesis space has more than two possibilities, for example, a disease could be one of three types, or a manufacturing defect could come from one of four machines, the extended form of Bayes' Theorem handles them all simultaneously.

Extended Bayes' Theorem
P(Aₖ | B) = P(B | Aₖ) · P(Aₖ) / Σᵢ [P(B | Aᵢ) · P(Aᵢ)]

where {A₁, A₂, …, Aₙ} is a partition of the sample space, and k is any one of the hypotheses whose posterior probability you want. The denominator is the same for every k, it is just the law of total probability applied to the full partition.

The practical procedure is always the same: for each hypothesis Aᵢ, compute the product P(B | Aᵢ) × P(Aᵢ). Then divide each product by their sum. This gives the posterior probability of each hypothesis given the evidence B.

Example 01 Extended Bayes — Defective item from which machine?

A factory has three machines: M₁ produces 50% of output with a 2% defect rate, M₂ produces 30% with a 3% defect rate, M₃ produces 20% with a 5% defect rate. A randomly selected item is defective. What is the probability it came from each machine?

Priors
P(M₁) = 0.5, P(M₂) = 0.3, P(M₃) = 0.2
Likelihoods
P(D|M₁) = 0.02, P(D|M₂) = 0.03, P(D|M₃) = 0.05
Numerators
P(D|M₁)·P(M₁) = 0.02×0.5 = 0.010 P(D|M₂)·P(M₂) = 0.03×0.3 = 0.009 P(D|M₃)·P(M₃) = 0.05×0.2 = 0.010
P(D) — denominator
P(D) = 0.010 + 0.009 + 0.010 = 0.029
Posteriors
P(M₁|D) = 0.010/0.029 ≈ 34.5% P(M₂|D) = 0.009/0.029 ≈ 31.0% P(M₃|D) = 0.010/0.029 ≈ 34.5%

Despite M₃ producing the least output, its high defect rate makes it equally likely as M₁ to be the source of a defective item.

§ 06Tree Diagrams — Organising Bayesian Problems

A probability tree is the most reliable visual tool for Bayesian problems. Each path through the tree represents one combination of events; the probability of the path is the product of the probabilities along its branches. Bayes' Theorem then becomes a matter of identifying the right paths and dividing.

Figure 01 — Probability Tree for a Medical Test
Person Disease P(D) = 0.001 No Disease P(Dᶜ) = 0.999 + 0.99 0.001×0.99 = 0.00099 ← TRUE POSITIVE − 0.01 0.001×0.01 = 0.00001 ← false negative + 0.01 0.999×0.01 = 0.00999 ← FALSE POSITIVE − 0.99 0.999×0.99 = 0.98901 ← true negative
For a disease with prevalence 0.1% and a test with 99% sensitivity and 99% specificity: the false-positive path (0.00999) is ten times larger than the true-positive path (0.00099). The posterior probability of disease given a positive test is 0.00099 / (0.00099 + 0.00999) ≈ 9%.

The Three-Step Tree Method

For any Bayesian problem, follow this procedure systematically:

Step 1 — First branches
Draw one branch per hypothesis (A₁, A₂, …). Label each with its prior probability P(Aᵢ).
Step 2 — Second branches
From each hypothesis node, draw branches for each possible observation. Label each with the conditional probability P(B | Aᵢ).
Step 3 — Multiply & divide
Multiply along each path to get joint probabilities P(Aᵢ ∩ B). Add the relevant paths to get P(B). Then divide each relevant path by P(B) to get the posterior.

§ 07Fully Worked Examples

Example 02 The medical test — classic base-rate problem

A disease affects 0.5% of the population. A test has 95% sensitivity (true positive rate) and 90% specificity (true negative rate, so 10% false-positive rate). A patient tests positive. What is the probability they have the disease?

Define events

D = has disease, T⁺ = tests positive. P(D) = 0.005, P(Dᶜ) = 0.995.

P(T⁺|D) = 0.95 (sensitivity) P(T⁺|Dᶜ) = 0.10 (false-positive rate)
Law of Total Prob.
P(T⁺) = 0.95×0.005 + 0.10×0.995 = 0.00475 + 0.0995 = 0.10425
Apply Bayes
P(D|T⁺) = 0.00475 / 0.10425 ≈ 0.0456
Result
P(Disease | Positive test) ≈ 4.6%

Even with a 95%-sensitive test, the low base rate means only about 1 in 22 people who test positive actually have the disease. The high false-positive rate (10%) swamps the true positives from the rare disease.

Example 03 Two coins — which one was flipped?

A bag contains two coins: Coin A is fair (P(H) = 0.5) and Coin B is biased (P(H) = 0.8). You pick one coin at random and flip it. It lands heads. What is the probability you picked Coin B?

Priors
P(A) = P(B) = 0.5
Likelihoods
P(H|A) = 0.5, P(H|B) = 0.8
P(H)
= 0.5×0.5 + 0.8×0.5 = 0.65
Posteriors
P(B|H) = (0.8×0.5)/0.65 = 0.4/0.65 ≈ 0.615 P(A|H) = (0.5×0.5)/0.65 ≈ 0.385
Result
P(Coin B | Heads) ≈ 61.5%

The heads outcome has updated our belief toward the biased coin, but only moderately, one flip is not conclusive.

Example 04 Sequential Bayesian updating — flipping twice

Using the same bag of coins as Example 03, you flip the chosen coin a second time and it lands heads again. Update the probability that you have Coin B.

New priors

Use the posteriors from Example 03 as the new priors:

P(B) = 8/13 ≈ 0.615, P(A) = 5/13 ≈ 0.385
P(H) again
= 0.8×(8/13) + 0.5×(5/13) = 6.4/13 + 2.5/13 = 8.9/13
Update
P(B|HH) = (0.8×8/13)/(8.9/13) = 6.4/8.9 ≈ 0.719
Result
P(Coin B | Two Heads) ≈ 71.9%

Each new observation of heads strengthens our belief that the biased coin was chosen. This sequential updating is the essence of Bayesian learning, the posterior from one update becomes the prior for the next.

Example 05 Spam filter — classifying an email by keyword

40% of emails are spam. The word "offer" appears in 60% of spam emails and 5% of legitimate emails. An email contains the word "offer." What is the probability it is spam?

Setup

P(Spam) = 0.4, P(Legit) = 0.6, P("offer"|Spam) = 0.6, P("offer"|Legit) = 0.05

P("offer")
= 0.6×0.4 + 0.05×0.6 = 0.24 + 0.03 = 0.27
Posterior
P(Spam|"offer") = 0.24 / 0.27 ≈ 0.889
Result
P(Spam | "offer") ≈ 88.9%

A single suspicious keyword raises the spam probability from the prior 40% to 89%. Real spam filters do this for hundreds of words simultaneously, taking the product of likelihoods (Naïve Bayes classifier).

Example 06 Urn selection — which urn did the ball come from?

Urn I contains 3 red and 7 blue balls. Urn II contains 6 red and 4 blue balls. An urn is selected at random and a ball is drawn. It is red. What is the probability it came from Urn II?

Priors
P(I) = P(II) = 0.5
Likelihoods
P(R|I) = 3/10 = 0.3P(R|II) = 6/10 = 0.6
P(R)
= 0.3×0.5 + 0.6×0.5 = 0.45
Result
P(II|R) = (0.6×0.5)/0.45 = 0.3/0.45 = 2/3
Example 07 Security screening — computing the false alarm rate

At an airport, 0.01% of passengers carry a prohibited item. The scanner detects prohibited items 98% of the time and has a 2% false-alarm rate (flags a safe passenger). A passenger is flagged. What is the probability they are carrying a prohibited item?

Data

P(Prohibited) = 0.0001, P(Flag|Prohibited) = 0.98, P(Flag|Safe) = 0.02

P(Flag)
= 0.98×0.0001 + 0.02×0.9999 = 0.000098 + 0.019998 = 0.020096
Bayes
P(Prohibited|Flag) = 0.000098/0.020096 ≈ 0.00488
Result
P(Prohibited | Flagged) ≈ 0.49%

Less than 1 in 200 flagged passengers actually carries a prohibited item. This drives real-world secondary screening procedures, the first alarm is rarely conclusive when the base rate is very low.

§ 08Real-World Applications

Bayes' Theorem is not a classroom curiosity: it underlies some of the most important reasoning tools in science, medicine, law, and technology.

Medical Diagnosis
Posterior = P(Disease | Test Result)
Every diagnostic test result must be interpreted relative to the base rate of the disease. Bayes' Theorem explains why rare diseases are usually not the cause of a positive test — even with highly accurate tests.
Naïve Bayes Classifier
P(Class | Features) ∝ P(Features | Class) · P(Class)
The foundation of spam filters and text classifiers. Assumes features (words) are independent given the class — hence "naïve" — but performs remarkably well in practice.
Courtroom Evidence
Posterior odds = Bayes Factor × Prior odds
Forensic evidence (DNA, fingerprints) shifts the probability of guilt. The "prosecutor's fallacy" is the error of confusing P(Evidence | Innocent) with P(Innocent | Evidence).
Scientific Hypothesis Testing
Posterior ∝ Likelihood × Prior
Bayesian statistics treats parameters as random variables and updates beliefs as data arrives. It avoids some paradoxes of classical (frequentist) hypothesis testing.
Example 08 The prosecutor's fallacy — DNA evidence

DNA at a crime scene matches a suspect. The probability of a random person's DNA matching by chance is 1 in 1,000,000. The prosecutor argues: "There is only a 1-in-a-million chance the suspect is innocent." Explain the flaw using Bayes' Theorem.

The error

The prosecutor is confusing P(Match | Innocent) = 0.000001 with P(Innocent | Match). These are not the same quantity.

Bayes corrects it

Suppose the city has 1,000,000 people, and initially P(Guilty) = 1/1,000,000 (one guilty person among a million).

P(Match|Guilty) ≈ 1 P(Match|Innocent) = 0.000001 P(Match) ≈ 1/1,000,000 + 0.000001×999,999/1,000,000 ≈ 0.000001 + 0.000001 = 0.000002
Correct posterior
P(Guilty|Match) ≈ 0.000001/0.000002 = 50%

The correct posterior is 50%, not 99.9999%. Additional evidence (motive, alibi, eyewitness testimony) must be used to update this further. A DNA match alone is not nearly as conclusive as the prosecutor claims.

Example 09 The Monty Hall Problem — resolved with Bayes

Three doors: a car behind one, goats behind the others. You pick Door 1. The host (who knows where the car is) opens Door 3, revealing a goat. Should you switch to Door 2?

Priors

P(Car at Door 1) = P(Car at Door 2) = P(Car at Door 3) = 1/3

Likelihoods

P(Host opens Door 3 | Car at Door 1) = 1/2 (host chooses randomly between Doors 2 and 3)

P(Host opens Door 3 | Car at Door 2) = 1 (host must open Door 3, since Door 2 has the car)

P(Host opens Door 3 | Car at Door 3) = 0 (host cannot reveal the car)

P(Host opens 3)
= (1/2)(1/3) + (1)(1/3) + (0)(1/3) = 1/6 + 1/3 = 1/2
Posteriors
P(D1 | Host opens 3) = (1/2·1/3)/(1/2) = 1/3 P(D2 | Host opens 3) = (1·1/3)/(1/2) = 2/3
Result
Switching wins with probability 2/3. Staying wins with probability 1/3.

You should always switch. The host's action (which is not random) transfers probability from Door 3 to Door 2. Bayes' Theorem makes this rigorous.

Example 10 Two independent tests — both positive

Using the disease scenario from Example 02 (prevalence 0.5%, sensitivity 95%, false-positive rate 10%): a patient tests positive on the first test, then takes a second independent test and is positive again. What is the final probability of disease?

After Test 1

From Example 02: P(D | T₁⁺) ≈ 0.0456. Use this as the new prior.

P(T₂⁺)
= 0.95×0.0456 + 0.10×0.9544 = 0.04332 + 0.09544 = 0.13876
Final posterior
P(D|T₁⁺,T₂⁺) = (0.95×0.0456)/0.13876 ≈ 0.0433/0.1388 ≈ 0.312
Result
P(Disease | Two positive tests) ≈ 31.2%

Two positive results push the probability from 4.6% to 31%, substantial, but still less than even odds. The base rate of 0.5% is so low that even two positive tests leave considerable uncertainty. A third positive test would raise it to approximately 77%.

§ 09Common Mistakes

Mistake 1: The Base Rate Neglect The single most common error in Bayesian reasoning is ignoring the prior P(A) and focusing only on the likelihood P(B | A). People hear "99% accurate test" and interpret a positive result as "99% chance of disease," completely omitting the base rate. Always identify P(A) first — it anchors everything else.
Mistake 2: The Prosecutor's Fallacy — P(B|A) ≠ P(A|B) Confusing "probability of the evidence given innocence" with "probability of innocence given the evidence" is a classic logical error with serious real-world consequences. P(Match | Innocent) = 0.000001 does NOT mean P(Innocent | Match) = 0.000001. Always apply Bayes' Theorem to invert the conditional correctly.
Mistake 3: Wrong denominator in P(B) When using the law of total probability, the sum must cover all mutually exclusive, exhaustive cases. If you list only some hypotheses (e.g., forget a third machine or a third disease type), your P(B) will be too small and all posteriors will be inflated. Check that all your priors sum to 1.
Mistake 4: Double-counting the evidence In sequential updating (Example 04), the posterior from round 1 becomes the prior for round 2 — you must NOT re-use the original prior. If you apply Bayes' Theorem twice with the same original prior and two observations, you are pretending each observation updates from scratch, ignoring the information already incorporated.
Mistake 5: Assuming tests are independent when they are not In Example 10, we assumed the two test results are independent given the true disease status. If both tests use the same biological mechanism (e.g., same antibody), they may be correlated, and the sequential update is not valid. Independence of tests conditional on the hypothesis must be established before sequential Bayesian updating is applied.
Strategy: Always Write Out the Full Table For two-hypothesis problems, create a 2×2 table: rows = hypotheses (A, Aᶜ), columns = observations (B, Bᶜ). Fill in joint probabilities (prior × likelihood) in each cell. Row sums give the priors; column sums give the marginal likelihoods. Each cell divided by its column sum gives the posterior. This eliminates almost every common error.

§ 10Test Your Understanding

Ten questions covering all aspects of Bayes' Theorem: from vocabulary and formula recall to numerical application and conceptual traps. Work each one before revealing the explanation.

10-Question Quiz
Bayes' Theorem & Conditional Probability

Cookie Settings