Bayes’ theorem questions are really “reverse” questions: you know how likely an observation is for each possible cause, and you are asked how likely a particular cause is once the observation has happened. A tree diagram turns this into a mechanical process. By the end of this article you will be able to draw the tree, read off the formula from it, and avoid the classic mix-up between \(P(A\mid E)\) and \(P(E\mid A)\).

The idea in one picture

Suppose the sample space is split into causes \(E_1, E_2, \dots, E_n\) that are mutually exclusive and together cover every possibility (a partition). An event \(A\) can happen through any of these causes. A tree diagram has two levels:

  • First branches: the causes, labelled with the prior probabilities \(P(E_i)\).
  • Second branches: from each cause, the branch for \(A\), labelled \(P(A\mid E_i)\).

Multiplying along a path gives \(P(E_i \cap A) = P(E_i)\,P(A\mid E_i)\). Adding all paths that end in \(A\) gives the theorem of total probability:

\[P(A) = \sum_{i} P(E_i)\,P(A\mid E_i).\]

Bayes’ theorem is simply “one path divided by all the \(A\)-paths”:

\[P(E_k\mid A) = \frac{P(E_k)\,P(A\mid E_k)}{\sum_i P(E_i)\,P(A\mid E_i)}.\]

Why does this work? By the definition of conditional probability, \(P(E_k\mid A) = \dfrac{P(E_k\cap A)}{P(A)}\). The numerator is one path of the tree; the denominator is the total of the \(A\)-paths. Nothing more is going on.

The tree-diagram method

  1. Name the causes \(E_1, E_2, \dots\) and the observed event \(A\) in words. Check that the causes form a partition.
  2. Write the priors \(P(E_i)\); they must add to 1.
  3. Write the likelihoods \(P(A\mid E_i)\) from the question (percentages become decimals).
  4. Multiply along each path to get \(P(E_i)P(A\mid E_i)\).
  5. Add the path products to get \(P(A)\).
  6. Divide the required path by \(P(A)\).

Read the question’s last sentence first. “Given that the sheet is smudged, find the probability that it came from printer C” means you want \(P(C\mid \text{smudged})\): the cause is unknown, the observation is known. That tells you which path goes on top.

Worked example 1: three sources

A school office has three printers. Printer A prints 50% of all sheets, B prints 30% and C prints 20%. Of the sheets they print, 2%, 3% and 5% respectively come out smudged. A sheet is picked at random and is smudged. Find the probability that it was printed by C.

Let \(S\) = sheet is smudged. The tree paths are:

Cause \(P(E_i)\) \(P(S\mid E_i)\) Path product
A 0.5 0.02 0.010
B 0.3 0.03 0.009
C 0.2 0.05 0.010
Total \(P(S)\) 0.029

\[P(C\mid S) = \frac{0.010}{0.029} = \frac{10}{29}.\]

Notice that C prints the fewest sheets but is as likely a source of a smudged sheet as A (both \(\frac{10}{29}\)), because its smudge rate is higher. B’s share is \(\frac{9}{29}\), and the three add to 1, which is a useful check.

Using the other branches too

A full tree also has a “not smudged” branch from each printer, with probabilities 0.98, 0.97 and 0.95. These paths give \(0.5\times0.98 = 0.49\), \(0.3\times0.97 = 0.291\) and \(0.2\times0.95 = 0.19\), totalling \(0.971 = 1 – 0.029\), as it must. So if the question had said the sheet was not smudged, the probability that it came from A would be \(\dfrac{0.49}{0.971} = \dfrac{490}{971}\). Drawing all branches costs a few seconds and lets you answer either version of the question, or a case-based question that asks both.

Worked example 2: a surprising answer

An email service finds that 20% of incoming emails are spam. Its filter flags 95% of spam emails and also wrongly flags 4% of genuine emails. An email has been flagged. What is the probability that it is actually spam?

Causes: \(E_1\) = spam (0.2), \(E_2\) = genuine (0.8). Event \(F\) = flagged.

\[P(F) = 0.2\times 0.95 + 0.8\times 0.04 = 0.19 + 0.032 = 0.222.\] \[P(\text{spam}\mid F) = \frac{0.19}{0.222} = \frac{190}{222} = \frac{95}{111} \approx 0.856.\]

Even with a filter that catches 95% of spam, roughly one flagged email in seven is genuine, because genuine emails are so much more common. Bayes’ theorem makes this precise.

Worked example 3: a two-stage experiment

Bag I contains 4 red and 3 blue balls; Bag II contains 2 red and 5 blue balls. A die is rolled. If it shows 1 or 2, a ball is drawn from Bag I; otherwise from Bag II. The ball drawn is red. Find the probability that it came from Bag I.

Priors: \(P(\text{I}) = \frac{2}{6} = \frac{1}{3}\), \(P(\text{II}) = \frac{2}{3}\). Likelihoods: \(P(R\mid\text{I}) = \frac{4}{7}\), \(P(R\mid\text{II}) = \frac{2}{7}\).

\[P(\text{I}\mid R) = \frac{\frac{1}{3}\cdot\frac{4}{7}}{\frac{1}{3}\cdot\frac{4}{7} + \frac{2}{3}\cdot\frac{2}{7}} = \frac{\frac{4}{21}}{\frac{4}{21} + \frac{4}{21}} = \frac{1}{2}.\]

Bag I is less likely to be chosen but more likely to give red, and here the two effects balance exactly.

Worked example 4: when the observation is a “not”

A courier firm sends 70% of its parcels by road and 30% by rail. A parcel sent by road arrives late with probability \(\frac{1}{10}\); one sent by rail arrives late with probability \(\frac{1}{4}\). A parcel arrived on time. Find the probability that it was sent by rail.

The observation is “on time”, so use the complementary branches: \(P(T\mid\text{road}) = 0.9\), \(P(T\mid\text{rail}) = 0.75\).

\[P(T) = 0.7\times 0.9 + 0.3\times 0.75 = 0.63 + 0.225 = 0.855.\] \[P(\text{rail}\mid T) = \frac{0.225}{0.855} = \frac{5}{19}.\]

Rail’s share drops from 0.3 to about 0.26, because rail parcels are less likely to be on time.

Prior versus posterior

It helps to name the two kinds of probability in every Bayes question. The prior \(P(E_i)\) is what you believe before the observation; the posterior \(P(E_i\mid A)\) is the updated value afterwards. In Example 1, printer C’s prior was 0.2 and its posterior rose to \(\frac{10}{29} \approx 0.34\), because smudging is more typical of C. Comparing the two is a quick sense check: a cause that makes the observation more likely than average should gain probability.

Common mistakes

  • Swapping the conditional: using \(P(A\mid E_k)\) as the answer when \(P(E_k\mid A)\) is asked.
  • Priors not adding to 1. If they do not, a cause is missing or the causes overlap.
  • Using the wrong percentage as a likelihood, for example the 95% “not smudged” figure instead of the 5% smudged figure.
  • Forgetting a path in the denominator. Every cause that can lead to \(A\) must be included.
  • Rounding too early. Keep fractions or exact decimals until the last step.

Practise next

Work through more problems on the Bayes’ theorem topic page. If conditional notation still feels uncertain, revise conditional probability first. Create a free student account to take timed practice tests on the Probability chapter.

Frequently asked questions

When should I use Bayes' theorem instead of total probability?

Use total probability when you need the overall chance of the observed event \(P(A)\). Use Bayes' theorem when the event has already happened and you need the probability of one particular cause, \(P(E_k\mid A)\).

Is drawing a tree diagram compulsory?

It is not required, but it organises the priors, likelihoods and path products clearly. A small table of paths, as in the examples here, does the same job.

Do the posterior probabilities always add up to 1?

Yes. Given that \(A\) has happened, exactly one of the causes produced it, so \(P(E_1\mid A) + P(E_2\mid A) + \dots = 1\). This is a quick check on your arithmetic.

Can the causes overlap?

No. Bayes' theorem in this form needs the causes to be mutually exclusive and exhaustive, i.e. a partition of the sample space.