State the law of total probability and give a concrete example of when you'd apply it.
The law of total probability computes an overall probability by taking a weighted average of conditional probabilities across a mutually exclusive and exhaustive partition. For example, it combines conversion rates from different traffic sources using each source's share of visitors.
How to think about it
The law of total probability computes an overall probability by splitting all cases into non-overlapping groups and taking a weighted average of the probability within each group. If B₁, B₂, …, Bₙ form a partition, then:
P(A) = Σᵢ P(A | Bᵢ) · P(Bᵢ)
Here, P(A | Bᵢ) means the probability of event A given that we are in group Bᵢ, and P(Bᵢ) is how common that group is.
The statement
An event is something that may or may not happen, such as a visitor converting. A sample space is the full set of outcomes under consideration, such as all visitors during a week.
A partition of the sample space has two properties:
- The groups are mutually exclusive, meaning one outcome cannot belong to two groups at once.
- The groups are exhaustive, meaning every outcome belongs to one of the groups.
For a finite partition B₁, B₂, …, Bₙ, each group must also have positive probability. The law is:
P(A) = P(A | B₁)P(B₁)
+ P(A | B₂)P(B₂)
+ ...
+ P(A | Bₙ)P(Bₙ)
The shape is simple: probability within a group, multiplied by the size of that group, then added across all groups.
That is why this is a weighted average rather than an ordinary average. A segment containing 60 percent of users should influence the overall rate six times as much as a segment containing 10 percent of users.
Why the formula works
The formula is not a trick to memorise. It follows from splitting event A into pieces.
Suppose the groups are traffic sources. Every conversion must come from exactly one source. So the event “converts” can be written as:
converts = (converts and organic)
or (converts and paid)
or (converts and social)
Those pieces do not overlap. A visitor assigned one first-touch source cannot be both an organic and a paid visitor in this analysis.
Because the pieces are disjoint, their probabilities add:
P(A) = Σᵢ P(A ∩ Bᵢ)
The product rule for probability says:
P(A ∩ Bᵢ) = P(A | Bᵢ)P(Bᵢ)
Substituting that into the previous expression gives the law of total probability:
P(A) = Σᵢ P(A | Bᵢ)P(Bᵢ)
The mechanism is therefore:
- Split the population into complete, non-overlapping groups.
- Calculate the event rate inside each group.
- Weight each rate by the group’s population share.
- Add the contributions.
Concrete example: e-commerce conversion
Suppose an online store has 100,000 visitors. Its first-touch attribution system assigns each visitor exactly one source.
| Traffic source | Share of visitors | Conversion rate |
|---|---|---|
| Organic search | 60% | 4% |
| Paid search | 30% | 7% |
| Social | 10% | 2% |
Let A be “the visitor converts.” Applying the law:
P(A) = P(A | organic)P(organic)
+ P(A | paid)P(paid)
+ P(A | social)P(social)
= 0.04 × 0.60
+ 0.07 × 0.30
+ 0.02 × 0.10
= 0.024 + 0.021 + 0.002
= 0.047
The overall conversion probability is therefore 4.7 percent.
The same result is easier to see using counts:
Organic conversions = 60,000 × 0.04 = 2,400
Paid conversions = 30,000 × 0.07 = 2,100
Social conversions = 10,000 × 0.02 = 200
Total conversions = 4,700
Overall rate = 4,700 / 100,000 = 4.7%
This is exactly when you apply the law: you know rates for separate segments, but need the rate for the whole population.
A common wrong answer is the ordinary average:
(4% + 7% + 2%) / 3 = 4.33%
That would be correct only if all three sources had equal traffic. They do not. Organic search has six times as many visitors as social, so its rate must count more heavily.
The connection to Bayes’ rule
The law of total probability is often the denominator in Bayes’ rule.
Bayes’ rule reverses a conditional question. Instead of asking, “What is the chance of conversion given paid search?”, it asks, “Given that someone converted, what is the chance they came from paid search?”
The numerator is the joint probability of being paid traffic and converting:
P(paid and converts) = P(converts | paid)P(paid)
= 0.07 × 0.30
= 0.021
But 0.021 is the probability that a randomly selected visitor is both paid and converted. It is not yet the probability that a converter was paid traffic.
To condition on conversion, divide by the probability of any conversion:
P(paid | converts)
= P(converts | paid)P(paid) / P(converts)
= 0.021 / 0.047
≈ 0.447
So about 44.7 percent of conversions came from paid search, even though paid search represented only 30 percent of visitors.
The denominator is:
P(converts) = Σᵢ P(converts | sourceᵢ)P(sourceᵢ)
That is the law of total probability applied to all possible sources of a conversion. It makes the posterior probabilities add up correctly. This is the key connection covered in Bayes’ theorem.
The condition that matters most
The groups must genuinely form a partition.
In the example, that required a first-touch rule that assigns each visitor one source. In a real attribution system, a visitor might arrive through an organic search, click a paid ad later, and then convert through a bookmarked page. If the analyst labels that visitor as both organic and paid, the rows overlap.
Applying the formula directly would count that visitor in multiple groups. The total can then be too large, sometimes dramatically so.
The remedy is not to hope the arithmetic behaves. Redefine the groups. For example, use categories such as:
- organic only
- paid only
- both organic and paid
- neither or unknown
Those categories are mutually exclusive and can be made exhaustive. Alternatively, use a carefully defined attribution policy and assign one source.
If some visitors have no known source, add an “unknown” group. Silently dropping them changes the population whose probability you are calculating.
Sometimes the correct target is the rate among classified visitors only. Let C mean “the visitor has a known source.” Then use the conditional form:
P(A | C) = Σᵢ P(A | Bᵢ, C)P(Bᵢ | C)
The groups must partition the classified population C, and the weights must be source shares among that population, not shares among all visitors.
The senior nuance: aggregation does not explain cause
The law gives an exact aggregate probability when its inputs describe the same population. It does not say that a group caused the outcome.
Paid search has a 7 percent conversion rate in the example. That does not prove paid ads caused those conversions. Paid visitors may differ from organic visitors in intent, device, geography, or previous exposure to the brand. The law combines observed rates; it does not turn an observational comparison into a causal experiment.
It also warns you about composition effects. Suppose the conversion rates stay exactly the same, but the traffic mix changes to 80 percent organic, 10 percent paid, and 10 percent social:
Overall rate = 0.04 × 0.80
+ 0.07 × 0.10
+ 0.02 × 0.10
= 0.041
= 4.1%
The dashboard has fallen from 4.7 percent to 4.1 percent even though no channel got worse. The population simply contains less of the high-converting paid segment. An overall KPI can therefore move because of changing weights.
The same weighting mechanism is behind Simpson’s paradox, where a comparison visible inside every segment can reverse after the segments are combined. Before claiming that a model, campaign, or treatment improved, check both the segment-level rates and the segment mix.
There is another practical issue: production rates are usually estimates. If a validation sample is split 50–50 between two segments but production traffic is split 90–10, averaging the validation rates equally estimates the validation mix, not the production rate. Use weights from the population you care about.
For a continuous grouping variable such as age or temperature, the same idea remains valid, but the sum becomes an integral:
P(A) = ∫ P(A | X = x) fₓ(x) dx
Here, fₓ(x) is the probability density of the variable X. In everyday analytics, bins are often used as a practical approximation.
Common failure modes
The first symptom of an unweighted-average bug is usually a reconciliation failure. The segment table implies 4,700 conversions among 100,000 visitors, but the reported overall rate says 4.33 percent, or roughly 4,333 conversions. The arithmetic is tidy. The denominator is wrong.
Other mistakes are easy to spot if you ask what each number means:
- Adding conditional rates without multiplying by group shares treats rare and common groups as equally important.
- Using
P(converts | paid)as the answer toP(paid | converts)reverses the conditioning direction. - Using overlapping groups counts some outcomes more than once.
- Using weights from a biased sample answers a question about that sample rather than the target population.
- Treating the aggregate rate as causal hides differences between groups and changes in population mix.
A reliable check is to write the population in plain English before writing the formula. Ask: “What does one randomly selected outcome represent?” Then verify that exactly one Bᵢ describes every possible outcome in that population.
What they’ll ask next
Why can’t I just add the conditional probabilities?
Because they describe rates inside different-sized groups. You need each rate’s contribution to the whole population, which is P(A | Bᵢ)P(Bᵢ). The weights account for how often each group occurs.
Can I use the law when the groups overlap?
Not directly. First turn the groups into mutually exclusive cells, such as “paid only,” “organic only,” and “both,” or use a method that explicitly handles overlap. Otherwise, the same outcome can be counted more than once.
What happens when the groups do not cover everyone?
Add an unknown or other category, or state that you are conditioning on the covered population. For classified users, compute P(A | classified) with group shares calculated among classified users.
Why is this important for Bayes’ rule?
Bayes needs P(evidence) in the denominator. If the possible hypotheses form a partition, the law computes that denominator by summing the evidence probability under each hypothesis, weighted by its prior probability.
Say this in the interview
“The law of total probability says that if cases form a mutually exclusive and exhaustive partition, the overall probability is the weighted average of the conditional probabilities within those cases; for example, I combine each traffic source’s conversion rate with its share of visitors to get the site’s overall conversion rate.”