Test results are positive. What are the odds you have the virus? Surprise, intuition is wrong!

Bayes’s Theorem

This is pretty much a direct application of Bayes’s Theorem:

P(A|B) = P(A) * P(B|A) / P(B)

P(A) is the probability of event A (probability of having the disease, which is 0.01)

probability table

P(A|B) = P(A) * P(B|A) / P(B) = 0.01 * 0.99 / 0.0198 = 0.5

If you test positive, the likelihood of actually having the virus is 50%! That’s very counter-intuitive. You would expect it’s around 99%. What happened?

chances vs infection rate

How about real-world testing?

Does that mean testing is useless when rates are low? Actually no.

  • the overall infection rate is very low (1%), and
  • you’re picking test subjects completely at random (picking completely random people out of the general population, like literally pulling first name / last name out of a hat)

How about negative test results?

I wrote a follow-up which deals with the negative results. Read it here:

Credits and code

The images are free to use, via Unsplash. Credit links:

sick.chance <- function(inf.rate, test.rel = 0.99, tot.pop = 10000) {
sick.pop <- tot.pop * inf.rate
healthy.pop <- tot.pop - sick.pop
pos.sick <- sick.pop * test.rel
neg.healthy <- healthy.pop * test.rel
pos.healthy <- healthy.pop - neg.healthy
pos.total <- pos.sick + pos.healthy
chance <- pos.sick / pos.total
return(chance)
}
infection.rate <- 1:100 / 100
chances <- lapply(infection.rate, sick.chance)
plot(infection.rate, chances, col = 'blue'); grid()

--

--

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
Florin Andrei

Florin Andrei

65 Followers

Graduated Physics. Engineer in the computer industry. Working on my Master’s degree in Data Science.