The **Bayes’ theorem** describes the probability of an event based on prior knowledge of the conditions that might be relevant to the event. It tells us how to invert conditional probabilities, i.e. to find P(B|A) from P(A|B).

The formula for Bayes’ Theorem:

Example 1:

You are planning a picnic today, but the morning is cloudy

Oh no! 50% of all rainy days start off cloudy!

But cloudy mornings are common (about 40% of days start cloudy)

And this is usually a dry month (only 3 of 30 days tend to be rainy, or 10%)

What is the chance of rain during the day?

We will use Rain to mean rain during the day, and Cloud to mean cloudy morning.

So let's put that in the formula:

P(Rain|Cloud) = P(Rain) x P(Cloud|Rain) / P(Cloud)

P(Rain|Cloud) = 0.1 x 0.5 / 0.4 = 0.125

Or a 12.5% chance of rain. Not too bad, let's have a picnic!

Example 2 :

Imagine there is a drug test that is 98% accurate, meaning 98% of the time it shows a true positive result for someone using the drug, and 98% of the time it shows a true negative result for nonusers of the drug. Next, assume 0.5% of people use the drug.

If a person selected at random tests positive for the drug, the following calculation can be made to see whether the probability the person is actually a user of the drug.

(0.98 x 0.005) / [(0.98 x 0.005) + ((1 - 0.98) x (1 - 0.005))] = 0.0049 / (0.0049 + 0.0199) = 19.76%

Bayes' theorem shows that even if a person tested positive in this scenario, it is actually much more likely the person is not a user of the drug.