Bayes' Theorem is a mathematical formula/ Tool used for calculating conditional probabilities. To the uninformed on conditional probability is finding probability of one even occurring with prior knowledge of other event which has already occurred.

Let $A$ and $B$ be two events and say if event $A$ has already occurred to find the probability of the Event $B$ occurring knowing that $A$ has already occurred. Probability of the event $A$ is based on the condition about event $B$ occurring is known as the Conditional probability and written as

$P(A \mid B)$ = $\frac{P(A\cap B)}{P(B)}$ ; $P(B) \neq 0$

We can also rewrite $P(A \cap B)$ = $P(B)\ P(A \mid B)$ using Multiplication rule of Probability

Now knowing what conditional probability is let us define what is Baye’s theorem and how to use it.

Let $A_1,\ A_2,..\ A_n$ be n mutually exclusive and exhaustive events in a Sample Space $S$ such that $P(A_i) > 0$ for $i$ = $1, 2,…,\ n$. Let $B$ be any event with $P(B) > 0$ then

$P(A_i \mid B)$ = $\frac{P(A_i \cap B)}{ P(A_1 \cap B) + P(A_2 \cap B) + P(A_3 \cap B) + ............ + P(A_n \cap B)}$

$P(A_i \mid B)$ = $\frac{P(A_i) P(B \mid (A_i) )}{ P(P(A_1) P(B \mid A_1) + P(A_2) P(B \mid A_2) + P(A_3) P(B \mid A_3) + ......... + P(A_n) P(B \mid A_n)}$

Related Calculators | |

Bayes Theorem Calculator | Calculation of Probability |

Binomial Theorem Calculator | Calculate Pythagorean Theorem |

In a factory there are two Machines, Machine $A$ and Machine $B$ producing an Item. We are told that Machine $A$ produces $30 \%$ of the items and $3 \%$ of the items were defective. Machine $B$ produces $70 \%$ of the item and $4 \%$ of items produced by Machine $B$ are defective. If an item is drawn and found to be defective. What is the probability that Machine $B$ produced it.

Problem like these make use of the Bayes theorem.

Let us see how we can use it.

Let us check if we can partition the sample space to mutually exclusive and exhaustive partitions.

Let $A_1$ be the event of producing items on Machine $A$.

Let $A_2$ be the event of producing items on Machine $B$.

Let $B$ be the event of drawing a defective item.

We can partition $B$ with $A_1 \cap B$ and $A_2 \cap B$

Together they would cover the whole event $B$ and they are mutually exclusive and exhaustive.

We already have selected a defective item to know if it is Machine $B$ producing it.

The formula can be written as

$P(A_i \mid B)$ = $\frac{P(A_i) P(B\ (A_i) )}{ P(P(A_1) P(B \mid A_1) + P(A_2) P(B \mid A_2) + P(A_3) P(B \mid A_3) + ......... + P(A_n) P(B \mid A_n}$

$P(A_i \mid B)$ = $\frac{P(A_i) P(B\ (A_i) )}{ P(P(A_1) P(B \mid A_1) + P(A_2) P(B \mid A_2) + P(A_3) P(B \mid A_3) + ......... + P(A_n) P(B \mid A_n}$

Note the denominator would depend on the number of events.

$P(A_1)$ = $0.3$ and $P(B \mid A_1)$ = $0.03$

$P(A_2)$ = $0.7$ and $P(B \mid A_2)$ = $0.04$

Now to apply in our formula

$P(A_2 \mid B)$ = $\frac{(0.7)(0.004)}{(0.3)(0.03) + (0.7)(0.04)}$

$P(A_2 \mid B)$ = $\frac{0.028}{0.09+0.028}$ = $\frac{0.028}{0.037}$ = $0.7568$

$P(A_2 \mid B)$ = $\frac{(0.7)(0.004)}{(0.3)(0.03) + (0.7)(0.04)}$

$P(A_2 \mid B)$ = $\frac{0.028}{0.09+0.028}$ = $\frac{0.028}{0.037}$ = $0.7568$

This tells us the probability of the defective item manufactured by Machine $B$ is $75.68 \%$

Let $A_1, A_2,.. A_n$ be n mutually exclusive and exhaustive events in a Sample Space $S$ such that $P(A_i) > 0$ for $i$ = $1, 2, … n$. Let $B$ be any event with $P(B) > 0$ then

$P(A \mid B)$ = $\frac{P(A\cap B)}{P(B)}$ ; $P(B) \neq 0$

$P(A_i \mid B)$ = $\frac{P(A_i \cap B}{ P(A_1 \cap B) + P(A_2 \cap B) + P(A_3 \cap B) + ............ + P(A_n \cap B}$

$P(A_i \mid B)$ = $\frac{P(A_i) P(B\ (A_i) )}{ P(P(A_1) P(B \mid A_1) + P(A_2) P(B \mid A_2) + P(A_3) P(B \mid A_3) + ......... + P(A_n) P(B \mid A_n}$

The conditional probability of the event $A$, given that the event $B$ has already occurred is

The conditional probability of the event $A$, given that the event $B$ has already occurred is

$P(A \mid B)$ = $\frac{P(A\cap B)}{P(B)}$ ; $P(B) \neq 0$

If $A$ can be partitioned in to $n$ events and $B$ can be partitioned with exhaustive and exclusive events of $A$.

Then $B$ = $(A_1 \cap B) \cup (A_2 \cap B) \cup .........\cup (A_n \cap B)$

$P(B)$ = $P(A_1 \ cap B) + P(A_2 \cap B) +........ + P(A_n \cap B)$ Note: we can apply addition rule of probability and since they are mutually exclusive there is no intersection between them.

For any $i$ we can write

$P(A_i \mid B)$ = $\frac{P(A_i \cap B)}{P(B)}$

We can replace $P(B)$ with what we have found

We can replace $P(B)$ with what we have found

$P(A_i \mid B)$ = $\frac{P(A_i \cap B}{ P(A_1 \cap B) + P(A_2 \cap B) + P(A_3 \cap B) + ............ + P(A_n \cap B}$

That completes our proof. To get the Baye’s theorem in the other form we can rewrite with multiplicative rule of probability.

A firm rents car from three car rental agencies such that $20 \%$ from agency $P,\ 30 \%$ from agency $Q$ and $50 \%$ from agency $R$. If $90 \%$ of the cars from $P,\ 80 \%$ of cars from $Q$ and $95 \%$ of the cars from $R$ are in good conditions If a car received is in good condition, what is probability that it has came from agency $Q$?

Let $A_1, A_2, A_3$ be the events of renting the cars from $P, Q$ or $R$.

Let $B$ be the event of getting the car in good condition.

We can partition $B$ with combinations of $A_1, A_2, A_3$ which is exhaustive and covers the entire $B$.

We have the partitions as $(A_1 \cap B),\ (A_2 \cap B),\ (A_3 \cap B)$ we can see $(A_1 \cap B) \cup (A_2 \cap B) \cup (A_3 \cap B)$ = $B$

When these conditions satisfy we can apply the Bayes formula (Theorem)

$P(A_2 \mid B)$ = $\frac{P(A_2) P(B \mid A_2)}{ P(P(A_1) P(B \mid A_1) + P(A_2) P(B \mid A_2) + P(A_3) P(B \mid A_3)}$

Remember we discussed that the number of terms in the denominators is equal to number of partition we got.

Let us continue

$P(A_1)$ = $0.2$ and $P(B| A_1)$ = $0.9$

$P(A_2)$ = $0.3$ and $P(B| A_2)$ = $0.8$

$P(A_3)$ = $0.5$ and $P(B| A_3)$ = $0.95$

$P(A_2 \mid B)$ = $\frac{(0.3)(0.8)}{(0.2)(0.9)+ (0.3)(0.8) + (0.5)(0.95)}$

$P(A_2 \mid B)$ = $\frac{(0.24)}{0.19 + (0.24) + (0.475)}$

$P(A_2 \mid B)$ = $\frac{(0.24)}{0.895)}$

= $0.2682$

Probability that the good condition car comes from Agency $Q$ is $26.82 \%$