Menu

Bayes' Theorem

Chapter 8: No P(B) Provided – Flu Example

In this chapter, we use decision trees to visualize and solve our problems. Decision trees are quite straightforward, but if you need a refresher Wikipedia provides a great overview. This short lesson from Penn State is also helpful. However, just like Venn diagrams, we approach decision trees with small steps. Plus, we are not going to be using any complex terminology. You don’t need to worry!

Introduction: In earlier chapters, we used Venn diagrams to visually understand our questions and were provided with all the ingredients to solve. In this chapter, we are only provided with two of the three ingredients and must discover the third. Here is what this looks like using Venn diagrams:

Venn diagrams and Bayes' Theorem

In real life, this is typically the case and often requires us to discover one or more of the ingredients. P(B) is often the culprit, and so in this chapter, we will focus on discovering this ingredient. We will be using the same scenarios as in chapter 4, but we have tweaked them because we are now solving for P(B).

This time around we will be using two techniques to solve each scenario:

  • Decision trees
  • A classic approach using Bayes’ formula

Decision trees are a fantastic and powerful tool that can be used to quickly find P(B) and give you a clear understanding of how it is discovered. They are a great visual aid for helping you grapple with and comprehend probability questions. For each scenario in the following chapters, we will also solve the question by using a traditional Bayes’ formula approach. Let’s dig in!

The Scenario: (Expanded and Tweaked from Chapter 4)

Let’s say that you are at work one day and have just finished lunch. You suddenly feel horrible and find yourself lying down. The first thing that passes through your mind is food poisoning, but you don’t think that is the case. You then remember that your co-worker was recently off for a few days with the flu. Could you have the flu? Will you have to cancel your big trip next week?

You grab your phone and search for some answers. Google tells you that 5% of the population will get the flu each year. A few minutes pass by and you remember that you just downloaded a new app that predicts illness. Why not see what it says? You open it and input your symptoms, and within a few seconds the app predicts that you have the flu. It also displays the following:

  • It correctly predicts people having the flu 75% of the time.
  • 20% of the time it predicts that people have the flu when they do not have the flu.

You throw the phone onto the seat beside you. What do you make of this?

To start, we always need to determine what we are wanting to find. We want to know the probability of having the flu given that the app predicted that you have the flu.

Great. Now that we know our goal, we can move forward.

Solve Using a Decision Tree

To start we are going to solve this problem by using a decision tree. To do this we won’t be using any of Bayes’ formula terminology, but we will point out connections with the formula. Keep an eye out for those! If you would like to skip to solving this problem by using Bayes’ formula, click here.

Step 1: Begin by drawing two lines that connect at a single dot. These lines represent the possibility of you having the flu and not having the flu. You either have or do not have the flu, and that’s what we are drawing here. We’ll add in our numbers from the scenario.

Step 2: Next, we will add two more branches to each initial branch. Each pair of branches represents the possibility of the app predicting yes or no. In other words, if it will predict that you have the flu or do not have the flu. We’ll add in our numbers from the scenario.

Step 3: Now we will label each pathway and compute its value. Each pathway begins with either having or not having the flu, and ends with either a yes or no prediction. There are a total of 4 pathways:

Path 1: Yes Flu to Predict Yes

  • Label YY
  • Compute: .05 x .75 = .0375

Path 2: Yes Flu to Predict No

  • Label YN
  • Compute: .05 x .25 = .0125
  • * How did we find .25 ? Since the probability of both branches together is 100%, or 1, we subtracted .75 from 1. 1-.75 = .25.

Path 3: No Flu to Predict Yes

  • Label NY
  • Compute: .95 x .20 = .19

Path 4: No Flu to Predict No

  • Label NN
  • Compute: .95 x .80 = .76
  • ** How did we find .80 ? Since the probability of both branches together is 100%, or 1, we subtracted .80 from 1. 1-.20 = .80.

Step 4: Once we have our numbers, we need to sum Path 1 and Path 3. Here is why we are doing this:

  • The sum of Path 1 and Path 3 gives us P(B). In other words, it tells us the probability of the app predicting yes. This is our missing ingredient.
  • When we sum Path 1 and Path 3 we are adding both ways the app can predict yes. Path 1 represents the app predicting yes when you do have the flu. Path 3 represents the app predicting yes when you do not have the flu. When we add these paths together, we find P(B).
  • Once we have solved for the missing ingredient we can move on to find our answer.

Step 5: Now, we will divide Path 1 by the number we arrived at in Step 4 above. The end result will be our updated probability, which is P(A|B).

Path 1 represents the probability of the app predicting yes when you do have the flu. It is the equivalent of when we multiply P(B|A) with P(A).

Conclusion: The probability that you have the flu given that the app predicted you do is only 16.5%. Now, let’s move on and solve this same problem using Bayes’ formula. We’ll expand on our conclusion once we’ve done that.

Solve Using Bayes’ Formula

Let’s solve the same problem but now we’ll use Bayes’ formula.

Step 1: Determine what you want to find. – We want to know the probability of having the flu given that the app predicted that you have the flu.

Step 2: Write the above as a formula.

Step 3: Find each ingredient and label it.
From the scenario we know the following:

  • P(A) – In our formula, this ingredient is represented as P(Flu) and answers the question: What is the probability of you having the flu? This number is .05
  • P(B|A) – In our formula, this ingredient is represented as P(Yes | Flu) This number is .75

The only ingredient we are missing is: P(B)

Now, what is P(B)? How do we define what event “B” is so we can try to find it? To find our answers, let’s go back to what we are trying to figure out, which we defined in Step 1. Step 1 can be broken into two parts, and P(B) is tucked into the second part. The two parts of Step 1 are:

  • Probability of having the flu. This is P(A).
  • Probability of the app predicting yes “B” given that you have the flu “A” is .75. This is P(B|A), which contains both events “A” and “B”. This tells us that the definition of event “B” is the app predicting yes.

Excellent. Now we know the definition of event “B”. But what about its probability P(B)? We were given a third number in the scenario (20%), but this is not P(B). It is a part of P(B). To figure out where it fits and how to solve for P(B) we need to do the following:

– Let’s think for a moment. How many ways can the app arrive at a yes (positive) prediction? There are only 2 ways:

  • It can predict a positive prediction that is correct.
  • It can predict positive prediction that is false.

Now, the 20% from the scenario comes into play when the app predicts yes but the individual is not sick. If you look back at the paths we traced above (FY and NY), you can see the 20% in Path NY. All we need to do is multiply the numbers of each yes path and then add the answers together.

Step 4: Plug each ingredient into the formula and solve. Now we have all three ingredients and we can plug them into Bayes’ formula!

Here’s the formula:

  • P(A) = P(Having Flu) = .05
  • P(B|A) = P(Positive prediction given that you have the Flu) = .75
  • P(B) = P(Positive Prediction) = .2275

Let’s plug them in and solve.

Conclusion: We arrived at the same answer as before. The probability of having the flu given that the app predicted you do is 16.5%. Practically speaking what does this mean? How does it impact you? Well, 16.5% is not very high, which means the probability of you having the flu is quite low. Since it is not anywhere near 50%, you decide to remain at work and not take a half sick day. Once you finish the day and are at home, you’ll reassess your symptoms again.

Continue on to Chapter 9: Bayes’ Theorem in Real Life Use: Search and Rescue.