Updated date:

Math: How to Calculate Conditional Probabilities Using Bayes' Law

Author:

I studied applied mathematics, in which I did both a bachelor's and a master's degree.

Thomas Bayes

Thomas Bayes

Conditional probabilities are a very important topic in probability theory. It allows you to take known information into account when calculating probabilities. You can imagine that the probability that some person likes the new Star Wars movie is different than the probability that some person likes the new Star Wars movie given he liked all previous Star Wars movies. The fact that he did like all those other movies makes it much more likely he will like this one compared to a random person who might dislike the old movies. We can calculate such a probability using Bayes' Law:

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

Here, P(A and B) is the probability that A and B both happen. You can see that when A and B are independent P(A|B) = P(A), since in that case P(A and B) is P(A)*P(B). This makes sense if you think of what it means.

If two events are independent, then information about one does not tell you anything about the other. For example, the probability that a guy’s car is red doesn’t change if we tell you that he has three children. So the probability that his car is red given that he has three children is equal to the probability that his car is red. However, if we give you information that is not independent of the color the probability might change. The probability that his car is red given it is a Toyota is different than the probability that his car is red when we were not given that information, since the distribution of red cars of Toyota will not be the same as for all other brands.

So, when A and B are independent than P(A|B) = P(A) and P(B|A) = P(B).

Applying Bayes' Theorem on an Easy Example

Let’s look at an easy example. Consider a father of two children. Then we determine the probability that he has two boys. For this to happen, both his first and second child have to be a boy, so the probability is 50%*50% = 25%.

Now we calculate the probability that he has two boys, given he does not have two girls. Now this means he can have one boy and one girl, or he has two boys. There are two possibilities to have one boy and one girl, namely first a boy and second a girl or vice versa. This means that the probability he has two boys given he doesn’t have two girls is 33.3%.

We will now calculate this using Bayes' Law. We call A the event that he has two boys and B the event that he doesn’t have two girls.

We saw that the probability he has two boys was 25%. Then the probability he has two girls is also 25%. This means that the probability he doesn’t have two girls is 75%. Clearly, the probability he has two boys and he doesn’t have two girls is the same as the probability he has two boys, because having two boys automatically implies he does not have two girls. This means P(A and B) = 25%.

Now we get P(A|B) = 25%/75% = 33.3%.

A Common Misconception About Conditional Probabilities

If P(A|B) is high, it does not necessarily mean that P(B|A) is high—for example, when we test people on some disease. If the test gives positive with 95% when positive, and negative with 95% when negative, people tend to think that when they test positive they have a very big chance of having the disease. This seems logical, but might not be the case—for example, when we have a very rare disease and test a very large amount of people. Let’s say we test 10,000 people and 100 actually have the disease. This means that 95 of these positive people test positive and 5% of the negative people test positive. This are 5%*9900 = 495 people. So in total, 580 people test positive.

Now let A be the event that you test positive and B the event that you are positive.

P(A|B) = 95%

The probability that you test positive is 580/10.000 = 5.8%. The probability that you test positive and are positive is equal to the probability that you test positive given that you are positive times the probability that you are positive. Or in symbols:

P(A and B) = P(A|B)*P(B) = 95%*1% = 0.95%

P(A) = 5.8%

This means that P(B|A) = 0.95%/5.8% = 16.4%

This means that although the probability that you test positive when you have the disease is very high, 95%, the probability of actually having the disease when testing positive is very small, only 16.4%. This is due to the fact that there are way more false positives than true positives.

Medical Test

Medical Test

Solving Crimes Using Probability Theory

The same can go wrong when looking for a murderer, for example. When we know the murderer is white, has black hair, is 1.80 meters tall, has blue eyes, drives a red car and has a tattoo of an anchor on his arm, we might think that if we find a person that matches these criteria we will have found the murderer. However, although the probability for some to match all these criteria is maybe only one in 10 million, it doesn’t mean that when we find someone matching them it will be the murderer.

When the probability in is one in 10 million that someone matches the criteria, it means that in the USA there will be around 30 people matching. If we find just one of them, we have only a 1 in 30 probability that he is the actual murderer.

This has gone wrong a couple of times in court., such as with the nurse Lucia de Berk from the Netherlands. She was found guilty of murder because a lot of people died during her shift as a nurse. Although the probability that so many people die during your shift is extremely low, the probability that there is a nurse for which this happens is very high. In court, some more advanced parts of Bayesian statistics were done wrong, which led to them think that the probability of this happening was only 1 in 342 million. If that would be the case, it would indeed provide reasonable evidence that she was guilty, since 342 million is way more than the number of nurses in the world. However, after they found the flaw, the probability was 1 in 1 million, which means you would in fact expect that there are a couple of nurses in the world that had this happen to them.

Lucia de Berk

Lucia de Berk

This content is accurate and true to the best of the author’s knowledge and is not meant to substitute for formal and individualized advice from a qualified professional.