1. Home
  2. Explore
  3. Mathematics
  4. Bayes Theorem

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Bayes Theorem

📘 Bayes’ Theorem & Total Probability

Introduction to Bayes’ Theorem

Bayes’ Theorem provides a way to compute the conditional probability of an event given that another event has occurred. In particular, it helps find the “inverse” probability: if we know P(A∣B)P(A|B)P(A∣B), we can find P(B∣A)P(B|A)P(B∣A). This is crucial in many real-world scenarios where we observe an effect and want to infer the most likely cause.

Formal Statement

Let B1,B2,…,BnB_1, B_2, \dots, B_nB1​,B2​,…,Bn​ be a set of events that satisfy:

  • They are mutually exclusive (no two can occur together).

  • Their union is the entire sample space SSS (they form a partition of SSS).

  • P(Bi)≠0P(B_i) \neq 0P(Bi​)=0 for each iii.

Then for any event AAA (that can occur with one of the BiB_iBi​), the total probability of AAA is:

P(A)=∑i=1nP(Bi)⋅P(A∣Bi)P(A) = \sum_{i=1}^n P(B_i) \cdot P(A | B_i)P(A)=∑i=1n​P(Bi​)⋅P(A∣Bi​)

And Bayes’ Theorem gives the posterior probability of a particular BiB_iBi​ given AAA:

P(Bi∣A)=P(Bi)⋅P(A∣Bi)P(A)=P(Bi)⋅P(A∣Bi)∑j=1nP(Bj)⋅P(A∣Bj)P(B_i | A) = \frac{P(B_i) \cdot P(A | B_i)}{P(A)} = \frac{P(B_i) \cdot P(A | B_i)}{\sum_{j=1}^n P(B_j) \cdot P(A | B_j)}P(Bi​∣A)=P(A)P(Bi​)⋅P(A∣Bi​)​=∑j=1n​P(Bj​)⋅P(A∣Bj​)P(Bi​)⋅P(A∣Bi​)​

Interpretation: P(Bi)P(B_i)P(Bi​) is the prior probability (before observing AAA), and P(Bi∣A)P(B_i|A)P(Bi​∣A) is the posterior probability (after observing AAA). Bayes’ theorem updates our belief about BiB_iBi​ in light of new evidence AAA.


Example 1: Defective Bolts from Vendors

Setup: A company orders bolts from three vendors:

  • Vendor A: supplies 30% of bolts, with 2% defective.

  • Vendor B: supplies 40% of bolts, with 3% defective.

  • Vendor C: supplies 30% of bolts, with 5% defective.

All bolts are mixed together. A bolt is chosen at random and found to be defective.

Step 1: Define Events

  • AAA, BBB, CCC: the bolt came from vendor A, B, or C respectively.

  • DDD: the bolt is defective.

Given probabilities:

  • P(A)=0.30,P(B)=0.40,P(C)=0.30P(A) = 0.30,\quad P(B) = 0.40,\quad P(C) = 0.30P(A)=0.30,P(B)=0.40,P(C)=0.30

  • P(D∣A)=0.02,P(D∣B)=0.03,P(D∣C)=0.05P(D|A) = 0.02,\quad P(D|B) = 0.03,\quad P(D|C) = 0.05P(D∣A)=0.02,P(D∣B)=0.03,P(D∣C)=0.05

Step 2: Total Probability of Defective

P(D)=P(A)P(D∣A)+P(B)P(D∣B)+P(C)P(D∣C)P(D) = P(A)P(D|A) + P(B)P(D|B) + P(C)P(D|C)P(D)=P(A)P(D∣A)+P(B)P(D∣B)+P(C)P(D∣C)
=(0.30)(0.02)+(0.40)(0.03)+(0.30)(0.05)= (0.30)(0.02) + (0.40)(0.03) + (0.30)(0.05)=(0.30)(0.02)+(0.40)(0.03)+(0.30)(0.05)
=0.006+0.012+0.015=0.033= 0.006 + 0.012 + 0.015 = 0.033=0.006+0.012+0.015=0.033

So the overall probability that a randomly chosen bolt is defective is 0.0330.0330.033 (or 3.3%3.3\%3.3%).

Step 3: Bayes’ Theorem – Find Probability It Came from a Particular Vendor

Probability it came from Vendor A given it is defective:

P(A∣D)=P(A)P(D∣A)P(D)=0.30×0.020.033=0.0060.033=633=211P(A|D) = \frac{P(A)P(D|A)}{P(D)} = \frac{0.30 \times 0.02}{0.033} = \frac{0.006}{0.033} = \frac{6}{33} = \frac{2}{11}P(A∣D)=P(D)P(A)P(D∣A)​=0.0330.30×0.02​=0.0330.006​=336​=112​

Probability it came from Vendor B:

P(B∣D)=0.40×0.030.033=0.0120.033=1233=411P(B|D) = \frac{0.40 \times 0.03}{0.033} = \frac{0.012}{0.033} = \frac{12}{33} = \frac{4}{11}P(B∣D)=0.0330.40×0.03​=0.0330.012​=3312​=114​

Probability it came from Vendor C:

P(C∣D)=0.30×0.050.033=0.0150.033=1533=511P(C|D) = \frac{0.30 \times 0.05}{0.033} = \frac{0.015}{0.033} = \frac{15}{33} = \frac{5}{11}P(C∣D)=0.0330.30×0.05​=0.0330.015​=3315​=115​

Check: 211+411+511=1\frac{2}{11} + \frac{4}{11} + \frac{5}{11} = 1112​+114​+115​=1, as expected.

Key idea: Total probability gives P(D)P(D)P(D), then Bayes’ theorem uses P(D)P(D)P(D) as denominator to compute each posterior probability.


Example 2: Professors and New Subject Introduction

Setup: Three candidates X, Y, Z for a professor post. Their chances of selection are in proportion 4:2:34:2:34:2:3. If selected:

  • X will introduce a new subject with probability 0.350.350.35

  • Y with probability 0.520.520.52

  • Z with probability 0.800.800.80

Step 1: Prior Probabilities

Total proportion = 4+2+3=94+2+3 = 94+2+3=9.

P(X)=49,P(Y)=29,P(Z)=39P(X) = \frac{4}{9},\quad P(Y) = \frac{2}{9},\quad P(Z) = \frac{3}{9}P(X)=94​,P(Y)=92​,P(Z)=93​

Step 2: Event of Introducing New Subject

Let NNN = “new subject is introduced”. The conditional probabilities are:

P(N∣X)=0.35,  P(N∣Y)=0.52,  P(N∣Z)=0.80P(N|X)=0.35,\; P(N|Y)=0.52,\; P(N|Z)=0.80P(N∣X)=0.35,P(N∣Y)=0.52,P(N∣Z)=0.80

Step 3: Total Probability of New Subject

P(N)=P(X)P(N∣X)+P(Y)P(N∣Y)+P(Z)P(N∣Z)P(N) = P(X)P(N|X) + P(Y)P(N|Y) + P(Z)P(N|Z)P(N)=P(X)P(N∣X)+P(Y)P(N∣Y)+P(Z)P(N∣Z)
=49(0.35)+29(0.52)+39(0.80)= \frac{4}{9}(0.35) + \frac{2}{9}(0.52) + \frac{3}{9}(0.80)=94​(0.35)+92​(0.52)+93​(0.80)
=19(1.4+1.04+2.4)=19(4.84)=4.849= \frac{1}{9} \big( 1.4 + 1.04 + 2.4 \big) = \frac{1}{9}(4.84) = \frac{4.84}{9}=91​(1.4+1.04+2.4)=91​(4.84)=94.84​

Simplify (optional):

4.849=484900=121225≈0.5378\frac{4.84}{9} = \frac{484}{900} = \frac{121}{225} \approx 0.537894.84​=900484​=225121​≈0.5378

Thus the probability that a new subject will be introduced in the department is 0.53780.53780.5378 (or about 53.78%53.78\%53.78%).

Note: This is a straightforward total probability problem. No Bayes inversion is needed here because the question only asks for P(N)P(N)P(N), not the probability that a specific candidate was selected given NNN.


Example 3: Three Boxes with Colored Balls

Setup: There are three boxes containing:

  • Box 1: 1 white, 2 red, 3 black balls (total 6)

  • Box 2: 2 white, 3 red, 1 black ball (total 6)

  • Box 3: 3 white, 1 red, 2 black balls (total 6)

A box is chosen at random, and then two balls are drawn from it without replacement. The two balls are one red and one white.

Question: Given that the two drawn balls are one red and one white, what is the probability they came from Box 1?

Step 1: Prior Probabilities

Since a box is chosen at random:

P(Box 1)=P(Box 2)=P(Box 3)=13P(\text{Box 1}) = P(\text{Box 2}) = P(\text{Box 3}) = \frac{1}{3}P(Box 1)=P(Box 2)=P(Box 3)=31​

Step 2: Conditional Probabilities of Drawing One Red and One White from Each Box

Let EEE = “one red and one white ball are drawn”.

Box 1:

  • Total ways to choose 2 balls from 6: (62)=15\binom{6}{2}=15(26​)=15

  • Ways to get 1 red (from 2) and 1 white (from 1): (21)(11)=2\binom{2}{1}\binom{1}{1}=2(12​)(11​)=2

  • So P(E∣Box 1)=215P(E|\text{Box 1}) = \frac{2}{15}P(E∣Box 1)=152​

Box 2:

  • Total ways: 151515

  • Ways: 1 red from 3, 1 white from 2: (31)(21)=6\binom{3}{1}\binom{2}{1}=6(13​)(12​)=6

  • So P(E∣Box 2)=615=25P(E|\text{Box 2}) = \frac{6}{15} = \frac{2}{5}P(E∣Box 2)=156​=52​

Box 3:

  • Total ways: 151515

  • Ways: 1 red from 1, 1 white from 3: (11)(31)=3\binom{1}{1}\binom{3}{1}=3(11​)(13​)=3

  • So P(E∣Box 3)=315=15P(E|\text{Box 3}) = \frac{3}{15} = \frac{1}{5}P(E∣Box 3)=153​=51​

Step 3: Total Probability of Event EEE

P(E)=13⋅215+13⋅615+13⋅315=13(2+6+315)=13⋅1115=1145P(E) = \frac{1}{3}\cdot\frac{2}{15} + \frac{1}{3}\cdot\frac{6}{15} + \frac{1}{3}\cdot\frac{3}{15} = \frac{1}{3}\left(\frac{2+6+3}{15}\right) = \frac{1}{3}\cdot\frac{11}{15} = \frac{11}{45}P(E)=31​⋅152​+31​⋅156​+31​⋅153​=31​(152+6+3​)=31​⋅1511​=4511​

Step 4: Bayes’ Theorem – Probability It Came from Box 1

P(Box 1∣E)=13⋅2151145=2451145=211P(\text{Box 1}|E) = \frac{\frac{1}{3}\cdot\frac{2}{15}}{\frac{11}{45}} = \frac{\frac{2}{45}}{\frac{11}{45}} = \frac{2}{11}P(Box 1∣E)=4511​31​⋅152​​=4511​452​​=112​

The required probability is 211\frac{2}{11}112​.


Example 4: Bridge Collapse – Wrong Design or Inferior Material

Setup: A bridge may collapse due to wrong designing (WD) or inferior material (IM). Given:

  • Probability of wrong designing: P(WD)=10%=0.10P(WD) = 10\% = 0.10P(WD)=10%=0.10

  • Hence P(IM)=1−0.10=0.90P(IM) = 1 - 0.10 = 0.90P(IM)=1−0.10=0.90

  • If designing is wrong, probability of collapse: P(Collapse∣WD)=95%=0.95P(\text{Collapse} | WD) = 95\% = 0.95P(Collapse∣WD)=95%=0.95

  • If inferior material, probability of collapse: P(Collapse∣IM)=45%=0.45P(\text{Collapse} | IM) = 45\% = 0.45P(Collapse∣IM)=45%=0.45

Question: The bridge collapsed. Find the probability that it was due to wrong designing.

Step 1: Define Events and Given Probabilities

  • CCC = collapse

  • P(WD)=0.10P(WD)=0.10P(WD)=0.10, P(IM)=0.90P(IM)=0.90P(IM)=0.90

  • P(C∣WD)=0.95P(C|WD)=0.95P(C∣WD)=0.95, P(C∣IM)=0.45P(C|IM)=0.45P(C∣IM)=0.45

Step 2: Total Probability of Collapse

P(C)=P(WD)P(C∣WD)+P(IM)P(C∣IM)P(C) = P(WD)P(C|WD) + P(IM)P(C|IM)P(C)=P(WD)P(C∣WD)+P(IM)P(C∣IM)
=(0.10)(0.95)+(0.90)(0.45)=0.095+0.405=0.500= (0.10)(0.95) + (0.90)(0.45) = 0.095 + 0.405 = 0.500=(0.10)(0.95)+(0.90)(0.45)=0.095+0.405=0.500

Step 3: Bayes’ Theorem – Probability of Wrong Designing Given Collapse

P(WD∣C)=P(WD)P(C∣WD)P(C)=0.0950.500=0.19P(WD|C) = \frac{P(WD)P(C|WD)}{P(C)} = \frac{0.095}{0.500} = 0.19P(WD∣C)=P(C)P(WD)P(C∣WD)​=0.5000.095​=0.19

Thus the chance that the collapse was due to wrong designing is 0.190.190.19 (or 19%19\%19%).

Key insight: Even though faulty designs are much more likely to cause collapse (95% vs 45%), the prior probability of bad design is only 10%. So after observing a collapse, the posterior probability that design was at fault is only 19%.


Example 5: Coins – True vs False (Two-Headed)

Setup: There are 3 true coins (one head, one tail) and 1 false coin (heads on both sides). A coin is chosen at random and tossed 4 times. Heads appear all 4 times.

Question: What is the probability that the chosen coin was the false coin?

Step 1: Prior Probabilities

Total coins = 4, so:

P(True)=34,P(False)=14P(\text{True}) = \frac{3}{4},\quad P(\text{False}) = \frac{1}{4}P(True)=43​,P(False)=41​

Step 2: Conditional Probabilities of Getting 4 Heads

Let H4H_4H4​ = “4 heads in 4 tosses”.

  • For a true coin: probability of head in one toss = 1/21/21/2. Tosses independent, so P(H4∣True)=(12)4=116P(H_4|\text{True}) = \left(\frac{1}{2}\right)^4 = \frac{1}{16}P(H4​∣True)=(21​)4=161​.

  • For the false coin (heads on both sides): every toss yields heads for sure, so P(H4∣False)=1P(H_4|\text{False}) = 1P(H4​∣False)=1.

Step 3: Total Probability of Getting 4 Heads

P(H4)=P(True)P(H4∣True)+P(False)P(H4∣False)P(H_4) = P(\text{True})P(H_4|\text{True}) + P(\text{False})P(H_4|\text{False})P(H4​)=P(True)P(H4​∣True)+P(False)P(H4​∣False)
=34⋅116+14⋅1=364+1664=1964= \frac{3}{4}\cdot\frac{1}{16} + \frac{1}{4}\cdot 1 = \frac{3}{64} + \frac{16}{64} = \frac{19}{64}=43​⋅161​+41​⋅1=643​+6416​=6419​

Step 4: Bayes’ Theorem – Probability It Is the False Coin

P(False∣H4)=14⋅11964=14⋅6419=1619P(\text{False}|H_4) = \frac{\frac{1}{4}\cdot 1}{\frac{19}{64}} = \frac{1}{4} \cdot \frac{64}{19} = \frac{16}{19}P(False∣H4​)=6419​41​⋅1​=41​⋅1964​=1916​

The required probability is 1619\frac{16}{19}1916​ (approximately 0.8421).

Observation: Even though the false coin is only 1 out of 4 coins, seeing four heads makes it very likely (about 84%) that we picked the false coin.


Summary of Bayes’ Theorem Workflow

  1. Identify the partition: a set of mutually exclusive and exhaustive events B1,B2,…,BnB_1, B_2, \dots, B_nB1​,B2​,…,Bn​ (the “causes”).

  2. List the prior probabilities P(Bi)P(B_i)P(Bi​).

  3. List the conditional probabilities P(A∣Bi)P(A|B_i)P(A∣Bi​) of the observed event AAA under each cause.

  4. Compute total probability P(A)=∑P(Bi)P(A∣Bi)P(A) = \sum P(B_i)P(A|B_i)P(A)=∑P(Bi​)P(A∣Bi​).

  5. Apply Bayes’ theorem to find any posterior probability: $$P(B_i|A) = \frac{P(B_i)P(A|B_i)}{P(A)}$$

This framework is used across science, engineering, machine learning, and decision making to update beliefs with evidence.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent