Skip to content
datarekha

Bayes' Theorem

The direction you can measure — a test's accuracy, P(positive given disease) — is rarely the one you want, P(disease given positive). Bayes is the single rule that turns one into the other, and the base-rate twist inside it is the most-tested idea in GATE probability.

7 min read Intermediate GATE DA Lesson 7 of 122

What you'll learn

  • Bayes as the inversion of a conditional: from P(E|H) to P(H|E)
  • Prior, likelihood, evidence (the normaliser), and posterior
  • Working a medical-test problem to a number (a real 2026 question)
  • Why a positive test for a rare condition is usually a false alarm

Before you start

We ended the last lesson stuck on a flip. The factory told us the chance a part is defective given its machine, but the inspector wanted the machine given a defective part. A doctor’s test reports the chance of a positive result given the disease, yet the patient wants the disease given a positive result. The direction you can easily measure is hardly ever the direction you care about. Bayes’ theorem is the one rule that turns the conditional around.

The rule that flips a conditional

Let us build it from the multiplication rule you already have. The chance of both a hypothesis H and some evidence E can be written two ways, depending on which you condition on first:

P(H ∩ E) = P(E | H) · P(H)        and        P(H ∩ E) = P(H | E) · P(E)

Both equal the same P(H ∩ E), so set them equal and divide by P(E). Out drops Bayes’ theorem — the wanted direction P(H | E) in terms of the measurable one P(E | H):

P(H | E)=P(E | H) · P(H)P(E)posteriorlikelihoodpriorevidence (normaliser)
Posterior belief = how well the cause explains the evidence, scaled by how likely the cause was to begin with.

Each piece has a plain name, and naming them now that the formula is in front of you makes Bayes feel less like algebra and more like updating a belief:

  • the prior P(H) — what you believed before the evidence,
  • the likelihood P(E | H) — how well the hypothesis explains the evidence,
  • the evidence P(E) — the total chance of seeing E at all, the denominator that keeps the answer a proper probability,
  • the posterior P(H | E) — your updated belief after the evidence.

So Bayes reads as a sentence: your belief after seeing the evidence is your belief before, reweighted by how well the hypothesis accounts for what you saw. Drag the prior below and watch a flat starting belief reshape, flip by flip, into a confident posterior.

Trybayesian updating

Flip a coin of unknown bias — watch belief sharpen

Your belief about the coin’s bias θ is a Beta(α, β). Each flip updates it: posterior = Beta(α + H, β + T).

Prior
priorposterior
0.00.20.40.60.81.0θ (coin bias)
Data
0H / 0T
no flips yet
Posterior mean
0.500
(α+H)/(α+β+H+T)
MAP
0.500
most likely θ
95% interval
[0.09, 0.91]
central credible

Try No idea vs Believe fair, then flip ~50 times — with enough evidence the two posteriors converge. The prior fades; the data wins.

A worked example — a real 2026 question

A disease affects 30% of a population. A test detects it correctly 80% of the time, and gives a 10% false-positive rate on healthy people. A person tests positive. What is the chance they have the disease?

Lay out the four numbers, then put the total chance of a positive in the denominator — a positive can arrive two ways, from a sick person or a healthy one:

P(D) = 0.30,  P(+|D) = 0.80,  P(+|¬D) = 0.10,  P(¬D) = 0.70

              P(+|D)·P(D)                 0.80 · 0.30            0.24
P(D|+) = ───────────────────────── = ───────────────────── = ────── ≈ 0.77
          P(+|D)·P(D) + P(+|¬D)·P(¬D)   0.80·0.30 + 0.10·0.70   0.31

So about 0.77. This is GATE DA 2026, question 57, and 0.77 is the verified answer. The disease was common enough at 30% that a positive really is convincing.

When the base rate is tiny

Now turn the prior down and watch the whole answer collapse. Suppose the disease is rare — only 1% of people have it — tested by an instrument that is 99% sensitive (it flags 99 of every 100 people who truly have the disease) and has a 5% false-positive rate (it wrongly flags 5 of every 100 healthy people). Run the same recipe:

              0.99 · 0.01                  0.0099
P(D|+) = ───────────────────────── = ──────────────── ≈ 0.17
          0.99·0.01 + 0.05·0.99        0.0594

A near-perfect test, a positive result, and yet only a 17% chance of actually being ill. The reason is the base rate: when almost nobody has the disease, the healthy millions produce more false positives than the sick few produce true ones.

Count it out on ten thousand people and it stops feeling like a paradox. One hundred of them are ill, and the test flags 99 of those. The other 9,900 are healthy, and 5% of them — 495 people — get flagged anyway. So 594 people walk out holding a positive result, and only 99 are actually ill: 99 / 594 ≈ 0.17, exactly what the formula gave. The false alarms outnumber the true ones five to one, not because the test is poor, but because there are so many more healthy people to be wrong about.

Drag the prevalence slider and watch the posterior swing.

TryBayes on people

Why a 99%-accurate test still mostly catches healthy people

Each cell is one person. Drag the sliders — watch how false positives (healthy but tested positive) can outnumber true positives when the disease is rare.

Sick + positive (TP)Sick + negative (FN)Healthy + positive (FP)Healthy + negative (TN)
P(sick | positive)50%
True positives5
False positives5
Total positives10
P(sick | positive)=5 TP5 TP + 5 FP=0.50

A question to carry forward

So far each “hypothesis” was a single yes-or-no — sick or healthy, one machine or the other. Here is the thread onward: when there are several competing causes (three boxes a ball might come from, four machines a part might leave), the denominator simply grows one term per cause. How does the recipe stretch when the evidence could have come from many sources rather than two?

In one breath

  • Bayes flips the conditional: from the measurable P(E|H) to the wanted P(H|E)P(H|E) = P(E|H)·P(H) / P(E).
  • Four parts: prior P(H) (belief before), likelihood P(E|H) (how well H explains E), evidence P(E) (the total-probability normaliser), posterior P(H|E) (belief after).
  • The recipe (a guaranteed NAT): write prior × likelihood for every hypothesis, sum them for the denominator, divide the one you want. Disease 2026: 0.8·0.3 / (0.8·0.3 + 0.1·0.7) ≈ 0.77.
  • Base rates dominate: a rare condition makes most positives false alarms (P(disease|+) ≈ 0.17 at 1% prevalence) — never read the accuracy P(+|D) as the answer P(D|+).
  • It is just conditional + total probability, run backwards.

Practice

Quick check

0/6
Q1Recall: in P(H|E) = P(E|H)·P(H)/P(E), which piece is the prior?
Q2Trace: the real 2026 question — disease in 30%, test 80% sensitive, 10% false positive, a positive result. Find P(disease | positive). (2 decimals)numerical answer — type a number
Q3Trace: a rare disease at 1% prevalence, a 99%-sensitive test with a 5% false-positive rate, a positive result. Find P(disease | positive). (2 decimals)numerical answer — type a number
Q4Apply: recall the factory — Machine 1 makes 60% at 2% defective, Machine 2 makes 40% at 5% defective. Given a defective part, find P(it came from Machine 2). (3 decimals)numerical answer — type a number
Q5Apply: a test is 90% accurate at detecting a condition. Someone reasons, 'I tested positive, so there's a 90% chance I have it.' What's wrong?
Q6Create: a spam filter knows 40% of mail is spam; the word 'free' appears in 60% of spam but only 5% of real mail. An email contains 'free'. Set up Bayes and find P(spam | 'free'). (2 decimals)

Sign in to track your progress

Completed lessons, your XP, level, and streak save to your account — it's free and takes a few seconds.

Practice this in an interview

All questions
Walk me through Bayes' theorem with a disease-screening base-rate example.

Bayes' theorem updates a prior probability with new evidence: P(H|E) = P(E|H) P(H) / P(E). In disease testing, ignoring the low base rate (prior) makes a positive test look far more alarming than it really is — most positives are false positives when the disease is rare.

Explain demographic parity vs equalized odds. Can you satisfy both at once?

Demographic parity requires equal positive-prediction rates across groups, ignoring the true label; equalized odds requires equal true-positive and false-positive rates across groups, conditioning on the true label. In general you cannot satisfy both simultaneously (except in degenerate cases), because of impossibility results when base rates differ. Which metric to use depends on the harm you're trying to prevent.

What is p-hacking and how does multiple testing inflate false-positive rates?

P-hacking is the practice of making analytic choices — selecting metrics, segments, or time windows — after seeing data, guided by which choices produce p < 0.05. Multiple testing means that even without intent, testing many hypotheses at alpha = 0.05 expects one false positive per 20 tests.

What is conditional probability, and how does it differ from joint probability?

Conditional probability P(A|B) is the probability of A after learning that B occurred, computed as P(A and B) divided by P(B). Joint probability P(A and B) is the probability that both events occur in the full sample space, so conditional probability changes the denominator while joint probability does not.

Related lessons

Explore further