An inspection system raises an alert for 90 percent of faulty items. If an item triggers an alert, is it faulty with probability ? In general it is not, because that rate conditions on the fault while the question conditions on the alert, and the answer also depends on how common faults are before any alert. This lesson derives Bayes’ theorem from the definition of conditional probability and the law of total probability, and uses it to combine a prior probability with the likelihoods of the evidence into a posterior probability. All rates on this page are constructed for illustration.
Key terms
Bayes’ theorem
Definition Let and be events with and . Then
The proof uses the definition of conditional probability twice, since and both equal . If also , the law of total probability over the partition , gives the denominator
More generally, if partition and every , then , and the same formula gives each . The requirement cannot be dropped, because the calculation conditions on .
In plain words To find how probable is once is known, take the probability that and happen together and divide it by the total probability of , counting every way that can happen. Bayes’ theorem builds that joint probability from the prior and the likelihood, which are often the numbers a model actually provides.
Example Let be the event that an item is faulty and the event that it triggers an alert, with , and . True alerts contribute and false alerts contribute , so and
about . An imagined group of 10,000 items with exactly these proportions shows the same calculation as counts.
| Alert | No alert | Total | |
|---|---|---|---|
| Faulty | 180 | 20 | 200 |
| Sound | 490 | 9,310 | 9,800 |
| Total | 670 | 9,330 | 10,000 |
The alert column holds 670 items, of which 180 are faulty, and . These counts are the model’s probabilities written as frequencies, not measured results, and a random batch of 10,000 items would generally show somewhat different counts.
Prior and posterior probability
Definition In a Bayes calculation for a hypothesis and evidence , the prior probability is , the probability of before is taken into account. The posterior probability is , the probability of after conditioning on , which requires . Both are probabilities of the same event in the same model, and they differ only in the information they condition on. When the prior describes how common the hypothesis is in the relevant population, it is also called the base rate.
In plain words The prior is the starting point, and the posterior is where the evidence moves it. The names describe roles in one calculation, not two different kinds of probability.
Example In the alert model the prior fault probability is , and after an alert the posterior is . No alert has probability given a fault, so , while . Hence
about . In the table this is , the faulty share of the whole no-alert column. The two posteriors average back to the prior when weighted by the probabilities of the evidence, since , as the law of total probability requires.
Likelihood
Definition For a hypothesis with and an observed event , the likelihood of under is the conditional probability . It conditions on the hypothesis, the opposite direction from the posterior . When also , Bayes’ theorem shows that the two are equal exactly when or , so in general they differ. The likelihoods of one piece of evidence under competing hypotheses, such as and , condition on different events, so they need not add to .
In plain words A likelihood asks how expected the evidence is if the hypothesis is true. A likelihood alone is not a posterior, because it leaves out how probable the hypothesis was to begin with and how expected the evidence is under the alternatives.
Example In the alert model the likelihood of an alert is under a fault and under a sound item, and these add to , not . Their ratio says that an alert is 18 times as likely for a faulty item as for a sound one. This ratio gives a quick form of the update in odds. The prior odds of a fault are to , or to , and multiplying by gives posterior odds of to , which is the probability again. Multiplying the odds by 18 did not multiply the probability by 18, which would have given instead of about . The lesson Probability and Odds develops this form.
Sensitivity and specificity
Definition Let be the event that the condition being tested for is present, with , and let be the event of a positive result, here an alert. The sensitivity, or true positive rate, is . Its complement is the false negative rate. The specificity, or true negative rate, is , and its complement is the false positive rate. All of these rates condition on the true state, so none of them is a posterior probability of the condition.
In plain words Sensitivity asks how often the test catches the condition when it is present. Specificity asks how often the test stays negative when the condition is absent. Each looks at one true state at a time.
Example In the alert model the sensitivity is , so the false negative rate is , and the specificity is . Sensitivity is not the probability of a fault after an alert, which is . Likewise a false negative rate of does not make the fault probability after no alert equal to . That posterior is , the faulty share of all 9,330 no-alert items in the table, not a share of the faulty items.
False positive rate
Definition The false positive rate of a test is , the probability of a positive result for an item without the condition, which requires . It equals minus the specificity. It is different from the proportion of positive results that are false, which is the posterior probability and requires . By Bayes’ theorem that proportion depends on the base rate as well as on the test.
In plain words The false positive rate looks only at items without the condition and asks how often they set off the test. The share of false alarms looks only at alarms and asks how many of them come from such items.
Example In the alert model the false positive rate is , yet among alerts the share from sound items is
about . In the table, 490 of the 9,800 sound items raise an alert, which is 5 percent, while 490 of the 670 alerts, about 73 percent, come from sound items. Sound items outnumber faulty ones 49 to 1, while the alert rate for faulty items is only 18 times the rate for sound ones, so here the small rate applied to the large group produces more alerts than the large rate applied to the small group.
Base rate neglect
Definition Base rate neglect is the error of judging a posterior probability from the likelihoods alone while ignoring or underweighting the prior probability , the base rate of the hypothesis in the relevant population. A common form is to report a likelihood such as the sensitivity as if it were . Bayes’ theorem shows that when the likelihoods and are held fixed and both are positive, the posterior increases strictly as the prior increases, so the same evidence can support very different conclusions in different populations.
In plain words Unless the evidence rules the hypothesis in or out completely, how probable the hypothesis is after the evidence depends on how common it was before the evidence arrived, not only on the evidence. When the hypothesis is rare, even a small false positive rate applied to the many cases where it is false can produce more false alarms than true ones.
Example Keep the alert rates and , but suppose the items come from a population in which 20 percent are faulty. True alerts contribute and false alerts , so
about . With the prior the same alert gave only . The alert system did not change. The mix of faulty and sound items changed, and with it the makeup of the alert group. The prior and the likelihoods must describe the population and selection process the item actually comes from, or the calculation is precise but answers a different question.
Check yourself
- In another constructed system, 10 percent of items are faulty. An alert occurs for 80 percent of faulty items and for 20 percent of sound items. Find the probability that an item with an alert is faulty, and say how much of the alert probability comes from false alerts. Why is the answer neither nor ?
Show the answer
True alerts contribute and false alerts contribute , so and
about . False alerts supply of the , more than two thirds of the alert probability. The number is the likelihood , which conditions in the wrong direction. The number is the joint probability , which has not yet been divided by the probability of an alert. The alert raises the fault probability from to about because alerts are four times as likely under a fault, but the larger sound group still supplies most of the alerts.
- A screening test for a condition with prevalence has sensitivity and specificity . These rates are illustrative. Find the probability of the condition after a positive result and after a negative result.
Show the answer
Let be the event that a person has the condition and the event of a positive result. The false positive rate is and the false negative rate is . In an imagined group of 2,000 people with exactly these proportions, 100 have the condition and 95 of them test positive, while 1,900 do not and 190 of them test positive. So
The formula agrees. True positives contribute and false positives , so and . Among negative results, 5 come from people with the condition and 1,710 from people without it, so
about . A positive result raises the probability from to , yet two of every three positive results are false. A negative result lowers it to well under 1 percent.
- Return to the first alert model, with prior , sensitivity and false positive rate . Which change raises more, a perfect sensitivity of or a false positive rate of ? Explain the result with base rates.
Show the answer
With sensitivity , true alerts contribute and false alerts still contribute , so
With false positive rate , true alerts contribute and false alerts , so
The lower false positive rate helps far more. Faults are rare, so most alerts come from the large sound group. Perfect sensitivity can add at most to the true-alert term, while the lower false positive rate cuts the false-alert term from to .