An inspection that catches 90 percent of defective components and flags 5 percent of sound ones has just flagged a component. How likely is it that a flagged component is defective? The two rates alone cannot answer that, because the answer also depends on how common defects are among the components being inspected, and it equals 90 percent for only one particular base rate. This lesson shows how Bayes’ theorem combines that base rate with the inspection rates. All rates on this page are constructed to illustrate the arithmetic and make no claim about any real test.
Key terms
Bayes’ theorem
Definition Let and be events with and . Then
The proof is that and both equal by the multiplication rule. If also , the law of total probability over and gives the denominator
The theorem does not require and to be independent. If they were independent, it would give , and the evidence would change nothing.
In plain words Bayes’ theorem reverses the direction of a conditional probability. It combines the probability of the evidence given a hypothesis with the probability of the hypothesis before the evidence, and it gives the probability of the hypothesis given the evidence. Take the probability that the hypothesis and the evidence occur together, then divide by the total probability of the evidence, added up over every way the evidence can arise.
Example Let be the event that a component is defective, and write for a flag and for no flag. Suppose , and . True flags contribute to the probability of a flag and false flags contribute , so
Base rate and prior probability
Definition The base rate of a condition is the proportion of a stated population that has it, also called its prevalence. In a Bayes calculation the prior probability of a hypothesis is , its probability before the evidence at hand is taken into account. When a unit is chosen at random from a population, with every unit equally likely, the base rate of a condition in that population is the prior probability that the chosen unit has the condition. In this lesson every prior is a base rate in this sense.
In plain words The prior is where the calculation starts. For a component picked at random, the starting point is how common defects are among the components it was picked from. That base rate has to describe the population the component actually comes from, not some other group.
Example In the inspection model the base rate of defects is , so a component chosen at random has prior probability of being defective. If the inspection were used on a line where only percent of components are defective, and it still flagged percent of the defective and percent of the sound components there, the prior would be and a flag would lead to a far lower posterior probability, as the questions at the end show.
Posterior probability
Definition The posterior probability of a hypothesis after evidence , where , is the conditional probability in the same model as the prior. Bayes’ theorem computes it from the prior and the probabilities of the evidence under each hypothesis. If , the posteriors after and after average back to the prior, weighted by the probabilities of the evidence,
In plain words The posterior is the updated probability once the evidence is in. It is still a probability and not a verdict. A posterior of after a flag describes flagged components from this population as a group. If the model holds, about two thirds of a large number of them would be defective. It does not settle whether a particular flagged component is one of them.
Example In the inspection model the prior is . A flag raises the probability of a defect to . No flag has probability , and a component is both defective and unflagged with probability , so
about . This is low but not zero. Weighting the two posteriors by and recovers the prior, since .
Sensitivity and specificity
Definition Let be the event that a unit has the condition, with , and write and for a positive and a negative result. The sensitivity of the test is , the probability of a positive result for a unit with the condition. The specificity is , the probability of a negative result for a unit without it. Their complements are the false-negative rate , equal to minus the sensitivity, and the false-positive rate , equal to minus the specificity. All four rates condition on the true state of the unit.
In plain words Sensitivity looks only at units that have the condition and asks how often the test catches them. Specificity looks only at units without it and asks how often the test correctly stays negative. Neither answers the question raised by a positive result, which conditions on the result instead. Whether a test’s rates carry over from one population to another is an assumption to check, not a fact built into the definitions.
Example In the inspection model the sensitivity is and the specificity is , so the false-negative rate is and the false-positive rate is . Among flagged components the share that are sound is , not . The false-positive rate divides by all sound components, while that share divides by all flagged components.
Positive predictive value
Definition The positive predictive value of a test in a population is , the probability that a unit with a positive result has the condition, defined when . By Bayes’ theorem it equals the true-positive term divided by , which is the sum of the true-positive term and the false-positive term . So it depends on the base rate as well as on the sensitivity and the specificity. When the sensitivity and the false-positive rate are both positive and held fixed, the positive predictive value increases strictly as the base rate increases. The negative predictive value is the analogous probability for a negative result.
In plain words The positive predictive value asks what share of all positive results come from units that really have the condition. When the condition is rare, the many units without it can supply most of the positive results, even at a small false-positive rate.
Example With sensitivity and false-positive rate , the positive predictive value is at base rate . At base rate the two terms are and , and the positive predictive value is , about . At base rate it is , about . The inspection is the same in all three populations, and only the mix of defective and sound components differs. At base rate the negative predictive value is , about .
Natural frequencies
Definition Natural frequencies express a probability model as whole-number counts in an imagined group of fixed size, chosen so that every count matches the model’s proportions exactly. A conditional probability then becomes a ratio of counts, with the conditioning group as the denominator. The imagined counts restate the model. They are not data, and a real random batch of the same size would usually show somewhat different counts.
In plain words Replace the rates by a concrete group, follow it through the branches and count. The denominator of the question you are asking becomes a group you can see.
Example Imagine components that follow the inspection model exactly.
| Flagged | Not flagged | Total | |
|---|---|---|---|
| Defective | 90 | 10 | 100 |
| Sound | 45 | 855 | 900 |
| Total | 135 | 865 | 1,000 |
The flagged column holds components, of which are defective, so the positive predictive value is , the value Bayes’ theorem gave. The sensitivity uses the defective row as its denominator, while the positive predictive value uses the flagged column. The count appears in both.
Check yourself
- A different constructed inspection has sensitivity and specificity , and it is used where percent of components are defective. Use imagined components to find the positive predictive value.
Show the answer
Of the components, are defective and are sound. The inspection flags defective components and misses . The false-positive rate is , so it flags sound components and leaves unflagged. There are flags, so the positive predictive value is
about . The formula agrees, since and give . Most flags here come from sound components.
- Keep sensitivity and false-positive rate , but suppose only percent of components are defective. Find the probability that a flagged component is defective, explain why it is lower than , and say what it does and does not tell you about one flagged component.
Show the answer
True flags contribute and false flags , so and
In imagined components there are defective ones, of which are flagged, and sound ones, of which are flagged. The denominator is now the flags, and of them come from sound components. Lowering the base rate shrank the true-flag group and enlarged the sound group, which feeds the false flags, so the share of defective components among flags fell. The flag still raises the probability of a defect from to about , more than times the prior, but that is an updated probability and not certainty. If the model holds, about percent of a large number of flagged components would be defective, and any one flagged component either is defective or is not.
- Someone claims that with sensitivity and false-positive rate , a flag means a defect with probability whatever the population. For which base rate is that true? For which base rate is a flagged component equally likely to be defective or sound?
Show the answer
Write for the base rate, with . The positive predictive value is
Setting it equal to and dividing by gives , so and . The claim holds only at that one base rate. A flagged component is equally likely to be defective or sound when the true-flag and false-flag terms are equal, , so and , about . Below that base rate most flags are false. The sensitivity conditions on a defect, while the claim is about the probability of a defect given a flag, and that probability depends on the base rate.