Example 1: Medical Diagnosis
Suppose a rare disease, "X," affects 1% of the population. There is a medical
test for this disease that is 95% accurate for both positive and negative
results. If a person tests positive for the disease, what is the probability that
they actually have it?
Solution:
Let's define the events:
A: Having the disease (1% chance, P(A) = 0.01)
B: Testing positive for the disease (conditional probability, P(B|A) =
0.95)
We want to find P(A|B), the probability of having the disease given a
positive test result. Using Bayes' theorem:
P(A|B) = [P(B|A) * P(A)] / P(B)
P(B) can be calculated using the law of total probability:
P(B) = P(B|A) * P(A) + P(B|¬A) * P(¬A)
P(B|¬A) is the probability of testing positive given that you don't have the
disease, which is the false positive rate. In this case, it's 5% (0.05).
P(¬A) is the probability of not having the disease, which is 99% (1 - 0.01).
Now, plug these values into the formula:
P(B) = (0.95 * 0.01) + (0.05 * 0.99) = 0.0149
Now, use Bayes' theorem to find P(A|B):
P(A|B) = (0.95 * 0.01) / 0.0149 ≈ 0.637
So, if a person tests positive for the disease, the probability that they
actually have it is approximately 63.7%.
Example 2: Email Spam Detection
Suppose you receive an email with certain keywords commonly found in
spam emails. If 90% of spam emails contain those keywords, but only 10%
of legitimate emails do, and you know that 30% of the emails in your inbox
are spam, what's the probability that an email containing these keywords is
spam?
Solution:
Let's define the events:
A: The email contains the keywords (P(A) = ?)
B: The email is spam (P(B) = 0.30)
¬B: The email is not spam (P(¬B) = 0.70)
P(A|B) = 0.90 (probability that a spam email contains the keywords)
P(A|¬B) = 0.10 (probability that a legitimate email contains the
keywords)
We want to find P(B|A), the probability that the email is spam given that it
contains the keywords. Using Bayes' theorem:
P(B|A) = [P(A|B) * P(B)] / P(A)
Now, we need to calculate P(A):
P(A) = P(A|B) * P(B) + P(A|¬B) * P(¬B) P(A) = (0.90 * 0.30) + (0.10 * 0.70) =
0.27 + 0.07 = 0.34
Now, use Bayes' theorem to find P(B|A):
P(B|A) = (0.90 * 0.30) / 0.34 ≈ 0.794
So, if an email contains the keywords, the probability that it's spam is
approximately 79.4%.
Example 3: Weather Prediction
Suppose a meteorologist predicts that there is a 70% chance of rain on a
given day. However, historical data shows that the meteorologist is correct
only 60% of the time when predicting rain and 90% of the time when
predicting no rain. What's the probability that it will rain given the
meteorologist's prediction?
Solution:
Let's define the events:
A: It rains (P(A) = ?)
B: Meteorologist predicts rain (P(B) = 0.70)
¬B: Meteorologist predicts no rain (P(¬B) = 0.30)
P(A|B) = 0.60 (probability of correct rain prediction)
P(A|¬B) = 0.90 (probability of correct no-rain prediction)
We want to find P(A|B), the probability that it will rain given the
meteorologist's prediction. Using Bayes' theorem:
P(A|B) = [P(B|A) * P(A)] / P(B)
Now, we need to calculate P(B):
P(B) = P(B|A) * P(A) + P(B|¬A) * P(¬A) P(B) = (0.60 * P(A)) + (0.30 * (1 - P(A)))
We know that P(A) + P(¬A) = 1, so P(¬A) = 1 - P(A). Substituting this into
the equation:
P(B) = (0.60 * P(A)) + (0.30 * (1 - P(A)))
Now, we can use the fact that P(B) = 0.70:
0.70 = (0.60 * P(A)) + (0.30 * (1 - P(A)))
Solve for P(A):
0.70 = 0.60P(A) + 0.30 - 0.30P(A) 0.40P(A) = 0.40 P(A) = 0.40 / 0.40 P(A) = 1
Now that we know P(A) is 1, we can use Bayes' theorem to find P(A|B):
P(A|B) = (0.60 * 1) / 0.70 ≈ 0.857
So, if the meteorologist predicts rain, the probability that it will rain is
approximately 85.7%.
Example 1: Medical Diagnosis
Suppose a rare disease, "Disease X," affects 1% of the population. A
diagnostic test for Disease X is not perfect, with a false positive rate of 5%
and a false negative rate of 2%. If a randomly selected person tests positive
for Disease X, what is the probability that they actually have the disease?
Solution: Let A be the event that a person has Disease X, and B be the event
that the test result is positive. We want to find P(A | B), the probability that
a person has the disease given a positive test result.
Using Bayes' Theorem: P(A∣B)=P(B)P(B∣A)∗P(A)
P(B | A) = Probability of a positive test result given that a person has the
disease = 1 - False Negative Rate = 1 - 0.02 = 0.98 P(A) = Prior probability
of having the disease = 0.01 P(B) = Total probability of a positive test result
= P(B | A) * P(A) + P(B | ¬A) * P(¬A) = (0.98 * 0.01) + (0.05 * 0.99) ≈ 0.0587
Now, calculate P(A | B): P(A∣B)=0.05870.98∗0.01≈0.1668
So, given a positive test result, the probability that a person actually has
Disease X is approximately 16.68%.
Example 2: Email Spam Detection
Suppose you receive an email, and your spam filter has previously
determined that 90% of spam emails contain the word "free," while only
10% of legitimate emails contain this word. If the email you received
contains the word "free," what is the probability that it's spam?
Solution: Let A be the event that an email is spam, and B be the event that
the email contains the word "free." We want to find P(A | B), the probability
that the email is spam given that it contains the word "free."
Using Bayes' Theorem: P(A∣B)=P(B)P(B∣A)∗P(A)
P(B | A) = Probability of an email containing "free" given that it's spam =
0.90 P(A) = Prior probability of an email being spam = 0.50 (assuming a
50% spam rate) P(B) = Total probability of an email containing "free" = P(B |
A) * P(A) + P(B | ¬A) * P(¬A) = (0.90 * 0.50) + (0.10 * 0.50) = 0.50
Now, calculate P(A | B): P(A∣B)=0.500.90∗0.50=0.90
So, if an email contains the word "free," the probability that it's spam is
90%.
Example 3: Coin Toss
Suppose you have two coins in a bag. Coin A is a fair coin (50% chance of
heads), while Coin B is biased (80% chance of heads). You randomly choose
one of the coins and toss it, and it comes up heads. What is the probability
that you chose Coin B?
Solution: Let A be the event of choosing Coin A, and B be the event of
choosing Coin B. Let H be the event of getting heads. We want to find P(B |
H), the probability that you chose Coin B given that you got heads.
Using Bayes' Theorem: P(B∣H)=P(H)P(H∣B)∗P(B)
P(H | B) = Probability of getting heads with Coin B = 0.80 P(B) = Probability
of choosing Coin B = 0.50 (assuming an equal chance of choosing either
coin) P(H) = Total probability of getting heads = P(H | A) * P(A) + P(H | B) *
P(B) = (0.50 * 0.50) + (0.80 * 0.50) = 0.65
Now, calculate P(B∣H)=0.650.80∗0.50≈0.6154
So, if you got heads, the probability that you chose Coin B is approximately
61.54%.
1. Medical Diagnosis: Suppose a medical test is used to detect a rare
disease, and the test is known to have a 95% accuracy rate (true
positive rate). However, the test also produces false positives 10% of
the time. If the prevalence of the disease in the population is 2%, you
can use Bayes' theorem to calculate the probability that a person
actually has the disease given that they tested positive.
P(Disease) = 0.02 (prevalence) P(Positive | Disease) = 0.95 (true
positive rate) P(Positive | No Disease) = 0.10 (false positive rate)
Using Bayes' theorem: P(Disease | Positive) = [P(Positive | Disease) *
P(Disease)] / [P(Positive | Disease) * P(Disease) + P(Positive | No
Disease) * P(No Disease)]
Plug in the values: P(Disease | Positive) = [0.95 * 0.02] / [0.95 * 0.02 +
0.10 * 0.98] ≈ 0.1637 or 16.37%
So, the probability that a person actually has the disease given a
positive test result is approximately 16.37%.
2. Card Games: Consider a deck of cards. You draw a card at random,
but before showing it to you, someone tells you whether it's a red
card (heart or diamond) or a black card (spade or club). You want to
find the probability that the card is a heart given that it's red.
P(Heart) = 13/52 (number of hearts in a deck of 52 cards) P(Red) =
26/52 (number of red cards in a deck of 52 cards)
Using Bayes' theorem: P(Heart | Red) = [P(Red | Heart) * P(Heart)] /
P(Red)
Since P(Red | Heart) is 1 (if it's a heart, it's red), the formula simplifies
to: P(Heart | Red) = (1 * 13/52) / (26/52) = 0.5 or 50%
So, the probability that the card is a heart given that it's red is 50%.
3. Weather Prediction: Suppose a meteorologist predicts that there is
an 80% chance of rain when the sky is cloudy and a 20% chance of
rain when the sky is clear. On a given day, the sky is cloudy 60% of
the time and clear 40% of the time. You want to find the probability
of rain on that day.
P(Rain | Cloudy) = 0.80 (probability of rain when cloudy) P(Rain |
Clear) = 0.20 (probability of rain when clear) P(Cloudy) = 0.60
(probability of a cloudy day)
Using Bayes' theorem: P(Rain) = [P(Rain | Cloudy) * P(Cloudy)] +
[P(Rain | Clear) * P(Clear)]
Plug in the values: P(Rain) = (0.80 * 0.60) + (0.20 * 0.40) = 0.48 + 0.08
= 0.56 or 56%
So, the probability of rain on that day is 56%.