Skip to content

chances, and Bayes' rule

learning from examples

what it is

A chance is a count out of a whole. A sniffer dog sits at 9 of every 10 bags with fruit, yet only 9 of the 27 bags it sits at hold fruit. Bayes' rule turns one chance into the other, and squares you can count show why.

A sniffer dog checks bags at an airport for fruit. Take 100 bags, one square each. 10 hold fruit and 90 hold none. The dog is good but not perfect. It sits at 9 of the 10 bags with fruit, and at 18 of the 90 bags without. A dot marks each bag it sits at.

bags with fruitbags without fruitthe dog sits
bagshow manythe dog sitsno sit
bags with fruit1091
bags without fruit901872
all bags1002773

The dog sits at 27 bags and 9 of them hold fruit, so a bag it sits at holds fruit about 33% of the time.

100 bags, one square each. The first 10 hold fruit and the other 90 hold none. A dot marks each bag the dog sits at, 9 of the 10 with fruit and 18 of the 90 without.

A chance is a count out of a whole. Pick a bag without looking. The chance it holds fruit is 10 out of 100, which you can write as 0.1 or as 10%. Books call a chance a probability.

Now ask for a chance inside one group. Among the 10 bags with fruit, the dog sits at 9. So the chance of a sit, given fruit, is 9 out of 10. The whole is no longer the 100 bags. It is the 10 with fruit. Among the 90 bags without, the dog sits at 18, so the chance of a sit, given no fruit, is 18 out of 90, or 2 in 10. Books call a chance inside a group a conditional probability.

Turn the question round. The dog sits at a bag. What is the chance the bag holds fruit? The whole is now the bags the dog sits at, 9 and 18, which is 27. Of those, 9 hold fruit. So the chance of fruit, given a sit, is 9 out of 27, a third.

the questioncountout ofchance
fruit, of all bags101000.1
a sit, given fruit9100.9
a sit, given no fruit18900.2
fruit, given a sit9270.33
Four chances from the same 100 bags, each a count out of its own whole. The last is the second turned round, written to two places.

The chance of a sit given fruit and the chance of fruit given a sit answer different questions. Given fruit, the dog sits 9 times in 10. Given a sit, the bag holds fruit 1 time in 3. The count on top is the same 9. The wholes differ: 10 bags with fruit, but 27 sits. Most sits are wrong ones, because bags without fruit are so many: 2 sits in every 10 of the 90 make 18, twice the 9 sits at fruit.

Bayes' rule is this turning round, done with chances in place of counts. Questions 1 and 2 below work it out one line at a time.

Now move the sliders. Make fruit common, and a sit means fruit nearly every time. Or keep 10 bags of fruit and let the dog sit at every bag of both kinds. Then a sit tells you nothing new: the chance of fruit stays at 10 out of 100.

bags with fruitbags without fruitthe dog sits
bagshow manythe dog sitsno sit
bags with fruit1091
bags without fruit901872
all bags1002773

The dog sits at 27 bags and 9 of them hold fruit, so a bag it sits at holds fruit about 33% of the time.

With scripts on, three sliders set how many bags hold fruit and how often the dog sits at each kind. The squares, the table and this line change with them.

The same 100 bags with all three numbers free to change. How common fruit is matters as much as how good the dog is.

where the formulas come from

Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about nn, or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.

question 1Of 100 bags, nn hold fruit. The dog sits at 9 of every 10 bags with fruit and at 2 of every 10 without. Of the bags it sits at, what share, SS, hold fruit?
  1. the move: count the sits each way

    the line:
    S=9n109n10+2(100−n)10S = \frac{\frac{9n}{10}}{\frac{9n}{10} + \frac{2(100 - n)}{10}}
    bags with fruitsits with fruitsits withoutshare
    109180.33
    2018160.53
    5045100.82
    908120.98
    The sits each way at four counts of bags with fruit, and the share of sits with fruit, to two places. The more common fruit is, the more a sit means fruit.

    why it is allowed: The dog sits at 9 tenths of the nn bags with fruit, and at 2 tenths of the other 100−n100 - n. The share is the sits with fruit over all the sits. For 10 bags with fruit, that is 9 over 9 + 18.

  2. the move: multiply top and bottom by 10

    the line:
    S=9n9n+2(100−n)S = \frac{9n}{9n + 2(100 - n)}

    why it is allowed: Ten times each part clears the tenths. Top and bottom grow alike, so the share is unchanged.

  3. the move: multiply out the bracket

    the line:
    S=9n9n+200−2nS = \frac{9n}{9n + 200 - 2n}

    why it is allowed: 2 times 100 is 200, and 2 times nn is 2n2n, which is taken away.

  4. the move: gather the nn

    the line:
    S=9n7n+200S = \frac{9n}{7n + 200}

    why it is allowed: 9n9n take away 2n2n is 7n7n. For 10 bags with fruit that is 90 over 270, a third. For 50 it is 450 over 550, about 0.82.

try it with a small nn: at n=10n = 10, line 1 gives SS, about 0.33

question 2The same bags, with chances in place of counts. The chance of fruit is n100\frac{n}{100}. Write SS so that every piece is a chance.
  1. the move: count the sits each way

    the line:
    S=9n109n10+2(100−n)10S = \frac{\frac{9n}{10}}{\frac{9n}{10} + \frac{2(100 - n)}{10}}

    why it is allowed: Question 1's first line, the sits with fruit over all the sits.

  2. the move: write each count as a share of its bags

    the line:
    S=910×n910×n+210×(100−n)S = \frac{\frac{9}{10} \times n}{\frac{9}{10} \times n + \frac{2}{10} \times (100 - n)}
    piecewith 10 bags of fruitwhat it is
    910\frac{9}{10}0.9the chance of a sit, given fruit
    nn10bags with fruit
    210\frac{2}{10}0.2the chance of a sit, given no fruit
    100−n100 - n90bags without fruit
    The four pieces of this line with 10 bags of fruit. 0.9 times 10 is the 9 sits with fruit, and 0.2 times 90 is the 18 without.

    why it is allowed: 9n10\frac{9n}{10} is 9 tenths of nn: the chance of a sit given fruit, times the bags with fruit. In the same way, 2 tenths of the other 100−n100 - n bags get a sit.

  3. the move: divide top and bottom by 100

    the line:
    S=910×n100910×n100+210×100−n100S = \frac{\frac{9}{10} \times \frac{n}{100}}{\frac{9}{10} \times \frac{n}{100} + \frac{2}{10} \times \frac{100 - n}{100}}

    why it is allowed: Top and bottom shrink alike, so the share is unchanged. nn over 100 is the chance of fruit, and 100−n100 - n over 100 is the chance of no fruit. So the top is the chance of a sit given fruit, times the chance of fruit. Underneath, the same for no fruit is added to it, which makes the chance of a sit. This is Bayes' rule. For 10 bags with fruit the top is 0.9 times 0.1, which is 0.09: the 9 bags with fruit and a sit, out of 100. Underneath, 0.2 times 0.9 is 0.18, and 0.09 + 0.18 is 0.27, the 27 sits out of 100. 0.09 over 0.27 is a third again.

try it with a small nn: at n=10n = 10, line 1 gives SS, about 0.33

a worked example

A farmer checks 40 eggs. 8 are cracked. Held up to a lamp, 6 of the 8 cracked eggs show a dark line. So do 4 of the 32 sound eggs. An egg shows a line. What is the chance it is cracked?

  1. The chance an egg is cracked is 8 out of 40, which is 0.2.
  2. The chance of a line, given a cracked egg, is 6 out of 8, which is 0.75.
  3. Turn it round. 6 and 4 make 10 eggs with a line, and 6 of them are cracked. The chance of a cracked egg, given a line, is 6 out of 10, which is 0.6.
  4. Check it by Bayes' rule: question 2's last line, with eggs in place of bags. Its top is the chance of a line given a cracked egg, times the chance of a cracked egg. 0.75 times 0.2 is 0.15. That is 6 out of 40, the cracked eggs with a line.
  5. Underneath the top, the same for the sound eggs is added. A sound egg shows a line 4 times in 32, which is 0.125, and 32 eggs in 40 are sound, which is 0.8. 0.125 times 0.8 is 0.1, the 4 sound eggs with a line out of 40. 0.15 + 0.1 is 0.25, and 0.15 over 0.25 is 0.6 again.
cracked eggssound eggsshows a line
eggshow manyshows a lineno line
cracked eggs862
sound eggs32428
all eggs401030

10 eggs show a line and 6 of them are cracked, so an egg with a line is cracked about 60% of the time.

40 eggs, one square each. The first 8 are cracked and the other 32 are sound. A dot marks each egg that shows a line, 6 of the cracked and 4 of the sound.

the trap

check yourself

  1. Of 100 bags, 20 hold fruit. The dog sits at 9 of every 10 bags with fruit and at 2 of every 10 without. It sits at a bag. What is the chance of fruit?

    the answer

    It sits at 18 bags with fruit and at 16 of the 80 without, 34 in all. The chance is 18 out of 34, about 0.53.

  2. A lazy dog sits at every bag. 10 of 100 bags hold fruit. It sits at a bag. What is the chance of fruit?

    the answer

    It sits at all 100 bags, and 10 of them hold fruit. The chance is 10 out of 100, the same as before the sit. A sit that comes every time tells you nothing.

  3. A dog sits at every one of the 10 bags with fruit, and at 18 of the 90 without. Does a sit make fruit certain?

    the answer

    No. It sits at 28 bags and 10 hold fruit, so the chance is 10 out of 28, about 0.36. Finding every bag with fruit is not the same as being right at every sit.