Premium problem73. Probability of Disease After a Positive Test

Easy Locked

A test has sensitivity (it catches a true case) and specificity (it clears a healthy one). The disease affects a prevalence fraction of people. Someone tests positive. Return the probability they actually have it.

The answer is usually far lower than people expect, because for a rare disease the false positives drawn from the huge healthy population outnumber the true positives.

P(D∣+)=sens⋅prevsens⋅prev+(1−spec)(1−prev)P(D \mid +) = \frac{\text{sens} \cdot \text{prev}}{\text{sens} \cdot \text{prev} + (1-\text{spec})(1-\text{prev})}

Input

prevalence = 0.001
sensitivity = 0.99
specificity = 0.99

Output

0.09016393442622944

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)