A packing machine runs at a low or a high setting, and its display has failed. At the low setting a packet comes out marked with probability , and at the high setting with probability . One packet is inspected and it is marked. Either setting could have produced it, so the packet does not prove which setting is in use, yet it makes the high setting more plausible than before. This lesson measures that change by multiplying starting probabilities by likelihoods and rescaling, and then writes the same update in terms of odds. The machine and its rates are a constructed teaching model.
Key terms
Prior distribution
Definition Suppose a model allows a finite list of hypotheses , exactly one of which is true within the model, and each hypothesis fixes a probability model for the data, for example by fixing the value of an unknown parameter. A prior distribution assigns each hypothesis a probability before the data at hand are used, with
The prior is a stated input of the analysis. It may come from earlier evidence, from knowledge of the process or from a deliberate convention such as equal weights, and its basis should be reported with the result.
In plain words The prior records how plausible each candidate is before the new observation is taken into account. It only spreads probability over the hypotheses the model lists. A hypothesis that is left off the list, or given prior probability , gets posterior probability whatever data arrive, so an exclusion of that kind should be made on purpose.
Example In the machine model the unknown quantity is the marking rate , and the two hypotheses are for the low setting and for the high setting. Equal weights give the prior . If maintenance records showed that the machine usually runs at the low setting, a prior of for and for might be better supported. Either way it is an assumption made before the packet is inspected.
Posterior distribution
Definition Let be the observed data. The likelihood of a hypothesis in the list is , the probability that gives to the data actually observed, read as a function of the hypothesis while the data stay fixed. Provided the normalizing constant of the next card is positive, the posterior distribution assigns each hypothesis in the list the probability
This is Bayes’ theorem applied to each hypothesis. For continuous data the probabilities of the data are replaced by densities. The posterior probabilities are nonnegative and add to , and they are conditional on the model, the prior and the data together.
In plain words The posterior reweights the prior by how well each hypothesis predicted what was actually seen. A hypothesis that made the data more probable gains weight relative to one that made them less probable. The likelihood and the posterior condition in opposite directions, so a likelihood of does not mean a posterior probability of . The posterior is also not the observed frequency. One marked packet out of one is a frequency of , but no hypothesis in this model has , and the posterior can only spread probability over and .
Example Write for the event that the inspected packet is marked. With equal priors the products of prior and likelihood are for and for . Dividing each product by their sum gives the posterior probability of the high setting,
and the posterior probability of the low setting. Given the two-setting model, the equal prior and one marked packet, the high setting has posterior probability .
Normalizing constant
Definition The normalizing constant of the update is the total probability of the observed data under the model,
with the sum running over the hypotheses in the list, by the law of total probability. It is the probability the model, prior included, gave to the data before they were observed, and it is also called the marginal likelihood or the evidence. It is the same number for every hypothesis, so the posterior is often written , where means equal up to a positive factor that is the same for every hypothesis. The update needs . If every hypothesis with positive prior probability gives the observed data probability , the update is not defined, and the model itself needs another look.
In plain words The products of prior and likelihood already stand in the right ratios to one another. They just do not add to . Dividing every product by their total fixes the scale without changing any ratio.
Example With equal priors the constant for a marked packet is . Before inspection the model said a packet would be marked with probability . The likelihoods and add to rather than , and nothing is wrong with that, because they are probabilities of one observation under two different hypotheses, not probabilities of different outcomes under one hypothesis. With the prior and the products become and , and the constant changes to .
Bayesian updating
Definition Bayesian updating is the passage from a prior distribution to a posterior distribution by conditioning on observed data within a stated model. With finitely many hypotheses it has three steps. Multiply each prior probability by the likelihood of the data under that hypothesis, add the products, and divide each product by the sum. When data arrive in two parts and then , the posterior after serves as the prior for , and the likelihood for the second step is . If the two parts are conditionally independent given each hypothesis, that likelihood is simply . Updating in two steps then gives the same posterior as one update with the likelihood of both parts together, provided each observation is used exactly once.
In plain words The posterior from today becomes the prior for tomorrow. Each new observation shifts probability toward the hypotheses that predicted it better than the prior average and away from those that predicted it worse, which can mean away from the current favorite. Updating means following the evidence in whichever direction it points, not growing more certain of whatever led after the first observation.
Example Packets are assumed independent given the setting. After the marked packet the probabilities are and . A second packet is unmarked, which has probability when and when . The products are and , with sum , so the posterior is for and for . The unmarked packet lowered the probability of the high setting, though it is still ahead. Updating once on both packets from the equal prior gives the likelihoods and , products and , sum , and again and .
Prior odds and posterior odds
Definition For two hypotheses and with , the prior odds of against are . After data with , the posterior odds of against are . Odds can be any number from upward. The odds of against are the reciprocal, when . If and are the only hypotheses in the model, odds correspond to the probability
and the same conversion turns posterior odds into a posterior probability. With more hypotheses in the model, the number is the probability of given that one of the two is true.
In plain words Odds compare two hypotheses directly and leave the others aside. They are a ratio, not a probability, so odds of are perfectly possible while a probability of is not. Keep the direction fixed, saying which hypothesis is on top, throughout a calculation.
Example With equal priors the prior odds of against are . After the marked packet the posterior odds are , and since the model has only these two hypotheses, the posterior probability of is . The posterior odds of against are .
Bayes factor
Definition For hypotheses and and data with , the Bayes factor in favor of against is
If , Bayes’ theorem gives
because the normalizing constant cancels from the ratio. In words, posterior odds equal prior odds times the Bayes factor. The Bayes factor of against is when . For a simple hypothesis, one that fixes every parameter, is an ordinary likelihood value. For a composite hypothesis that allows a range of parameter values, is the likelihood averaged over a prior for the parameter within that hypothesis, so the Bayes factor then depends on that prior too.
In plain words The Bayes factor is the part of the update that comes from the data. It says how many times as probable the observed data are under one hypothesis as under the other, and it does not depend on the prior odds of the two hypotheses. For two simple hypotheses no prior enters it at all. It is not the odds that one hypothesis is true. Those also need the prior odds, and a strong prior can outweigh a moderate Bayes factor.
Example For a marked packet the Bayes factor of against is , and for an unmarked packet it is . Now take the prior for and for , so the prior odds of against are . After one marked packet the posterior odds are , and
The direct calculation agrees, since . The data favor the high setting by a factor of , yet the low setting remains more probable, because it started four times as probable.
Check yourself
- In the machine model, suppose the prior is for and for , and one inspected packet is unmarked. Find the posterior probability of , then check it with the Bayes factor and odds.
Show the answer
Write for the event that the packet is unmarked. It has probability when and when . The products are and , and the normalizing constant is . So
With odds, the Bayes factor of against is and the prior odds are , so the posterior odds are . Converting gives again. The unmarked packet lowered the probability of the high setting from , as it should, because that observation is more probable at the low setting.
- Start from equal priors. A marked packet and then an unmarked packet are inspected. A student takes the posterior after the first packet, and , as the new prior, but then multiplies by the likelihood of both packets, and . What does the student get, what is the correct posterior, and what went wrong?
Show the answer
The student’s products are and , so the student reports a posterior probability for of
The correct answer is . Either multiply the prior and by the likelihood of the second packet only, which gives and and then and , or multiply the original equal prior by the likelihood of both packets. The student used the marked packet twice, once inside the new prior and once inside the joint likelihood, which is the same as pretending that two marked packets and one unmarked packet were seen.
- Extend the model to three settings, with , and and prior probabilities , and . One packet is inspected and it is marked. Find the posterior distribution. A colleague notes that the Bayes factor of against is and the prior odds are , and concludes that . Is that right?
Show the answer
The products of prior and likelihood are , and , and their sum is . The posterior probabilities are therefore , and , which add to . The posterior odds of against are indeed , the prior odds times the Bayes factor. The conclusion is wrong, though, because turning odds into the probability assumes the two hypotheses are the only ones. Here is the probability of given that is or . The posterior probability of is , and the most probable setting after the marked packet is .