Probability and Bayes’ rule

A probability depends on which outcomes you are counting. Combine groups to find an overall rate, then restrict the same counts to see what new evidence tells you.

A flag changes which group we count

A detector flags a component for inspection. How likely is a flagged component to be defective? A high detection rate alone cannot answer this: flags may also come from good components. Use the following chosen batch of 1000 components, with hypothetical detector outcomes.

Actual conditionFlaggedNot flaggedTotal
Defective18220
Good49931980
Total679331000

Imagine selecting one of these 1000 components uniformly. An event is a set of possible selected components. Write H for “defective” and E for “flagged.” Then $P(H)=20/1000$, the fraction in H. The intersection $H\cap E$ consists of components that are both defective and flagged; its probability is 18/1000.

The conditional probability $P(H\mid E)$ means the probability of a defect given that the component is flagged. The condition keeps only the 67 flagged components. Of those, 18 are defective, so the answer is 18/67. Reversing the condition asks a different question: among the 20 defective components, how many are flagged? That is $P(E\mid H)=18/20=9/10$.

$$P(H\mid E)=\frac{P(H\cap E)}{P(E)},\qquad P(E)>0$$

Conditioning divides the overlap by the probability of the group being kept. It is not a claim that H caused E.

We can recover the overlap from the other conditional: $P(H\cap E)=P(E\mid H)P(H)$. Here (18/20)(20/1000)=18/1000. Substitute this into the preceding fraction to obtain Bayes' theorem.

$$P(H\mid E)=\frac{P(E\mid H)P(H)}{P(E)}$$

The displayed likelihood P(E|H) requires P(H)>0, and the posterior requires P(E)>0. A zero-prior hypothesis can instead be handled by its zero joint probability.

The prior $P(H)$ is our probability before using this new evidence; it can already reflect other knowledge. The likelihood $P(E\mid H)$ describes how often the evidence occurs under the hypothesis. The posterior $P(H\mid E)$ is the probability after restricting to the evidence. The denominator P(E) counts every route to that evidence, including flags from good components.

Build the denominator from both kinds of flag

  1. Let $H^c$ mean the complement of H: the component is good. The prior probabilities are $P(H)=1/50$ and $P(H^c)=49/50$. They add to one because every component is in exactly one of these two groups.
  2. The detector's true-positive rate is $P(E\mid H)=9/10$. Its false-positive rate is $P(E\mid H^c)=49/980=1/20$. Multiply each rate by the share of components to which it applies: true flags have probability 9/500 and false flags 49/1000.
  3. These are disjoint routes to a flag, so $P(E)=9/500+49/1000=67/1000$. Therefore $P(H\mid E)=(18/1000)/(67/1000)=18/67\approx0.269$.
  4. For a non-flagged component, use the other column. There are 2 defective components among 933 non-flags, giving $P(H\mid E^c)=2/933$. Its numerator can also be computed as $(1-9/10)(1/50)=2/1000$.

The flag raises the defect probability from 1/50 to about 0.269, but it does not raise it to 0.9. Good components are much more numerous, and their 49 false flags outnumber the 18 true flags. The probability of a false flag among good components, 1/20, is also different from the probability of being good among flags, 49/67.

If the overall evidence probability is already supplied, no two-case calculation is needed. For example, chosen probabilities $P(E\mid H)=3/5$, $P(H)=1/4$ and $P(E)=1/2$ give $P(H\mid E)=(3/5)(1/4)/(1/2)=3/10$. The overlap 3/20 is divided by the evidence probability, not by the prior again.

Odds compare a probability with its complement: prior odds are $P(H)/P(H^c)$. In the detector table they are 20/980=1/49. Among flags the posterior odds are 18/49. Dividing Bayes' formula for H by its formula for Hᶜ cancels the common evidence denominator.

$$\frac{P(H\mid E)}{P(H^c\mid E)}=\frac{P(E\mid H)}{P(E\mid H^c)}\frac{P(H)}{P(H^c)}$$

Posterior odds equal likelihood ratio times prior odds. This finite-ratio form requires both prior groups and the false-positive likelihood to have positive probability.

Here the likelihood ratio is (9/10)/(1/20)=18, so the odds multiply by 18: (1/49)·18=18/49. Odds of 18 to 49 correspond to probability 18/(18+49)=18/67; odds and probability have different denominators.

Evidence need not change a prior. If a different flag occurs with probability 2/5 in both defective and good components, its overall probability is also 2/5. Bayes gives $P(H\mid E)=(2/5)P(H)/(2/5)=P(H)$. Equal likelihoods provide no distinction between the hypotheses. If P(E)=0 instead, elementary conditional probability is undefined: its formula cannot divide by zero.