DEV Community

Artik Blue
Artik Blue

Posted on

Covid19 tests and Thomas Bayes

Bayes theorem

Created by reverent Thomas Bayes, who created this famous rule to infere the existence of God... needless to say that the existence of God is still in the realm of faith but his famous rule has became the very fundamentals of inference probability

The bayes theorem can be written as the following:

Alt Text

Do you remember the covid detection example we had in the last tutorial?

We want to know the probabilitty for one person of having covid if he or she had tested positive

We have the on average probability for a random individual of having covid or not

p(covid) = 0.01
p(¬covid) = 0.99

Then we have this test we just bought that goes:

90% of the time outputs POSITIVE if you have covid

But also

90% of the time marks NEGATIVE ig you don't have it

So we can mind our problem the following way:

P(C | POS) = P(C) * P(POS|C)
P(¬C | POS) = P(¬C) * P(POS|¬C)

In this case P(C | POS) will be the probability of having covid given a positive test result, and P(POS|C) the probability of having a positive test result giving that the patient actually has covid, it is important to mark those concepts as sometimes we may get confused on what do they represent.

So let's compute them on our case.

P(C | POS) = P(C) * P(POS|C) = 0.01 * 0.9 = 0.009

And

P(¬C | POS) = P(¬C) * P(POS|¬C) = 0.099

But as you might have seen, those probabilities don't add up to one, they should be somehow complementary right? Given a positive test if we don't have covid, then we have it right? No other options around, so they should add to one, thats not exactly like that because we are selecting random individuals and they may or may not have the virus, we need to "focus" on our target.

If we want to relativize our context to those two options, we need to normalize them, so first we add those values together:

0.009 + 0.099 = 0.108 that is the total probability of having a positive test (wether the person has the virus or not) after selecting a random person on town.

So finally we can obtain whats called the posterior probability by normalizing our probabilities, that means, dividing them by their sum.

P(C|POS) = 0.009 / 0.108 = 0.0833

P(¬C|POS) =0.099 / 0.108 = ¨0.9166

So those are the probabilities, pretty impressive right? That is because we are assuming an initial positive result on the test. We can see it better if we go in the other direction, let's evaluate for negative results.

P(C | NEG) = P(C) * P(NEG|C) = 0.001
P(¬C | NEG) = P(¬C) * P(NEG|¬C) = 0.891

And the normalizer is = 0.001 + 0.891 = 0.892

Finally:

P(C | NEG) = 0.0011
P(¬C | NEG) = 0.9989

So if we get a negative on our test, there we can be 99% sure that we are covid free, said that you can easily detect that those tests are great for "discarting", for doing the initial triage and detecting negatives, but when it comes to positives, aditional checks should be made to get a veredict.

Top comments (0)