DEV Community

Artik Blue
Artik Blue

Posted on

A small lesson on conditional probability

By continuing to study the many aspects of probability we have to look at the conditional probability, that answers the fundamental question: What is the probability of having X phenomenon if Y phenomenon already happened?

When we are just flipping coins the results of the second throw won't depend on the results given at the first one, but for example if we pick a random person there is some chance that he or she will be a night person or day person depending whether the person prefeers the night or the day it will be more or less probable that he or she likes to go out running early in the morning. That is one of the fundamentals of conditional probability, events that are correlated.

The covid19 test

Imagine that we are in charge of a hospital and we have this novel test that we have to use and can detect covid19 in a matter of minutes, the test works as follow:

If the person has covid it will detect it 90% of the time
If the person does not have it it will also detect that 80% of the time

And with those you can easily calculate the complementaries. We can also write it in other terms:

P(POSITIVE | COVID) = 0.9
P(NEGATIVE | COVID) = 0.1

P(POSITIVE | ¬COVID) = 0.2
P(NEGATIVE | ¬COVID) = 0.8

And from our statistical data we assume that if we pick a random person on our town only 1 out of 10 have covid, SO

P(COVID) = 0.1
P(¬COVID) = 0.9

So using that we can generate a table and calculate some probabilities:

If we want to know the probability we have that if we pick a random person on the street, this person will have covid and will be detected as positive we can just multiply the general probability of having covid by the probability of having a positive test given that he or she has covid.

We can even build a table.

COVID TEST P()
Y POS 0.09
Y NEG 0.02
N POS 0.18
N NEG 0.72

Note that all of those add to one and we can even calculate probabilities such as: what is the probability that if we pick a random person on the street he or she will do positive on a test, no matter if he or she has the virus o not?

We just need to add the probability of doing POS having the virus and doing POS not having it, that is 0.009 + 0.18 = 0.27 very intuitive!

Moar coins

Yes... more of them. So if we have two identical coins and we flip one, and then the other the probabilities for the second throw to be a tail won't depend on the first throw at all, as all of them will have the same probability and we will pick one or the other. But let's say one of the coins is loaded so the probability of getting a head after throwing it is 0.9, the other is just a regular coin. We put them both on a box and we ask someone to pick one of them and throw it we assume that 50% of the time the person will pick one 50% will pick the other, the probabilities of getting a tail will change here as firstly the person will have to pick a coin and DEPENDING on the coin he or she picks the probabilities of getting head will be diferent!

Again we can get the probability of getting a tail after picking the non loaded coin by doing 0.5 (picking the coin) * 0.5 (and getting tail) and after that we can build the table like this:

PICK COIN FLIP COIN
1 H 0.25
1 T 0.25
2 H 0.45
2 T 0.05

The methodology is the same. You can think about more complex things such as, starting by the coin picking game and then doing multiple throws or using fake coins that have a head on both sides, the logic is the same.

See you next with some more probabiliy with bayes theorem :)

Top comments (0)