# Bayes theorem tricky example

In a certain population, 1% of people have a particular rare disease. A diagnostic test for this disease is known to be 95% accurate when a person has the disease and 90% accurate when a person does not have the disease. If a person tests positive, what is the probability that they actually have the disease?

I was trying: first let's define: $$P(p) =$$ probability of person test positive $$P(d) =$$probability of a person having disease,

$$P(d|p) = \frac{P(d)P(p|d)}{P(d)P(p|d)+P(h)P(h|d)} = \frac{(0.01)(0.95)}{(0.01)(0.95)+(0.99)(0.90)}$$

where $$P(h)$$ is the probability of being healthy and P(h|d) is the probability of being healthy and being classified as sick. Did I set up the formula correctly?

• No. The two ways to test positive are $1:$ have the disease and get an accurate test. and $2:$ be healthy and get an inaccurate test. Thus the numerator is $P(d)\times P(p\,|\,d)$ as you say but the denominator should be that plus $P(h)\times P(p\,|\,h)$ . Thus the second term in the denominator should be $.99\times .1$.
– lulu
Commented May 23 at 18:21
• A good mental exercise: take extreme cases. Suppose that the test was perfect for healthy people. This is, suppose the $90\%$ were $100%$. Then, no healthy person ever tests positive so a positive test result is proof that the patient has the disease. But your formula does not give $1$ in that case.
– lulu
Commented May 23 at 18:22
• @lulu Thank you nice mental excersice Commented May 23 at 18:26

In a certain population, 1% of people have a particular rare disease. A diagnostic test for this disease is known to be 95% accurate when a person has the disease and 90% accurate when a person does not have the disease. If a person tests positive, what is the probability that they actually have the disease?

$$P(d|p) = \frac{P(d)P(p|d)}{P(d)P(p|d)+P(h)P(h|d)} = \frac{(0.01)(0.95)}{(0.01)(0.95)+(0.99)(0.90)}$$

where $$P(h)$$ is the probability of being healthy and P(h|d) is the probability of being healthy and being classified as sick. Did I set up the formula correctly?

As indicated by the comments, you have an analytical mistake. Also, I saw what looks like a typo in your equation. Further, it looks like you are over-loading the variable $$~d~$$ to represent both having the disease and testing positive for the disease.

Let $$~d~$$ denote the event that you have the disease.
This implies that $$~p(d) = 0.01.$$

Let $$~h~$$ denote the event that you do not have the disease.
This implies that $$~p(h) = 1 - p(d) = 0.99.$$

Let $$~t~$$ denote the event that you test positive for the disease. This can happen in one of two ways:

• Either you have the disease and got a true positive.
This is expressed as
$$p(d) \times p(t|d) = (0.01 \times 0.95).$$

• Or you do not have the disease and got a false positive.
This is expressed as
$$p(h) \times p(t|h) = [ ~0.99 \times (1 - 0.90) ~] = [ ~0.99 \times 0.10 ~].$$

Using the syntax that $$~p(E_1,E_2)~$$ represents that events $$~E_1~$$ and $$~E_2~$$ simultaneously occur, then the desired equation is :

$$p(t) \times p(d|t) = p(d,t) \implies$$

$$p(d|t) = \frac{p(d,t)}{p(t)}$$

$$= \frac{p(d) \times p(t|d)}{[ ~p(d) \times p(t|d) ~] + [ ~p(h) \times p(t|h) ~]}$$

$$= \frac{(0.01) \times (0.95)}{[ ~(0.01) \times (0.95) ~] + [ ~(0.99) \times (0.10) ~]}.$$

If you find this problem "tricky", I'd encourage you to start with what is the "baby" form of Bayes' Rule, and proceed step by step

Using your terminology to avoid confusion, let's define the events

p = test positive
d = diseased
h = healthy

Then $$P(d\mid p) = \dfrac{P(d \cap p )}{P(p)} = \dfrac{P(d \cap p)}{P(d \cap p )+ P(h \cap p )}$$

$$= \dfrac {P(d).P(p\mid d)}{P(d).P(p\mid d) + P(h).P(p\mid h)}$$

$$= \dfrac{0.01 \times 0.95}{ (0.01 \times 0.95) + (0.99 \times 0.10) }, \approx 8.76 \%$$