Labs 2 - Bayes` theorem

Labs 2
Bayes’ theorem
ZUI 2
Fakulta matematiky, fyziky a informatiky UK
ZUI 2 (FMFI UK)
Labs 2
1 / 10
Content
1
Bayes’ theorem
2
Example 1
3
Example 2
ZUI 2 (FMFI UK)
Labs 2
2 / 10
Bayes’ theorem
Bayes’ theorem
P(A|B) =
ZUI 2 (FMFI UK)
P(B|A)P(A)
P(B)
Labs 2
3 / 10
Bayes’ theorem
Bayes’ rule
Hypothesis–evidence view
P(H|E ) =
ZUI 2 (FMFI UK)
P(E |H)P(H)
P(E )
Labs 2
4 / 10
Example 1
Example 1
After your yearly checkup, the doctor has bad news and good news. The
bad news is that you tested positive for a serious disease, and that the test
is 99% accurate (i.e., the probability of testing positive given that you
have the disease is 0.99, as is the probability of testing negative given that
you don’t have the disease). The good news is that this is a rare disease,
striking only one in 10,000 people. Why is it good news that the disease is
rare? What are the chances that you actually have the disease?
ZUI 2 (FMFI UK)
Labs 2
5 / 10
Example 1
Example 1
Formalization
What do we know?
P(Test = true|Disease = true) = 0.99
P(Disease = true) = 0.00001
ZUI 2 (FMFI UK)
Labs 2
6 / 10
Example 1
Example 1
Formalization
What do we know?
P(Test = true|Disease = true) = 0.99
P(Disease = true) = 0.00001
What are we asking?
P(Disease = true|Test = true) =?
ZUI 2 (FMFI UK)
Labs 2
6 / 10
Example 1
Example 1
Solution
P(Disease = true|Test = true) =
P(Disease = true, Test = true)
P(Test = true)
P(+d, +t) = P(+t|d+)P(d+)
P(+t) =
X
P(+t|D)P(D) = P(+t| + d)P(+d) + P(+t| − d)P(−d)
d∈D
P(+d| + t) =
ZUI 2 (FMFI UK)
0.99 × 0.0001
≈ 0.009804
0.99 × 0.0001 + 0.01 × 0.9999
Labs 2
7 / 10
Example 2
Example 2
The disease meningitis causes the patient to have a stiff neck 50% of the
time. The prior probability that someone has meningitis is 1/50,000. The
prior that someone has a stiff neck is 1/20. Knowing that a person has a
stiff neck, what is the probability that they have meningitis?
ZUI 2 (FMFI UK)
Labs 2
8 / 10
Example 2
Example 1
Formalization
What do we know?
P(StiffNeck = true|Meningitis = true) = 0.99
P(Meningitis = true) = 0.00002
P(StiffNeck = true) = 0.00002
ZUI 2 (FMFI UK)
Labs 2
9 / 10
Example 2
Example 1
Formalization
What do we know?
P(StiffNeck = true|Meningitis = true) = 0.99
P(Meningitis = true) = 0.00002
P(StiffNeck = true) = 0.00002
What are we asking?
P(Meningitis = true|StiffNeck = true) =?
ZUI 2 (FMFI UK)
Labs 2
9 / 10
Example 2
Example 2
Solution
Applying Bayes’ theorem:
P(+m| + s) =
P(+m| + s) =
ZUI 2 (FMFI UK)
P(+s| + d)P(+d)
P(+s)
0.5 × 0.00002
= 0.002
0.05
Labs 2
10 / 10