TL;DR
Sometimes the easiest way to find the chance of an event is to split the whole situation into separate cases, work out the chance of the event inside each case, and then average those chances, weighted by how likely each case is. The split has to be clean: the cases must not overlap, and together they must cover everything that can happen.
This is the rule that turns "the answer depends on which case we are in" into a single number.
Where you'll see it: in computing the overall error rate of a classifier from its error rates on each class, in Bayes' rule where the denominator is built with this law, and in marginalising a latent variable out of a model.
Intuition
Averaging over the cases
Suppose a factory has two production lines. Line A makes 60% of the parts and Line B makes the other 40%. Line A ships 2% defective parts and Line B ships 5%. You pick one part at random from the whole output. What is the chance it is defective?
You cannot read that off directly, because the answer depends on which line made the part. But you do know the answer within each line, and you know how much of the output each line contributes. The overall chance is just the defect rate of each line, weighted by that line's share:
So 3.2% of all parts are defective. Notice that this is not the simple average of 2% and 5%, which would be 3.5%. Line A's parts count for more because there are more of them. The weights matter.
That is the whole idea. Split by a question you can answer (which line made it?), get the answer in each piece, and add the pieces back up with the right weights.
flowchart TD W[All parts] --> A[Made by Line A, 60 percent] W --> B[Made by Line B, 40 percent] A --> DA[Defective within A: 2 percent] B --> DB[Defective within B: 5 percent] DA --> T[Total defective: 0.6 times 2 plus 0.4 times 5 equals 3.2 percent] DB --> T
Why the split must be clean
The method only works if every part belongs to exactly one line. If a part could come from both lines, it would be counted twice. If some parts came from neither line, they would be missing from the total. The cases have to tile the whole sample space like pieces of a jigsaw: no overlaps, no gaps. Mathematicians call such a set of cases a partition.
The math
Partitions
A collection of events is a partition of the sample space if the events are pairwise disjoint (no two of them can happen together, so for ) and their union covers everything, . Each also needs , so that the conditional probabilities given exist.
The factory lines form a partition: each part came from exactly one line, and every part came from some line. The are the "cases" and the are the weights.
The law
For any event and any partition (the sum uses summation notation),
Each term is "the chance of inside case " times "how likely case is". The sum adds up these pieces. Note that is a conditional probability (see conditional probability), so the law leans on the multiplication rule .
Why it is true
Start with and cut it up by the cases. Because the cover , every outcome in lies in at least one , so
Because the are disjoint, these pieces do not overlap. Probability adds over non-overlapping events, so
Finally, apply the multiplication rule to each term, , and the law follows. Each step is one line, and none of them needs more than the definition of conditional probability.
Checking the factory example
Let be "made by Line A" and be "made by Line B". Let be "defective". Then
and
The law gives the same answer as the intuition above, now written in symbols.
The continuous version
When the cases form a continuum, the sum becomes an integral. If is a random variable with density and depends on , then the density of is
This is the same idea: is the density of inside the case , the integral averages over all cases, and is the weight. Statisticians call it marginalising out .
Worked examples
A bag is chosen by a fair coin toss. Bag 1 holds 3 red balls and 1 blue ball. Bag 2 holds 1 red ball and 3 blue balls. You draw one ball from the chosen bag. What is the chance it is red?
- The cases are "Bag 1" and "Bag 2". They are disjoint and cover everything, so they form a partition.
- The weights are and .
- Within Bag 1, the chance of red is . Within Bag 2, it is .
- Apply the law: .
Interpretation: the two bags are mirror images, so overall a red ball is exactly as likely as a blue one. Each bag is lopsided, but the lopsidedness cancels because the bags are equally likely to be chosen.
A mail filter sorts messages into two groups by whether they contain the word "invoice". Suppose 30% of all messages contain "invoice", and 10% of those are spam. Among messages without "invoice", 2% are spam. What fraction of all messages are spam?
- Cases: = "contains invoice" and = "does not contain invoice". These partition all messages.
- Weights: and .
- Spam rates within each case: and .
- Apply the law: .
Interpretation: about 4.4% of all messages are spam. A naive guess that averages 10% and 2% would give 6%, which is wrong because most messages fall in the low-spam group.
Tradeoffs and failure modes
The law is a calculation, not a modelling choice, so it is hard to use wrongly in the formula itself. Most mistakes come from the setup.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Cases overlap | Some outcomes are counted twice and the total is too big | Redefine the cases so each outcome falls in exactly one |
| Cases leave gaps | Some outcomes are missing and the total is too small | Add a catch-all case such as "none of the above" |
| Averaging the rates without weights | Small cases get the same say as big ones | Use the case probabilities as weights |
| Conditioning on an event of probability zero | The conditional probability is undefined | Drop the case, or use a density in the continuous version |
| Many or continuous cases | Summing over every case is impractical | Use the integral form, or a model with a closed-form marginal |
A common confusion is between and . The law tells you how to get from the first kind of quantity. Turning the answer around to get needs Bayes' rule, which uses this law in its denominator.
History
The idea of splitting a question into cases and averaging is much older than its formal name. It appears in early probability arguments, including the 18th-century work of Thomas Bayes on reasoning backwards from observations and Pierre-Simon Laplace's treatises on probability. Laplace used this kind of case-splitting routinely.
The modern treatment came in the 1930s. Andrey Kolmogorov's axioms, published in 1933, defined probability as a measure on a sample space. Once probability is defined that way, the law is a short theorem that follows from additivity over disjoint events, which is exactly the proof above. It caught on because it is the basic tool for combining conditional information, and nearly every later calculation with conditional probabilities uses it somewhere.
Check yourself
QuestionRecall: what two conditions must a set of events meet to be a partition of the sample space?Show answer
The events must be pairwise disjoint, so no two of them can happen together, and their union must cover the whole sample space, so one of them always happens. In addition, each should have positive probability so that is defined.
QuestionA machine has two shifts. Shift 1 runs 70% of the hours and has a fault rate of 1%. Shift 2 runs 30% of the hours and has a fault rate of 4%. What is the overall fault rate?Show answer
Use the law with the shifts as the partition: . The overall fault rate is 1.9%. The simple average of 1% and 4% would be 2.5%, which is wrong because Shift 1 runs more often and should carry more weight.
QuestionWhy is the sum of conditional rates weighted by the case probabilities, and not simply averaged?Show answer
The overall probability counts every outcome of once. Each case contributes the share of that falls inside it, and that share is the case's probability times its internal rate. A case that is rarely true contributes only a small piece of the total, so an unweighted average would give it too much influence.
QuestionA test flags a part as faulty. Two suppliers provide parts. Supplier X provides 80% of parts, and the chance a part from X is flagged is 0.05. Supplier Y provides 20%, and the chance a part from Y is flagged is 0.15. A part is picked at random. What is the chance it is flagged, and which supplier's parts drive most of the flags?Show answer
By the law, the chance is , or 7%. Supplier X contributes 0.040 of that 0.070, which is more than half, so most flags come from X. Supplier Y has a much higher rate, but it provides only a fifth of the parts, so its contribution is smaller.