Educerie

This whole subtopic is higher level. Nothing in it is on an SL paper.

Educerie · IB Diploma · Mathematics: analysis and approaches

IB Mathematics AA 4.13 · HL only

Bayes' theorem

When you know how likely the evidence is for each possible cause, how do you work out how likely each cause is, now that you have seen the evidence?

What you will learn

  • HL Understand that Bayes' theorem turns P(evidence | cause) into P(cause | evidence)
  • HL Know Bayes' theorem for two causes and for three causes that split the sample space
  • HL Understand why a positive result for a rare condition can still mean a low chance of having it
  • HL Know that when the evidence is equally likely under every cause, the probability of the cause does not change

You must be able to

  1. HL Calculate a reversed conditional probability with Bayes' theorem from a tree or from given probabilities
  2. HL Calculate the total probability of the evidence as a sum of products
  3. HL Solve Bayes' problems with three causes and check the answers add to 1
  4. HL Comment on what a screening test result means in context
  5. HL Solve for an unknown probability from a given Bayes' answer
  6. HL Show that equal likelihoods under each cause mean the events are independent

In the exam. HL Paper 1 and Paper 2, as a 3 to 6 mark part of a longer probability question, usually after a tree diagram: "given that the parcel was damaged, find the probability that it passed through the south centre". Paper 1 uses exact fractions; Paper 2 uses decimals and contexts such as screening tests. A Paper 3 problem may hide a parameter that you find by working backwards.

1From the definition to the theorem

Start from the definition of conditional probability, aimed the way you want to go:

P(B∣A)=P(A∩B)P(A)P(B \mid A) = \frac{P(A \cap B)}{P(A)}

Now replace the top and bottom with things you know. The top comes from the alternate form in 4.11: P(A∩B)=P(B)P(A∣B)P(A \cap B) = P(B)P(A \mid B).

The bottom is the total probability of AA. AA happens either with BB or with B′B', and those two routes cannot overlap. So

P(A)=P(A∩B)+P(A∩B′)P(A) = P(A \cap B) + P(A \cap B')P(A)=P(B)P(A∣B)+P(B′)P(A∣B′)the law of total probabilityP(A) = P(B)P(A \mid B) + P(B')P(A \mid B') \qquad \textcolor{#838c91}{\text{the law of total probability}}

Put both into the definition:

P(B∣A)=P(B)P(A∣B)P(B)P(A∣B)+P(B′)P(A∣B′)P(B \mid A) = \dfrac{P(B)P(A \mid B)}{P(B)P(A \mid B) + P(B')P(A \mid B')} · Bayes' theorem, from the formula booklet.

The pair BB and B′B' is a partition of the sample space: they cannot both happen, and one must. The denominator needs only that.

Figure 1 shows where each piece sits on a tree. With BB drawn first, every quantity on the right-hand side of the formula is on a branch.

  • The numerator is the product along the teal path, BB then AA.
  • The denominator is the sum of the two paths that end in AA, teal and amber.

Bayes' theorem is nothing more than the "path over paths" recipe you used in 4.11, written in symbols.

Figure 1 · Bayes' theorem reads a tree backwards P(B) B P(B′) B′ P(A | B) A P(B) P(A | B) P(A′ | B) A′ P(A | B′) A P(B′) P(A | B′) P(A′ | B′) A′ P(B | A) = P(B) P(A | B) P(B) P(A | B) + P(B′) P(A | B′) The tree gives P(A | B). Bayes' theorem gives P(B | A): the teal path over both paths that end in A.
Figure 1 · Bayes' theorem reads a tree backwards

Two small points:

  • Sometimes a question gives P(A)P(A) outright instead of the two paths. Use the first form, P(B∣A)=P(B)P(A∣B)P(A)P(B \mid A) = \dfrac{P(B)P(A \mid B)}{P(A)}, and there is nothing to add up.
  • Once you have P(B∣A)P(B \mid A), the complement follows: P(B′∣A)=1−P(B∣A)P(B' \mid A) = 1 - P(B \mid A). Given AA, either BB or B′B' happened.

You can quote the formula and substitute, or draw the tree and compute path over paths. Both are valid. The formula suits a question that gives conditional probabilities in words. The tree suits one that asks several things about the same situation.

2Your first reversals

Three small cases first, before the screening test.

Two sources, one flaw

  • Example: a fruit stall buys crates from two farms, 60% from the hill farm (HH) and 40% from the river farm (RR). An apple is bruised (UU) with probability 0.050.05 if from HH and 0.100.10 if from RR.
  • A randomly chosen apple is bruised. Which farm did it most likely come from? Draw the farm first, the bruise second.
P(U)=0.6×0.05+0.4×0.10=0.03+0.04=0.07P(U) = 0.6 \times 0.05 + 0.4 \times 0.10 = 0.03 + 0.04 = 0.07P(H∣U)=0.030.07=37≈0.429P(H \mid U) = \frac{0.03}{0.07} = \frac{3}{7} \approx 0.429P(R∣U)=1−37=47P(R \mid U) = 1 - \frac{3}{7} = \frac{4}{7}

Before the bruise, HH was the likelier source (0.60.6). After it, RR is (47\tfrac{4}{7}), because RR bruises its apples twice as often. The evidence moved the probability from one farm to the other.

Reversing two draws

  • The cause does not have to be a machine. It can simply be the first of two events.
  • Example: a drawer holds 6 red and 4 black socks. Two are taken without replacement. Given that the second is black, find the probability that the first was red. In time order, the first draw is the cause and the second the evidence.
P(B2)=610×49+410×39=2490+1290=3690=25P(B_{2}) = \frac{6}{10} \times \frac{4}{9} + \frac{4}{10} \times \frac{3}{9} = \frac{24}{90} + \frac{12}{90} = \frac{36}{90} = \frac{2}{5}P(R1∣B2)=P(R1∩B2)P(B2)=24/9036/90=23P(R_{1} \mid B_{2}) = \frac{P(R_{1} \cap B_{2})}{P(B_{2})} = \frac{24/90}{36/90} = \frac{2}{3}

The second-draw fractions, 49\tfrac{4}{9} after a red and 39\tfrac{3}{9} after a black, change with the first draw. They are conditional: the draws are not independent.

Notice that P(B2)=25P(B_{2}) = \tfrac{2}{5} equals P(B1)P(B_{1}). With no information about the first draw, the second is as likely to be black as the first. That is a useful check.

It is also a cue: when a question says "given that the second… find the probability that the first…", it is a Bayes question.

Reading it off a table. Counts make the idea visible. Example: a library recorded 500 loans.

OverdueReturned on timeTotal
Fiction45255300
Non-fiction50150200
Total95405500

Given that a loan is overdue, the chance it is fiction is 4595=919\dfrac{45}{95} = \dfrac{9}{19}. Restrict attention to the overdue column and take the fiction share.

In probability language this is 300500×4530095500\dfrac{\frac{300}{500} \times \frac{45}{300}}{\frac{95}{500}}, the formula with the 300s cancelling. If a question hands you a table, read the answer straight off. If it hands you percentages, you need the formula.

3A screening test

The guide names medical studies as the context. A screening test is used for a condition that affects 1% of the people screened.

  • Among people who have the condition, the test is positive 95% of the time.
  • Among people who do not, it is still positive 8% of the time (a false positive).

A person tests positive. How likely is it that they have the condition?

Let DD be "has the condition" and ++ be "tests positive". Then P(D)=0.01P(D) = 0.01, P(+∣D)=0.95P(+ \mid D) = 0.95 and P(+∣D′)=0.08P(+ \mid D') = 0.08.

P(+)=P(D)P(+∣D)+P(D′)P(+∣D′)=0.01×0.95+0.99×0.08=0.0095+0.0792=0.0887\begin{aligned}P(+) &= P(D)P(+ \mid D) + P(D')P(+ \mid D') \\[6pt] &= 0.01 \times 0.95 + 0.99 \times 0.08 \\[6pt] &= 0.0095 + 0.0792 = 0.0887\end{aligned}P(D∣+)=P(D)P(+∣D)P(+)=0.00950.0887=0.107 (3 s.f.)\begin{aligned}P(D \mid +) &= \frac{P(D)P(+ \mid D)}{P(+)} \\[6pt] &= \frac{0.0095}{0.0887} \\[6pt] &= 0.107 \ \text{(3 s.f.)}\end{aligned}

A positive result means about an 11% chance of having the condition. Most people find that shocking: a "95% accurate" test sounds as though a positive should mean 95%.

Figure 2 shows why it does not, using natural frequencies. Imagine 10 000 people.

  • About 100 have the condition, and 95 of them test positive.
  • Of the 9 900 without it, 8% is 792, and every one of those tests positive too.
  • So 887 people test positive, and only 95 of them have the condition.

The false positives swamp the true ones, because there are so many more healthy people for the 8% to act on.

Figure 2 · The screening test in 10 000 people 10 000 people have the condition 1% → 100 do not have it 99% → 9 900 test positive 95% → 95 test negative 5 test positive 8% → 792 test negative 9 108 All 887 positive results, to scale 95 true 792 false positives Of the 887 people who test positive, only 95 have the condition: 95 ÷ 887 ≈ 0.107.
Figure 2 · The screening test in 10 000 people

The 1% is the prior probability, P(D)P(D) before any evidence. The answer 0.1070.107 is the posterior probability, P(D∣+)P(D \mid +) after it. You need not use the words, but they tell the story.

The evidence raised the probability more than tenfold, from 0.010.01 to 0.1070.107. It is still far from certain, because the prior was so small.

Figure 3 plots the same test in groups where the condition is more or less common. The posterior rises steeply with the prior. Where 30% have the condition, a positive result means 0.8360.836.

The test did not change; the people did. That is why screening programmes aim tests at high-risk groups, and why a positive screening result is usually followed by a second, different test.

Figure 3 · The rarer the condition, the less a positive result means P(D | +) prevalence P(D), % 0 0.25 0.5 0.75 1 0 10 20 30 40 50 1%: P(D | +) = 0.107 10%: 0.569 30%: 0.836 Test with P(+ | condition) = 0.95 and P(+ | no condition) = 0.08, used in groups of different prevalence.
Figure 3 · The rarer the condition, the less a positive result means

A negative result is a different question. P(D∣−)P(D \mid -) uses the paths that end in a negative:

P(−)=1−0.0887=0.9113P(-) = 1 - 0.0887 = 0.9113P(D∩−)=0.01×0.05=0.0005P(D \cap -) = 0.01 \times 0.05 = 0.0005P(D∣−)=0.00050.9113=0.000549 (3 s.f.)P(D \mid -) = \frac{0.0005}{0.9113} = 0.000549 \ \text{(3 s.f.)}

A negative result is very reassuring: about 5 or 6 people in 10 000. Questions often ask for both, then ask you to comment.

A good comment names both numbers: "the test is good at ruling the condition out, since P(D∣−)P(D \mid -) is tiny, but poor at ruling it in, since P(D∣+)P(D \mid +) is only 0.1070.107."

4Updating twice: a second positive test

Suppose the person who tested positive takes the same test again and is positive again. The starting point is now 0.1070.107, not 1%: what you know after the first test. Apply the theorem again with that as the prior.

The question will state the assumption: the two results are independent for a person of known status.

P(D)=0.10710 (new prior, kept to 5 s.f.)P(D) = 0.10710 \ \text{(new prior, kept to 5 s.f.)}P(D∣second +)=0.10710×0.950.10710×0.95+0.89290×0.08=0.101750.10175+0.07143=0.101750.17318=0.588 (3 s.f.)\begin{aligned}P(D \mid \text{second } +) &= \frac{0.10710 \times 0.95}{0.10710 \times 0.95 + 0.89290 \times 0.08} \\[6pt] &= \frac{0.10175}{0.10175 + 0.07143} \\[6pt] &= \frac{0.10175}{0.17318} \\[6pt] &= 0.588 \ \text{(3 s.f.)}\end{aligned}

Figure 4 shows the three stages. One positive raised 0.010.01 to 0.1070.107. A second raised it to 0.5880.588.

You get the same 0.5880.588 in one step by treating "positive twice" as the evidence. Then P(++∣D)=0.952=0.9025P(++ \mid D) = 0.95^{2} = 0.9025 and P(++∣D′)=0.082=0.0064P(++ \mid D') = 0.08^{2} = 0.0064, so P(D∣++)=0.0090250.009025+0.99×0.0064=0.588P(D \mid ++) = \dfrac{0.009025}{0.009025 + 0.99 \times 0.0064} = 0.588. Two routes, one answer: a good check.

Figure 4 · Each positive result updates the probability before testing 0.01 after one positive 0.107 after two positives 0.588 0 0.25 0.5 0.75 1 probability of having the condition The answer after the first test becomes the starting probability for the second.
Figure 4 · Each positive result updates the probability

5Bayes' theorem with three events

The guide asks for Bayes' theorem "for a maximum of three events". The possible causes are split into three: B1B_{1}, B2B_{2} and B3B_{3}.

  • They are mutually exclusive: only one can happen.
  • They are exhaustive: one of them must happen. So P(B1)+P(B2)+P(B3)=1P(B_{1}) + P(B_{2}) + P(B_{3}) = 1.

The theorem keeps its shape: one path on top, every path to AA underneath.

The denominator comes from the same argument as before. B1B_{1}, B2B_{2} and B3B_{3} partition the sample space, so AA can only happen together with exactly one of them:

P(A)=P(A∩B1)+P(A∩B2)+P(A∩B3)=P(B1)P(A∣B1)+P(B2)P(A∣B2)+P(B3)P(A∣B3)\begin{aligned}P(A) &= P(A \cap B_{1}) + P(A \cap B_{2}) + P(A \cap B_{3}) \\[6pt] &= P(B_{1})P(A \mid B_{1}) + P(B_{2})P(A \mid B_{2}) + P(B_{3})P(A \mid B_{3})\end{aligned}

Putting this under P(Bi∩A)=P(Bi)P(A∣Bi)P(B_{i} \cap A) = P(B_{i})P(A \mid B_{i}) gives the theorem:

P(Bi∣A)=P(Bi)P(A∣Bi)P(B1)P(A∣B1)+P(B2)P(A∣B2)+P(B3)P(A∣B3)P(B_{i} \mid A) = \dfrac{P(B_{i})P(A \mid B_{i})}{P(B_{1})P(A \mid B_{1}) + P(B_{2})P(A \mid B_{2}) + P(B_{3})P(A \mid B_{3})} for i=1,2,3i = 1, 2, 3 · from the formula booklet.

Example: a courier company sorts parcels at three centres. 45% go through the north centre (NN), 35% through central (CC) and 20% through south (SS). The probability that a parcel is damaged (DD) is 0.020.02 at NN, 0.040.04 at CC and 0.050.05 at SS.

A customer receives a damaged parcel. Which centre most probably handled it? Figure 5 draws the tree with the three products.

Figure 5 · Three sorting centres: the tree for Bayes with three events 0.45 N 0.35 C 0.20 S 0.02 D 0.45 × 0.02 = 0.009 0.98 D′ 0.04 D 0.35 × 0.04 = 0.014 0.96 D′ 0.05 D 0.20 × 0.05 = 0.010 0.95 D′ N, C, S: north, central, south centre D: the parcel is damaged P(S | D) = 0.010 ÷ 0.033 = 10/33 ≈ 0.303 P(D) = 0.009 + 0.014 + 0.010 = 0.033. Given damage, each centre's share is its own path over 0.033.
Figure 5 · Three sorting centres: the tree for Bayes with three events
P(D)=0.45×0.02+0.35×0.04+0.20×0.05=0.009+0.014+0.010=0.033\begin{aligned}P(D) &= 0.45 \times 0.02 + 0.35 \times 0.04 + 0.20 \times 0.05 \\[6pt] &= 0.009 + 0.014 + 0.010 = 0.033\end{aligned}P(N∣D)=0.0090.033=311≈0.273P(N \mid D) = \frac{0.009}{0.033} = \frac{3}{11} \approx 0.273P(C∣D)=0.0140.033=1433≈0.424P(C \mid D) = \frac{0.014}{0.033} = \frac{14}{33} \approx 0.424P(S∣D)=0.0100.033=1033≈0.303P(S \mid D) = \frac{0.010}{0.033} = \frac{10}{33} \approx 0.303check: 933+1433+1033=1\text{check: } \frac{9}{33} + \frac{14}{33} + \frac{10}{33} = 1

Central is the most probable source (0.4240.424), even though south has the worst damage rate. South handles too few parcels, and north's low damage rate keeps its share down despite its traffic.

Bayes' theorem weighs both at once: how common each cause is, and how likely each is to produce the evidence.

Always check that the posteriors add to 1. Given the evidence, exactly one cause happened. The check takes ten seconds and catches a wrong denominator.

Conditioning on the complement

  • "Given that a parcel arrived undamaged, find the probability that it went through the north centre" uses the D′D' branches. P(D′)=1−0.033=0.967P(D') = 1 - 0.033 = 0.967, and P(N∣D′)=0.45×0.980.967=0.4410.967=0.456P(N \mid D') = \dfrac{0.45 \times 0.98}{0.967} = \dfrac{0.441}{0.967} = 0.456 (3 s.f.).
  • An undamaged parcel is slightly more likely than average to have come through NN (0.4560.456 against 0.450.45), because NN rarely damages anything.

6Paper 1 fractions and Paper 2 normal models

No calculator

  • Numbers are chosen so that fractions work, but only if you organise them.
  • Example: Ravi travels to the climbing hall by tram with probability 14\tfrac{1}{4}, by bike with probability 12\tfrac{1}{2} and on foot with probability 14\tfrac{1}{4}. He arrives late with probability 16\tfrac{1}{6} by tram, 18\tfrac{1}{8} by bike and 13\tfrac{1}{3} on foot. Tonight he is late. Find the probability that he cycled.
P(L)=14×16+12×18+14×13=124+116+112=248+348+448=948=316\begin{aligned}P(L) &= \frac{1}{4} \times \frac{1}{6} + \frac{1}{2} \times \frac{1}{8} + \frac{1}{4} \times \frac{1}{3} \\[6pt] &= \frac{1}{24} + \frac{1}{16} + \frac{1}{12} \\[6pt] &= \frac{2}{48} + \frac{3}{48} + \frac{4}{48} = \frac{9}{48} = \frac{3}{16}\end{aligned}P(bike∣L)=116316=13P(\text{bike} \mid L) = \frac{\frac{1}{16}}{\frac{3}{16}} = \frac{1}{3}

The other two are P(tram∣L)=1/243/16=29P(\text{tram} \mid L) = \dfrac{1/24}{3/16} = \dfrac{2}{9} and P(foot∣L)=1/123/16=49P(\text{foot} \mid L) = \dfrac{1/12}{3/16} = \dfrac{4}{9}. With 39\tfrac{3}{9} for the bike they sum to 1.

Put the three products over a common denominator before you add. Dividing by a sum of unlike fractions is where Paper 1 answers go wrong. Walking is the likeliest explanation of lateness, though Ravi cycles twice as often as he walks.

Likelihoods from a normal model

  • Sometimes P(A∣B)P(A \mid B) is not given but must be found from a distribution.
  • Example: a packing line has two machines. Machine 1 fills 55% of the jars, with masses normal, mean 250 g, standard deviation 3 g. Machine 2 fills the rest: normal, mean 256 g, standard deviation 3 g.
  • A jar weighs less than 250 g. Find the probability that machine 1 filled it.
  • Let WW be "mass under 250 g".
    • For machine 1, 250 is the mean, so P(W∣1)=0.5P(W \mid 1) = 0.5.
    • For machine 2, 250 is two standard deviations below the mean, so P(W∣2)=P(Z<−2)=0.02275P(W \mid 2) = P(Z < -2) = 0.02275.
P(1∣W)=0.55×0.50.55×0.5+0.45×0.02275=0.2750.2852375=0.964 (3 s.f.)\begin{aligned}P(1 \mid W) &= \frac{0.55 \times 0.5}{0.55 \times 0.5 + 0.45 \times 0.02275} \\[6pt] &= \frac{0.275}{0.2852375} = 0.964 \ \text{(3 s.f.)}\end{aligned}

On Paper 1 the normal facts are handed to you (a value at the mean gives 0.50.5, or a probability is quoted). On Paper 2 you find each likelihood on the calculator. Either way they feed the tree, and Bayes' theorem reads it backwards.

7When the evidence tells you nothing, and working backwards

The guide links this subtopic to independent events. Suppose the evidence AA is equally likely whatever the cause: P(A∣B)=P(A∣B′)=qP(A \mid B) = P(A \mid B') = q. Then

P(B∣A)=P(B) qP(B) q+P(B′) q=P(B) qq(P(B)+P(B′))=P(B) qq=P(B)since P(B)+P(B′)=1\begin{aligned}P(B \mid A) &= \frac{P(B)\,q}{P(B)\,q + P(B')\,q} \\[6pt] &= \frac{P(B)\,q}{q\left(P(B) + P(B')\right)} \\[6pt] &= \frac{P(B)\,q}{q} = P(B) && \textcolor{#838c91}{\text{since }P(B) + P(B') = 1}\end{aligned}

The posterior equals the prior. Seeing AA does not change the probability of BB at all. That is exactly the definition of independence from 4.11, P(B∣A)=P(B)P(B \mid A) = P(B).

A test that is positive 20% of the time whether or not you have the condition is useless, and Bayes' theorem says so. The further apart P(A∣B)P(A \mid B) and P(A∣B′)P(A \mid B') are, the more the evidence moves the probability.

Working backwards

  • Because the theorem is an equation, a question can give the posterior and hide something else.
  • Example: a factory sensor raises an alarm for 90% of real faults. Faults occur in 20% of the machines monitored. For a machine with no fault, the alarm sounds with probability xx. Given an alarm, the probability of a real fault is 0.750.75. Find xx.
0.2×0.90.2×0.9+0.8x=0.75\frac{0.2 \times 0.9}{0.2 \times 0.9 + 0.8x} = 0.750.18=0.75(0.18+0.8x)multiply through; the denominator is positive0.18 = 0.75(0.18 + 0.8x) \qquad \textcolor{#838c91}{\text{multiply through; the denominator is positive}}0.18=0.135+0.6x0.18 = 0.135 + 0.6xx=0.075x = 0.075

Check by substituting back: 0.180.18+0.06=0.75\dfrac{0.18}{0.18 + 0.06} = 0.75.

When the condition is an inequality, the answer is a bound. For the screening test of section 3, a positive result means at least a 50% chance of the condition only if

0.00950.0095+0.99x≥0.5\frac{0.0095}{0.0095 + 0.99x} \ge 0.50.00475≥0.495xthe denominator is positive, so multiply through0.00475 \ge 0.495x \qquad \textcolor{#838c91}{\text{the denominator is positive, so multiply through}}x≤0.00960 (3 s.f.)x \le 0.00960 \ \text{(3 s.f.)}

The false-positive rate would have to fall from 8% to under about 0.96%. For a rare condition, one positive means little unless the false-positive rate is very low.

Practice questions

10 questions on this note, from easy to hard. Each one you get right lights a star of this topic's constellation.