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 | how many | the dog sits | no sit |
|---|---|---|---|
| bags with fruit | 10 | 9 | 1 |
| bags without fruit | 90 | 18 | 72 |
| all bags | 100 | 27 | 73 |
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.
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 question | count | out of | chance |
|---|---|---|---|
| fruit, of all bags | 10 | 100 | 0.1 |
| a sit, given fruit | 9 | 10 | 0.9 |
| a sit, given no fruit | 18 | 90 | 0.2 |
| fruit, given a sit | 9 | 27 | 0.33 |
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 | how many | the dog sits | no sit |
|---|---|---|---|
| bags with fruit | 10 | 9 | 1 |
| bags without fruit | 90 | 18 | 72 |
| all bags | 100 | 27 | 73 |
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.
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 , 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.
the move: count the sits each way
the line:bags with fruit sits with fruit sits without share 10 9 18 0.33 20 18 16 0.53 50 45 10 0.82 90 81 2 0.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 bags with fruit, and at 2 tenths of the other . The share is the sits with fruit over all the sits. For 10 bags with fruit, that is 9 over 9 + 18.
the move: multiply top and bottom by 10
the line:why it is allowed: Ten times each part clears the tenths. Top and bottom grow alike, so the share is unchanged.
guess it, thenthe move: multiply out the bracket
the line:why it is allowed: 2 times 100 is 200, and 2 times is , which is taken away.
guess it, thenthe move: gather the
the line:why it is allowed: take away is . For 10 bags with fruit that is 90 over 270, a third. For 50 it is 450 over 550, about 0.82.
guess it, then
try it with a small : at , line 1 gives , about 0.33
the move: count the sits each way
the line:why it is allowed: Question 1's first line, the sits with fruit over all the sits.
the move: write each count as a share of its bags
the line:piece with 10 bags of fruit what it is 0.9 the chance of a sit, given fruit 10 bags with fruit 0.2 the chance of a sit, given no fruit 90 bags 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: is 9 tenths of : the chance of a sit given fruit, times the bags with fruit. In the same way, 2 tenths of the other bags get a sit.
guess it, thenthe move: divide top and bottom by 100
the line:why it is allowed: Top and bottom shrink alike, so the share is unchanged. over 100 is the chance of fruit, and 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.
guess it, then
try it with a small : at , line 1 gives , 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?
- The chance an egg is cracked is 8 out of 40, which is 0.2.
- The chance of a line, given a cracked egg, is 6 out of 8, which is 0.75.
- 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.
- 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.
- 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.
| eggs | how many | shows a line | no line |
|---|---|---|---|
| cracked eggs | 8 | 6 | 2 |
| sound eggs | 32 | 4 | 28 |
| all eggs | 40 | 10 | 30 |
10 eggs show a line and 6 of them are cracked, so an egg with a line is cracked about 60% of the time.
the trap
check yourself
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.
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.
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.