Probability & Statistics · Unit 1 · Topic 02

Bayes' theorem: from the result back to the cause.

Short answer

If \(E_1, \dots, E_n\) are mutually exclusive causes covering every case, then

\[P(E_i \mid A) = \frac{P(E_i)\,P(A \mid E_i)}{\sum_j P(E_j)\,P(A \mid E_j)}\]

The denominator is \(P(A)\), from the theorem of total probability. For a 1% disease and a test with 95% detection and 5% false positives, \(P(D \mid +) \approx 0.16\).

Engineering MathsBScClass 12
01

The theorem of total probability

Before you start: you need conditional probability and the multiplication rule \(P(A \cap B) = P(B)\,P(A \mid B)\).

Suppose bolts come from three machines, and each machine has its own defect rate. What fraction of all bolts is defective? You cannot answer with one rate. You have to split the problem by machine, find the defective share from each, and add.

The machines form a partition: events \(E_1, E_2, \dots, E_n\) that are mutually exclusive (a bolt comes from only one machine) and exhaustive (every bolt comes from some machine). So \(P(E_1) + \cdots + P(E_n) = 1\).

Total probability

If \(E_1, \dots, E_n\) partition the sample space, then for any event \(A\), \[P(A) = P(E_1)P(A \mid E_1) + P(E_2)P(A \mid E_2) + \cdots + P(E_n)P(A \mid E_n)\]

Why it works: \(A\) splits into the pieces \(A \cap E_1, \dots, A \cap E_n\), which do not overlap. Add their probabilities, and write each piece with the multiplication rule.

02

Bayes' theorem and the tree method

Total probability goes forwards: from the cause to the result. Bayes' theorem goes backwards. You see the result (a defective bolt) and ask which cause produced it (which machine).

Bayes' theorem

\[P(E_i \mid A) = \frac{P(E_i)\,P(A \mid E_i)}{\sum_{j=1}^{n} P(E_j)\,P(A \mid E_j)}\]

In words

Posterior \(=\) (this branch) \(\div\) (all branches that lead to \(A\)).

\(P(E_i)\) is the prior: what you believed before seeing \(A\). \(P(E_i \mid A)\) is the posterior: your updated belief after seeing \(A\). The proof is one line. By definition \(P(E_i \mid A) = \dfrac{P(E_i \cap A)}{P(A)}\). The top is \(P(E_i)P(A \mid E_i)\) and the bottom is the total probability.

  1. Draw a tree. First branches: the causes \(E_i\) with their priors. Second branches: the result \(A\) (and not-\(A\)) with probabilities \(P(A \mid E_i)\).
  2. Multiply along each path that ends in \(A\). These products are \(P(E_i \cap A)\).
  3. Add the paths ending in \(A\). That sum is \(P(A)\).
  4. Divide the path you want by the total.

With percentages, an even quicker route is to imagine a round number of items, say 10,000, and count. Example 7 does exactly that.

03

Solved examples

Example 1: Two bags

Easy

Bag I has 3 red and 2 black balls. Bag II has 2 red and 4 black balls. A bag is chosen at random and a ball is drawn. Find the probability that it is red.

  1. Partition: \(E_1\) = bag I, \(E_2\) = bag II, each with probability \(\tfrac{1}{2}\).
  2. \(P(R \mid E_1) = \dfrac{3}{5}\), \(P(R \mid E_2) = \dfrac{2}{6} = \dfrac{1}{3}\).
  3. \(P(R) = \dfrac{1}{2}\cdot\dfrac{3}{5} + \dfrac{1}{2}\cdot\dfrac{1}{3} = \dfrac{3}{10} + \dfrac{1}{6} = \dfrac{9 + 5}{30}\).

Answer\(P(R) = \dfrac{7}{15}\)

Example 2: Which bag?

Easy

In Example 1 the ball drawn is red. Find the probability that it came from bag I.

  1. Path for bag I and red: \(\dfrac{3}{10}\). Total for red: \(\dfrac{7}{15}\).
  2. \(P(E_1 \mid R) = \dfrac{3/10}{7/15} = \dfrac{3}{10}\cdot\dfrac{15}{7} = \dfrac{45}{70}\).

Answer\(\dfrac{9}{14}\)

Example 3: Three machines

Medium

Machines A, B and C make 25%, 35% and 40% of a factory's bolts. Of their output, 5%, 4% and 2% respectively are defective. A bolt is picked at random and found defective. Find the probability that it was made by each machine.

  1. Paths: \(A\): \(0.25 \times 0.05 = 0.0125\). \(B\): \(0.35 \times 0.04 = 0.014\). \(C\): \(0.40 \times 0.02 = 0.008\).
  2. Total: \(P(D) = 0.0125 + 0.014 + 0.008 = 0.0345\).
  3. \(P(A \mid D) = \dfrac{0.0125}{0.0345} = \dfrac{25}{69}\), \(P(B \mid D) = \dfrac{0.014}{0.0345} = \dfrac{28}{69}\), \(P(C \mid D) = \dfrac{0.008}{0.0345} = \dfrac{16}{69}\).
  4. Check: \(25 + 28 + 16 = 69\), so the three posteriors add to 1.

Answer\(\dfrac{25}{69}\), \(\dfrac{28}{69}\), \(\dfrac{16}{69}\)

Example 4: Three urns

Medium

Urn 1 has 2 white and 3 black balls, urn 2 has 3 white and 2 black, urn 3 has 4 white and 1 black. An urn is chosen at random and a white ball is drawn. Find the probability that it came from urn 3.

  1. Each urn has prior \(\tfrac{1}{3}\). \(P(W \mid U_1) = \tfrac{2}{5}\), \(P(W \mid U_2) = \tfrac{3}{5}\), \(P(W \mid U_3) = \tfrac{4}{5}\).
  2. \(P(W) = \dfrac{1}{3}\left(\dfrac{2}{5} + \dfrac{3}{5} + \dfrac{4}{5}\right) = \dfrac{1}{3}\cdot\dfrac{9}{5} = \dfrac{3}{5}\).
  3. \(P(U_3 \mid W) = \dfrac{\frac{1}{3}\cdot\frac{4}{5}}{3/5} = \dfrac{4/15}{3/5}\).

Answer\(\dfrac{4}{9}\)

Example 5: Telling the truth

Medium

A man speaks the truth 3 times out of 4. He throws a fair die and reports that it is a six. Find the probability that it really is a six.

  1. Causes: \(E_1\) = a six was thrown, \(P = \tfrac{1}{6}\); \(E_2\) = not a six, \(P = \tfrac{5}{6}\).
  2. Result \(A\) = he says "six". \(P(A \mid E_1) = \tfrac{3}{4}\) (truth). \(P(A \mid E_2) = \tfrac{1}{4}\) (a lie).
  3. Paths: \(\dfrac{1}{6}\cdot\dfrac{3}{4} = \dfrac{3}{24}\) and \(\dfrac{5}{6}\cdot\dfrac{1}{4} = \dfrac{5}{24}\).
  4. \(P(E_1 \mid A) = \dfrac{3/24}{3/24 + 5/24}\).

Answer\(\dfrac{3}{8}\)

Example 6: A medical test

Exam level

A disease affects 1% of a population. A test detects it in 95% of people who have it, but also gives a positive result for 5% of people who do not. A person tests positive. Find the probability that they have the disease.

  1. Priors: \(P(D) = 0.01\), \(P(D') = 0.99\). \(P(+ \mid D) = 0.95\), \(P(+ \mid D') = 0.05\).
  2. Paths to a positive: \(0.01 \times 0.95 = 0.0095\) and \(0.99 \times 0.05 = 0.0495\).
  3. \(P(D \mid +) = \dfrac{0.0095}{0.0095 + 0.0495} = \dfrac{0.0095}{0.059} = \dfrac{19}{118} \approx 0.161\).
  4. Only about 16% of positives are real. The disease is rare, so the 5% false alarms among the healthy 99% outnumber the true cases.

Answer\(\dfrac{19}{118} \approx 0.161\)

Example 7: Counting instead of a tree

Exam level

An insurance company insures 2000 scooter drivers, 4000 car drivers and 6000 truck drivers. The probabilities of an accident are 0.01, 0.03 and 0.15. One insured person has an accident. Find the probability that the person is a scooter driver.

  1. Expected accidents: scooter \(2000 \times 0.01 = 20\), car \(4000 \times 0.03 = 120\), truck \(6000 \times 0.15 = 900\).
  2. Total accidents: \(20 + 120 + 900 = 1040\).
  3. The person is one of these 1040, and 20 of them drive scooters: \(P = \dfrac{20}{1040}\).
  4. With Bayes' formula and priors \(\tfrac{1}{6}, \tfrac{1}{3}, \tfrac{1}{2}\) you get the same fraction; the 12,000 just cancels.

Answer\(\dfrac{1}{52}\)

Vipul Sir's tip

When the numbers are percentages, I tell students to picture 10,000 people and fill in the counts. In Example 6 that is 100 sick people (95 test positive) and 9,900 healthy people (495 test positive). Then \(P(D \mid +) = \dfrac{95}{590}\), and nobody needs the formula.

04

Common mistakes

1. Reading \(P(+ \mid D)\) as \(P(D \mid +)\)

"The test is 95% accurate" gives \(P(+ \mid D) = 0.95\). It does not mean a positive result is 95% likely to be correct. In Example 6 that probability is only about 0.161.

2. Using causes that are not a partition

The priors must cover every case once and add to 1. In Example 5, the two causes are "six" (\(\tfrac{1}{6}\)) and "not six" (\(\tfrac{5}{6}\)). Using \(\tfrac{1}{6}\) for both would be wrong.

3. Dividing by the wrong total

The denominator is \(P(A)\), the sum of every path that ends in \(A\). Wrong: \(P(A \mid D) = \dfrac{0.0125}{0.25}\). Right: \(\dfrac{0.0125}{0.0345}\).

05

Practice questions

Try each one on paper before you open the answer.

Q1Box 1 has 2 white and 3 red balls; box 2 has 4 white and 1 red. A fair coin decides the box, and a ball is drawn. Find the probability that it is white.

\(\dfrac{1}{2}\cdot\dfrac{2}{5} + \dfrac{1}{2}\cdot\dfrac{4}{5} = \dfrac{1}{5} + \dfrac{2}{5} = \dfrac{3}{5}\).

Q2In Q1 the ball is white. Find the probability that it came from box 2.

\(\dfrac{2/5}{3/5} = \dfrac{2}{3}\).

Q3Machines X and Y make 60% and 40% of the items, with defect rates 2% and 3%. Find the probability that a defective item came from X.

\(P(D) = 0.012 + 0.012 = 0.024\). \(P(X \mid D) = \dfrac{0.012}{0.024} = \dfrac{1}{2}\).

Q4A disease affects 2% of people. A test is positive for 90% of those with it and for 10% of those without it. Find \(P(\text{disease} \mid +)\).

Paths: \(0.02 \times 0.9 = 0.018\) and \(0.98 \times 0.1 = 0.098\). \(P = \dfrac{0.018}{0.116} = \dfrac{9}{58} \approx 0.155\).

Q530% of a college's students live in the hostel. 60% of hostellers and 40% of day scholars get an A grade. A student with an A grade is chosen. Find the probability that the student is a hosteller.

Paths: \(0.3 \times 0.6 = 0.18\) and \(0.7 \times 0.4 = 0.28\). \(P = \dfrac{0.18}{0.46} = \dfrac{9}{23}\).

Q6A bag has one fair coin and one coin with heads on both sides. A coin is picked at random and tossed, and it shows heads. Find the probability that it is the two-headed coin.

Paths: \(\dfrac{1}{2}\cdot 1 = \dfrac{1}{2}\) and \(\dfrac{1}{2}\cdot\dfrac{1}{2} = \dfrac{1}{4}\). \(P = \dfrac{1/2}{3/4} = \dfrac{2}{3}\).

Stuck on a question?

Bring it to a free demo class and work through it with Vipul Sir. Book on WhatsApp.

06

Frequently asked questions

What is Bayes' theorem in simple words?

It updates a probability after you see some evidence. The chance that cause \(E_i\) produced result \(A\) is the probability of the path through \(E_i\) to \(A\), divided by the total probability of \(A\).

What is the difference between total probability and Bayes' theorem?

Total probability finds \(P(A)\) by adding over all causes. Bayes' theorem uses that \(P(A)\) as its denominator to find \(P(E_i \mid A)\), the probability of one cause given the result.

What are prior and posterior probabilities?

The prior \(P(E_i)\) is the probability of a cause before you see any evidence. The posterior \(P(E_i \mid A)\) is its probability after you know \(A\) happened.

Why is a positive test often a false alarm?

When a disease is rare, the healthy group is huge, so even a small false-positive rate produces more false alarms than there are true cases. That is why \(P(D \mid +)\) can be small when the test itself looks accurate.

Related lessons

← All 10 Probability & Statistics topics
Vipul Sir
Written by Vipul Sir

Vipul Sir has taught mathematics for over 15 years to HSC, CBSE, ICSE, IGCSE/IB, Diploma, Engineering and BSc students at VVS Classes in Goregaon and Vile Parle, Mumbai. He teaches every class himself, concepts first and exam technique second.

Probability and Statistics

Get Probability & Statistics right, with Vipul Sir beside you.

Concept-first classes in small batches in Goregaon and Vile Parle, or online. Your first class is free.

WhatsApp↗