Bayes' Theorem, named after Rev. Thomas Bayes, describes the relationship between the conditional probability of two events $A$ and $B$ as follows:

$\mathbb{P}\left(A\mid B\right)=\frac{\mathbb{P}\left(B\mid A\right)\mathbb{P}\left(A\right)}{\mathbb{P}\left(B\right)}$

or

$\mathbb{P}\left(A\mid B\right)=\frac{\mathbb{P}\left(B\mid A\right)\mathbb{P}\left(A\right)}{\mathbb{P}\left(B\mid A\right)\mathbb{P}\left(A\right)+\mathbb{P}\left(B\mid \stackrel{‾}{A}\right)\mathbb{P}\left(\stackrel{‾}{A}\right)}$

Example:

In a certain country, it is known that 2% of the population suffer from a certain disease. A clinical test yields a correct positive result of a person carrying the disease 97% of the cases. However, when a person not carrying the disease is subjected to the same test, 9% of all the cases, the test will yield a false positive result.

If a random person from that country takes the test and get a positive result, what is the probability that he is really carrying the disease?

Intuitively, we may think that there's a very good chance that he's carrying the disease, since the test yield 97% correct positive result. However, let's look at the math.

Let us represent the information above as follows:

• $B$ = The event that the test yields a positive result.
• $\stackrel{‾}{B}$ = The event that the test yields a negative result.
• $A$ = The event that a person is carrying the disease
• $\stackrel{‾}{A}$ = The event that a person is not carrying the disease.

We also know the following probabilities:

• $\mathbb{P}\left(A\right)=2%$
• $\mathbb{P}\left(\stackrel{‾}{A}\right)=98%$
• $\mathbb{P}\left(B\mid A\right)=97%$
• $\mathbb{P}\left(B\mid \stackrel{‾}{A}\right)=9%$

Using the formula for conditional probability, we can then summarize the probabilities of the events in the following table:

$A$ (2%) $\stackrel{‾}{A}$ (98%)
$B$ True Positive $\begin{array}{rl}\mathbb{P}\left(B\cap A\right)& =\mathbb{P}\left(A\right)×\mathbb{P}\left(B\mid A\right)\\ & =2%×97%\\ & =1.94%\end{array}$ False Positive $\begin{array}{rl}\mathbb{P}\left(B\cap \stackrel{‾}{A}\right)& =\mathbb{P}\left(\stackrel{‾}{A}\right)×\mathbb{P}\left(B\mid \stackrel{‾}{A}\right)\\ & =98%×9%\\ & =8.82%\end{array}$
$\stackrel{‾}{B}$ False Negative $\begin{array}{rl}\mathbb{P}\left(\stackrel{‾}{B}\cap A\right)& =\mathbb{P}\left(A\right)×\mathbb{P}\left(\stackrel{‾}{B}\mid A\right)\\ & =2%×3%\\ & =0.06%\end{array}$ True Negative $\begin{array}{rl}\mathbb{P}\left(\stackrel{‾}{B}\cap \stackrel{‾}{A}\right)& =\mathbb{P}\left(\stackrel{‾}{A}\right)×\mathbb{P}\left(\stackrel{‾}{B}\mid \stackrel{‾}{A}\right)\\ & =98%×91%\\ & =89.18%\end{array}$

Now, suppose a person was tested positive, what is the probability that he is really carrying the disease?
In other words, we are trying to find the probability of $A$, given $B$ or $\mathbb{P}\left(A\mid B\right)$.

From the table above, we can see that $\mathbb{P}\left(A\mid B\right)$ is really the probability of true positive divided by the probability of getting any positive result. That is

$\frac{1.94%}{1.94%+8.82%}=18.03%$

We can also get this result by using the above Bayes' Theorem formula:

$\begin{array}{rl}\mathbb{P}\left(A\mid B\right)& =\frac{\mathbb{P}\left(B\mid A\right)\mathbb{P}\left(A\right)}{\mathbb{P}\left(B\mid A\right)\mathbb{P}\left(A\right)+\mathbb{P}\left(B\mid \stackrel{‾}{A}\right)\mathbb{P}\left(\stackrel{‾}{A}\right)}\\ & =\frac{97%×2%}{\left(97%×2%\right)+\left(9%×98%\right)}\\ & =\frac{1.94%}{1.94%+8.82%}\\ & =\frac{1.94%}{10.76%}\\ & =18.03%\end{array}$

This result may seems counter-intuitive. The probability that the person tested positive is actually carrying the disease is not as high as we may think. There's only about 18% chance that the person is really carrying the disease.

Why is this so?

In estimating the probability, we often forget that the percentage of the population carrying the disease is small in the first place (i.e. only 2% of the population suffers the disease). So even though the test is highly accurate for people with the disease, it doesn't mean that if the person is tested positive, there will be a high chance that he or she is really carrying the disease.

We can look at it this way. Suppose there are only 1000 people in that country. Only 20 people suffer the disease (2%). 19 of those 20 will get a positive test result (97% true positive result). Of the other 980 people not suffering the disease, about 88 people (9% false positive result) will also get positive test result.

So from the 1000 people, we can group them as follows

• 19 people get true positive results
• 1 person gets false negative result
• 88 people get false positive results
• 892 people get true negative results

From the above, we gather that about (88 + 19) = 107 people will get positive results (regardless of whether they suffer the disease or not). From these 107, how many of them are really carrying the disease? Only 19 out of 107 (or about 18%).