Why testing positive for a disease may not mean you are sick. Visualization of the Bayes Theorem and Conditional Probability.

Javier GB
Javier GB
Aug 7, 2015 · 4 min read

The Bayes Theorem describes the probability of an event happening, taking into consideration the conditions that can affect it. For example: the number of HIV+ people are 1 in 250, the probability of testing positive if you are healthy is around 1%. Then the probability of being actually HIV+ if you test positive is only 30%. Seems counter-intuitive. The intuition is that there are so many more healthy people than sick that most of the positive results are false positives. But I’ll explain the Bayes Theorem with drawings.

Let’s use the following example, where 1 in 10 people are sick. We denote could write p(Sick | Total population) = the probability of being sick given that you study the whole population = 0.1. But in the case when you study the whole population you just write p(Sick).

Image for post
Image for post

To simplify the example we assume that we know which ones are sick and which ones are healthy, but in a real test you don’t know that information. Now we test everybody for the disease:

Image for post
Image for post

The number of positive results among the sick population (#(Positive | Sick) is 9. These people are the true positives, a value that it’s known for tests:

Now the interesting question, what is the probability of being sick if you test positive? (in math: p(Sick | Positive))

Image for post
Image for post

In the figure above we have all the information, and therefore we can count the sick people among the positive results to say that the probability of being sick if you tested positive is 9/18 = 50%. However in real life you only know that 18/100 have tested positive. To know that 50% of those are false positives you can use the Bayes Theorem. But we will derive it here. All the information we know is:

Image for post
Image for post
Image for post
Image for post

To remind you, we want to calculate the people inside the square #(Sick | Positive).

The intuition is that if we know that there are 10 sick people (#(Sick)) and the true positive rate is 0.9, then #(Sick | Positive) = 9.

In math:

Image for post
Image for post

For the probability we divide among the studied population (the positive results) to get:

Image for post
Image for post

But we don’t know exactly how many people are sick, only the probability, so we can divide both parts of the fraction by the #(Total) and get probabilities of being sick and of testing positive.

Image for post
Image for post

And you have successfully derived the Bayes Theorem!

Image for post
Image for post

To recap:

Image for post
Image for post

Real example

Let’s use now a real example, the HIV, 1 in 250 people have the virus, and the test is positive for 99% of the sick people and 1% of the healthy people.

We have that p(Positive) = (0.99*1 + 0.01*249)/250 = 0.01392.

Image for post
Image for post

Only 1 in 3 positives are real. That’s the reason why they test every positive several times.

Other uses of Bayes

Let’s use another example. Imagine you have a collection of books by five authors (Cervantes, King, Carrol, Brown and Follet). Each book is written majoritarily in a verb tense and you know the probability that a given author uses a specific verb tense.

You take a random book from the collection and it’s written in present. Which author has written it?

Image for post
Image for post

The probability that Cervantes has written it is:

Image for post
Image for post

Sometimes you don’t know p(Present), i.e. the number of books in present in your collection. However, given that p(Present) is constant for all the authors you can still compare among them:

Image for post
Image for post

This is called the Bayes factor, and values above 5 are considered substantial evidence, above 10 strong and above 100 decisive.

Stay tuned!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store