## Bayes' Theorem

Bayes' theorem is stated mathematically as:

${\displaystyle P(A\mid B)={\frac {P(B\mid A)\,P(A)}{P(B)}},}$ where ${\displaystyle A}$ and ${\displaystyle B}$ are events and ${\displaystyle P(B)\neq 0}$ .

${\displaystyle P(A\mid B)}$ is a conditional probability: the likelihood of event ${\displaystyle A}$ occurring, given that ${\displaystyle B}$ is true.
${\displaystyle P(B\mid A)}$ is also a conditional probability: the likelihood of event ${\displaystyle B}$ occurring, given that ${\displaystyle A}$ is true.
${\displaystyle P(A)}$ and ${\displaystyle P(B)}$ are the marginal probabilities of observing ${\displaystyle A}$ and ${\displaystyle B}$ , independently of each other.

### Example: Drug testing

Suppose a blood test used to detect the presence of a particular banned drug is 99% sensitive and 99% specific. That is, the test will produce 99% true positive results for drug users and 99% true negative results for non-drug users. Suppose that 0.5% of people are users of the drug. What is the probability that a randomly selected individual who tests positive is a user?

{\displaystyle {\begin{aligned}P({\text{User}}\mid {\text{+}})&={\frac {P({\text{+}}\mid {\text{User}})P({\text{User}})}{P(+)}}\\&={\frac {P({\text{+}}\mid {\text{User}})P({\text{User}})}{P({\text{+}}\mid {\text{User}})P({\text{User}})+P({\text{+}}\mid {\text{Non-user}})P({\text{Non-user}})}}\\[8pt]&={\frac {0.99\times 0.005}{0.99\times 0.005+0.01\times 0.995}}\\[8pt]&\approx 33.2\%\end{aligned}}} Even if an individual tests positive, it is more likely than not (1 - 33.2% = 66.8%) that s/he does not use the drug. Why? Even though the test appears to be highly accurate, the number of non-users is very large compared to the number of users. Then, the count of false positives will outweigh the count of true positives.

To see this with actual numbers, if 1,000 individuals are tested, we expect 995 non-users and 5 users. Among the 995 non-users, 0.01 × 995 ≃ 10 false positives are expected. Among the 5 users, 0.99 × 5 ≈ 5 true positives are expected. Out of 15 positive results, only 5, ~33%, are genuine.

The importance of specificity in this example can be seen by calculating that even if sensitivity is improved to 100%, but specificity remains at 99%, then the probability that a person who tests positive is a drug user only rises from 33.2% to 33.4%. Alternatively, if sensitivity remains 99%, but specificity is improved to 99.5%, then the probability that a person who tests positive is a drug user rises to about 49.9%.

Text modified after Wikipedia, retrieved 2017 Nov 24