This HTML version of is provided for convenience, but it is not the best format for the book. In particular, some of the symbols are not rendered correctly.
You might prefer to read the PDF version.
Chapter 1 Bayes’s Theorem
1.1 Conditional probability
The fundamental idea behind all Bayesian statistics is Bayes’s Theorem, which is surprisingly easy to derive, provided that you understand conditional probability. So we’ll start with probability, then conditional probability, then Bayes’s Theorem, and on to Bayesian statistics.
A probability is a number between 0 and 1 (including both) that represents a degree of belief in a fact or prediction. A probability of 1 represents certainty that a fact is true, or that a prediction will come true. A probability of 0 represents equal certainty that the fact is false.
Intermediate values represent degrees of certainty. The value 0.5, often represented as 50%, means that a predicted outcome is as likely to happen as not. For example, the probability that a tossed coin lands face up is very close to 50%.
A conditional probability is a probability based on some background information. For example, I might be interested in the probability that I will have a heart attack in the next year. According to the CDC, “Every year about 785,000 Americans have a first coronary attack. (http://www.cdc.gov/heartdisease/facts.htm)”
The U.S. population is about 311 million, so the probability that a randomly-chosen American will have a heart attack in the next year is roughly 0.3%.
But I am not a randomly-chosen American. Epidemiologists have identified many factors affect the risk of heart attacks; depending on those factors, my risk might be higher or lower than average.
I am male, 45 years old, and I have borderline high cholesterol. Those factors increase my chances. However, I have low blood pressure and I don’t smoke, and those factors decrease my chances.
Plugging everything into the online calculator at http://hp2010.nhlbihin.net/atpiii/calculator.asp, I find that my risk of a heart attack in the next year is about 0.2%, less than the national average. That value is a conditional probability, because it is based on a number of factors that make up my “condition.”
The usual notation for conditional probability is p(A|B), which is the probability of A given that B is true. In this example, A represents the prediction that I will have a heart attack in the next year, and B is the set of conditions I listed.
1.2 Conjoint probability
“Conjoint probability” is a fancy way to say the probability that two things are true. I will write p(A and B) to mean the probability that A and B are both true.
If you learned about probability in the context of coin tosses and dice, you might have learned the formula
For example, if I toss two coins, and A means the first coin lands face up, and B means the second coin lands face up, then p(A) = p(B) = 0.5, and sure enough, p(A and B) = p(A) p(B) = 0.25.
But this formula only works because in this case A and B are independent; that is, the second event does not depend on the first. If you tell me the first coin is heads, that does not change p(B).
Here is a different example where the events are not independent. Suppose again that A means the first coin lands face up, but let’s add C, which means that both coins land face up. What is the probability of both events, p(A and C)?
These events are dependent because if we know whether or not A is true, that changes p(C). Specifically, if A is true then p(C) = 0.5; but if A is false p(C) = 0.
To be more correct, I should not say that p(C) changes, but rather that the conditional probabilities are different: p(C|A) = 0.5 and p(C| not A) = 0.
In general, the probability of a conjunction is
for any A and C. In this example, p(A and C) = (0.5)(0.5) = 0.25.
1.3 The Cookie Problem
We’ll get to Bayes’s Theorem soon, but I want to motivate it with an example called The Cookie Problem1. Suppose there are two bowls of cookies. Bowl 1 contains 30 vanilla cookies and 10 chocolate cookies. Bowl 2 contains 20 of each.
Now suppose you choose one of the bowls at random and, without looking, select a cookie at random. The cookie is vanilla. What is the probability that it came from Bowl 1?
This is a conditional probability; we want p(Bowl 1 | vanilla), but it is not obvious how to compute it. If I asked a different question—the probability of a vanilla cookie given Bowl 1—it would be easy: p(vanilla | Bowl 1) = 3/4 Unfortunately, p(A|B) is not the same as p(B|A). But there is a way to get from one to the other: Bayes’s Theorem.
1.4 Bayes’s Theorem
At this point we have everything we need to derive Bayes’s Theorem. We’ll start with the observation that conjunction is commutative; that is
for any events A and B.
Next, we write the probability of a conjunction:
Since we have not said anything about what A and B mean, they are interchangeable. Interchanging them yields
And that’s all we need. Pulling those pieces together, we get
Which means there are two ways to compute the conjunction. If you have p(A), you multiply by the conditional probability p(B|A). Or you can do it the other way around; if you know p(B), you multiply by p(A|B). Either way you should get the same thing.
Finally we can divide through by p(B)
And that’s Bayes’s Theorem! It doesn’t look like much, but it is a surprisingly powerful idea.
For example, we can use it to solve the Cookie Problem. I’ll write B1 for the hypothesis that the cookie came from Bowl 1 and V for the vanilla cookie. Plugging in Bayes’s Theorem we get
The term on the left is what we want: the probability of Bowl 1, given that we chose a vanilla cookie. The terms on the right are:
Putting it together, we have
which reduces to 3/5. So the vanilla cookie is evidence in favor of the hypothesis that we chose Bowl 1, because vanilla cookies are more likely to come from Bowl 1.
This example demonstrates one use of Bayes’s Theorem: it provides a process to get from p(B|A) to p(A|B). This strategy is useful in cases, like the Cookie Problem, where it is easier to compute the terms on the right side of Bayes’s Theorem than the term on the left.
1.5 The diachronic interpretation
There is another way to think of Bayes’s Theorem: it gives us a way to update the probability of a hypothesis, H, in light of some body of data, D.
This way of thinking about Bayes’s Theorem is called the diachronic interpretation. “Diachronic” means that something is happening over time; in this case there is an implicit notion that the probability of the hypotheses changes, over time, as we see new data.
Rewriting Bayes’s Theorem with H and D yields:
In this interpretation, each term has a name:
In some cases, we can compute the prior based on background information. For example, the Cookie Problem specifies that we choose a bowl at random with equal probability.
In other cases the prior is subjective; that is, reasonable people might disagree, either because they use different background information or because they interpret the same information differently.
The likelihood is usually the easiest part to compute. In the Cookie Problem, if we know which bowl the cookie came from, we can get the probability of getting a vanilla cookie by counting.
The normalizing constant can be tricky. It is supposed to be the probability of seeing the data under any hypothesis at all, but in the most general case it is hard to see what that means.
Most often we simplify things by specifying a set of hypotheses that are
I use the word suite for a set of hypotheses that has these properties.
In the Cookie Problem, there are only two hypotheses—the cookie came from Bowl 1 or Bowl 2—and they are mutually exclusive and collectively exhaustive.
In that case we can compute p(D) using the law of total probability, which says that if there are two exclusive ways that something might happen, you can add up the probabilities like this:
Plugging in the values from the Cookie Problem, we have
which is what we computed earlier by mentally combining the two bowls.
1.6 The M&M Problem
M&M’s are small candy-coated chocolates that come in a variety of colors. Mars, Inc., which makes M&M’s, changes the mixture of colors from time to time.
In 1995, they introduced blue M&M’s. Before then, the color mix in a bag of plain M&Ms was (30% Brown, 20% Yellow, 20% Red, 10% Green, 10% Orange, 10% Tan). Afterward it was (24% Blue , 20% Green, 16% Orange, 14% Yellow, 13% Red, 13% Brown).
Suppose a friend of mine has two bags of M&M’s, and he tells me that one is from 1994 and one from 1996. He won’t tell me which is which, but he gives me one M&M from each bag. One is yellow and one is green. What is the probability that the yellow one came from the 1994 bag?
This problem is similar to the Cookie Problem, with the twist that I draw one sample from each bowl/bag. This problem also gives me a chance to demonstrate the table method, which is useful for solving problems like this on paper. In the next chapter we will solve them computationally.
The first step is to enumerate the hypotheses. The bag the yellow M&Mcame from I’ll call Bag 1; I’ll call the other Bag 2. So the hypotheses are:
Now we construct a table with a row for each hypothesis and a column for each term in Bayes’s Theorem:
The first column has the priors. Since there is one bag from 1994 and one from 1996, it is reasonable to choose p(A) = p(B) = 1/2.
The second column has the likelihoods, which follow from the information in the problem. If A is true, the yellow M&M came from the 1994 bag with probability 20%, and the green came from the 1996 bag with probability 20%. Because the selections are independent, we get the conjoint probability by multiplying.
The third column is just the product of the previous two. The sum of this column, 270, is the normalizing constant. To get the last column, which contains the posteriors, we divide the third column by the normalizing constant.
That’s it. Simple, right?
Well, you might be bothered by one detail. I wrote p(D|H) in terms of percentages, not probabilities, which means it is off by a factor of 10,000. But that cancels out when we divide through by the normalizing factor, so it doesn’t affect the result.
When the set of hypotheses is mutually exclusive and collectively exhaustive, you can multiply the likelihoods by any factor, if it is convenient, as long as you apply the same factor to the entire column.
1.7 The Monty Hall problem
The Monty Hall problem might be the most contentious question in the history of probability. The scenario is simple, but the correct answer is so counter-intuitive that many people just can’t accept it, and many smart people have embarrassed themselves not just by getting it wrong but by arguing the wrong side, aggressively, in public.
Monty Hall was the original host of the game show Let’s Make a Deal. The Monty Hall problem is based on one of the regular games on the show. If you are on the show, here’s what happens:
Most people have the strong intuition that it makes no difference. There are two doors left, they reason, so the chance that the car is behind Door A is 50%.
But that is wrong. In fact, the chance of winning if you stick with Door A is only 1/3; if you switch, your chances are 2/3.
By applying Bayes’s Theorem, we can break this problem into simple pieces, and maybe convince ourselves that the correct answer is, in fact, correct.
To start, we should make a careful statement of the data. In this case D consists of two parts: Monty chooses Door B, and there is no car there.
Next we define three hypotheses: A, B and C represent the hypothesis that the car is behind Door A, Door B or Door C. Again, let’s apply the table method:
Filling in the priors is easy because we are told that the prizes are arranged at random, which implies that the car is equally likely to be behind any door.
Figuring out the likelihoods takes some thought, but with reasonable care we can be confident that we have it right:
Now the hard part is over; the rest is just arithmetic. The sum of the third column is 1/2. Dividing through yields p(A|D) = 1/3 and p(C|D) = 2/3. So you are better off switching.
There are many variations of the Monty Hall problem. One of the strengths of the Bayesian approach is that it generalizes to handle these variations.
For example, suppose that Monty always chooses B if he can, and only chooses C if he has to (because the car is behind B). In that case the revised table is:
The only change is p(D|A). If the car is behind A, Monty can choose to open B or C. But in this variation he always chooses B, so p(D|A) = 1.
As a result, the likelihoods are the same for A and C, and the posteriors are the same: p(A|D) = p(C|D) = 1/2. In this case, the fact that Monty chose B reveals no information about the location of the car, so it doesn’t matter whether the contestant sticks or switches.
On the other hand, if he had opened C, we would know p(B|D) = 1.
Are you using one of our books in a class?We'd like to know about it. Please consider filling out this short survey.