Bayes' Formula
More examples:
- In a certain country, $1\%$ of the population has a disease. The test has $99\%$ sensitivity and $95\%$ specificity. Let $D$: "person has disease" and $T$: "test is positive". What percentage of people has the disease given that the test turned out positive?
Solution: $P(D \mid T) = \frac{P(T \mid D) P(D)}{P(T \mid D) P(D) + P(T \mid D') P(D')} = \frac{0.99 \cdot 0.01}{0.99 \cdot 0.01 + 0.05 \cdot 0.99} \approx 0.166$.
- In an email server, $40\%$ of emails are spam. Among spam, $30\%$ include "win". Among non-spam, $5\%" include "win". Given "win" is in the email, what's the probability that it is spam?
Solution: $P(\text{spam} \mid \text{contains "win"}) = \frac{0.30 \cdot 0.40}{0.30 \cdot 0.40 + 0.05 \cdot 0.60} \approx 0.8$.
- Bag $A$ has $2$ red and $3$ blue marbles. Bag $B$ has $4$ red and $1$ blue marbles. One bag is chosen at random, and a red marble is drawn. What is the probability that it came from bag $A$?
Solution: $P(\text{bag}\ A \mid \text{red}) = \frac{P(\text{red} \mid \text{bag}\ A) P(\text{bag}\ A)}{P(\text{red} \mid \text{bag}\ A) P(\text{bag}\ A) + P(\text{red} \mid \text{not bag}\ A) P(\text{not bag}\ A)} = \frac{(2/5)(1/2)}{(2/5)(1/2) + (4/5)(1/2)} = \frac{2}{6} = \frac{1}{3}$.