Conditional probability and Bayes theorem
Group 3 CHEN Feifeng WANG Yilin YANG Yumei
Group 3 CHEN Feifeng WANG Yilin YANG Yumei
We often hear that some people have been dealt a bad hand. This is actually because we are exposed to a wide range of information and different choices every day, and the new information we are exposed to affects every decision we make, thus changing the probability of our initial success or failure. This is in fact the principle of Bayesian theory, which is a standard method of constantly revising prior probabilities by increasing the sample size. And the more events that occur in support of a property, the more likely it is that the property will hold.
Before today's class, we already learned conditional probability,total prbability and the definition of Bayes Formulae and its derivation.This section we will focus on the application of Bayes theorem with the help of Shiny app.To teach the application of Bayes Theorem, we will design some scenario through Shiny app to help us achieve lesson teaching. We will start with the explanation and application of Bayes' formula in two factor events scenario with the help of Shiny app 1,which can be helpful to deepen the understanding of Bayes' formula and know how to use Bayes to solve different application scenarios, and let students experience the practical value of Bayes' formula. and then we will use the horse betting problem and the monty hall game in Shiny app 2 to explore multiple factor events using the extended formulae and have preliminary perception of Bayes' Theorem. Many students report that they are receptive to the process of derivation of Bayes' formula, but when they encounter actual compound problems, they are unable to correctly judge and apply Bayes' formula. Therefore, our objective is to use the shiny app to assist in achieving the following objectives:
1. Firstly, we will make students clear about the significance of each quantity in the formula, as well as the fact that Bayes' formula is the process of finding inverse probability events, that is, the process of finding the cause from the effect, so as to enable students to correctly judge in what situation to correctly apply the Bayes' formula.
2. To apply Bayes' formula correctly, we need to be clear about the concepts and meanings of prior probability, posterior probability, likelihood, and marginalization.
3. We need to master the steps of solving problems using Bayes' formula, which are:i) Determine the object of the solution ii) Extract the known condition and specify which quantity in the formula it corresponds to iii) Substitute into the formula to solve for the conditional probabilities
4. Explore the essence of the Bayes theorem, that is, it is a standard method of constantly correcting the priori probability(subjective judgements about probability distributions) by expanding the sample size of the test.
Shiny app 1:
This is a Shiny app about Bayesian formulas for two-factor events. In the Shiny app, you can first see situation introduction, statement of theorem, extended form, and bayesian formula for this practical question.
Then you can use the drag slider to set Prior Probability, Sensitivity and Specificity.
Then click the "Calculate" button, and the application will calculate the posterior probability P (Disease | Positive) based on the input parameter values. This posterior probability represents the probability of illness after observing a positive result.
There is a calculation process and calculated value of using Bayesian formula to find the posterior probability.
There is 1 plot in the Shiny app: The main panel displays a bar chart of prior probability, sensitivity, specificity and posterior probability. You can slide one slider while leaving the others unchanged and watch the posterior probability change in the bar chart. Therefore, through this chart, you can have a more intuitive understanding of the relationship between prior probability, likelihood, and posterior probability.
By following the above steps, we can deepen students' understanding of Bayesian formula and help students correctly use Bayesian formula to solve problems.
The following is the link to the Shiny app 1. Use it complete Task 2 below:
We design the Statement of theorem, Extended form and Bayesian Formula in the main panel to guide students to associate event variables in practical problems with various terms in Bayesian formula, and deepen students' understanding of Bayesian formula.
We design the Bayesian Formula in the sidebar Panel to show the specific process of applying Bayesian formula to solve this practical problem. It can help students understand and master the process of applying Bayesian formula, and can also help students test their own calculation process.
Shiny app 2:
This is a Shiny app about Bayesian formulas for multi-factor events.In this app, three sub-pages will be displayed in the main panel.
The 1st sub-page named Horse Betting Problem :
You can first read the Situation Introduction first to understand the different reasons and their descriptions.Combined with the actual situation, you can select multiple events in the "Select Cause" of the sidebar panel.
Next, you can assign values to the probabilities you want to use and clicking the Calculate button. When an error alert will appear above the main panel ,you need check whether the sum of the prior probabilities you set is .
If no error alert, the posterior probability will be displayed in the lower part of the sidebar panel, and a visual Bar chart of posterior probability and Probability Table will be displayed in the main panel.
(Note that the values output at the sidebar panel correspond to the posterior probability of causes you selected in the previous .)
The 2nd sub-page named Task3-The Monty Hall Game :
You can first select a door and click Open, after seeing the host’s actions (i.e. choosing which goat door to open), you then choose whether to switch.Finally click the Reveal button to view the result.
The 3rd sub-page named Task3-Answer Judgment :
Used to check the answer to task 3. After answering as required, click the Evaluate button to check whether the answer is correct or wrong.
In general, this Shiny app aims to help students understand and apply Bayes formula through situational provisions and game design to improve their reasoning and decision-making abilities for multi-factor events and feel the practical application value of Bayes.
The following is the link to the Shiny app 2. Use it complete Task 3 below:
1.Through shiny app designed an interesting life situation,students can apply Bayes formula in this situation, make choices based on their own experience and understanding, and get answers more intuitively through visual information. This contextualized learning method can stimulate students' interest, enable them to solve real- world problems immersively, and deepen their understanding of Bayesian formula.
2.The purpose of setting up a game in Shiny is to help students can engage in interactive activities that allow them to better comprehend the problem's rules and enhance their utilization of Bayes' theorem. This contextualized learning approach fosters students' interest and enables them to immerse themselves in solving real-world problems, thereby deepening their understanding of Bayes' theorem.
3.The formula is designed on the first page to correspond event variables in practical problems with prior probabilities, likelihood functions and marginal probabilities in Bayesian formulas can help students connect abstract formulas with specific situations, thereby helping to improve their understanding of formulas. Understand and apply abilities to solve practical problems.
Task 1
2, 3, 4, ,6
4: A=The dice from the black box is a cheating dice(The prior probability)
B=The number we obtained is 6
6: By sliding the slider bar and observing the changes in the posterior probability in the bar chart, you can find it is right.(Remark: When studying the effect of one variable, hold other variables constant)
Purpose:
1 and 2 are 2 error-prone questions of opposite descriptions used to reinforce students' memory and understanding of the characteristics of Bayes' formula, i.e., Bayes' formula establishes a link between P(A | B) and P(B | A), and it is an inverse probability process that seeks to find the cause of a problem from the effect.
3 is to examine the nature of Bayes' formula, so that students can deepen their understanding of the nature and uses of Bayes, so that they can apply it correctly to specific situations.
4 is a context-specific application problem. Students need to identify which quantities of the data in the question correspond to the Bayesian formula in the process of determining its right or wrong, so that they can make the correct judgment of the question, and this process can strengthen students' understanding of the concepts and the correct application of the formula.
5 This is also an error-prone question. I tested whether students understood the conditions for the application of the plain Bayes formula by intentionally setting up a definition of the omission condition, i.e., A1,...,An is the complete set of events.
6 is to deepen students' understanding of the relationship between prior probability, likelihood, and posterior probability.
Task 2
Suppose there are two taxi companies in a city, namely Company A and Company B. Among them, 85% of Company A's taxis are blue and 15% are green; 12% of Company B's taxis are blue and 88% are green. One day, you saw a blue taxi on the roadside. What is the probability that this taxi came from Company A?
By analyzing the topic, we can let A1 be the event that the taxi is from Company A, A2 be the event that the taxi is from Company B, B be the event that the taxi is blue. Then by the analysis, we can know that P(A1)=0.5, P(B|A1)=0.85, P(B|A2)=0.12. And we should calculate P(A1|B).
We can enter the corresponding values in shiny app 1, click the calculation button, and then we can get the answer, P(A1|B)=0.8762887.
Purpose:
This task can test whether students have mastered the method of correlating event variables in practical problems with the items in Bayesian formula, and can also test whether students have mastered the method of applying Bayesian formula to solve problems. Through this task, students can also understand that Bayesian formula is a process of modifying probability by adding new information.
Task 3
Suppose there are three doors. Behind one door is a car, and behind the other two doors are goats. You have to choose one door, and if you guess the door with the car behind it, you win the car! After you choose a door but before opening it, the host opens one of the remaining two doors to reveal a goat. You then have the option to switch to the other remaining closed door.Please answer the following questions:
(1) To win the prize, would you choose to switch doors?
(2) What is the probability of winning if you switch doors?
Hint:
Analysis 1: Assuming you choose Door 1, the probability of the car being behind that door is 1/3, and the probability of it not being behind that door is 2/3. The host opens one of the other two doors, revealing a goat. If you decide not to switch doors, you will win the prize if the car is behind Door 1, which has a probability of 1/3. If you decide to switch doors, you will win the prize if the car is not behind Door 1, which has a probability of 2/3. Therefore, switching doors is the correct decision.
Analysis 2: Using the law of total probability and Bayes' theorem, we can analyze the situation from the perspective of conditional probability.
Let's use A1, A2, A3 to represent the car being behind Door 1, Door 2, Door 3, respectively, and B1, B2, B3 to represent the host opening Door 1, Door 2, Door 3, respectively. As mentioned above, if we assume you initially choose Door 1, your choice does not affect the probability distribution of the car behind the three doors. Therefore, the probabilities of events A1, A2, and A3 remain 1/3, which are the prior probabilities ,i.e.P(A1) = P(A2) = P(A3) = 1/3.
The host then opens a door other than Door 1, which reveals a goat. This means the host will only open one door out of Door 2 and Door 3 (we know that P(B1) = 0). There are several possible scenarios:
- If the car is behind Door 1, the host can open either Door 2 or Door 3. i.e., P(B2 | A1) = P(B3 | A1) = 1/2.
- If the car is behind Door 2, the host can only open Door 3. i.e., P(B2 | A2) = 1.
- If the car is behind Door 3, the host can only open Door 2. i.e., P(B2 | A3) = 1.
Based on the above analysis, we can calculate the probabilities of the host opening Door 2 and Door 3 using the law of total probability:
P(B2) = P(A1) * P(B2 | A1) + P(A2) * P(B2 | A2) + P(A3) * P(B2 | A3) = (1/3 * 1/2) + (0 * 1) + (1/3 * 1) = 1/2.
Thus, we obtain P(B3)=1-P(B2)=1-1/2=1/2=P(B2).
Next, assuming the host opens Door 2, we can calculate the probability of the car being behind Door 1 and the probability of the car being behind Door 3:
P(A1 | B2) = P(A1) * P(B2 | A1) / P(B2) = (1/3 * 1/2) / (1/2) = 1/3,i.e.the probability of winning without switching the door is 1/3,
P(A3 | B2) = P(A3) * P(B2 | A3) / P(B2) = (1/3 * 1) / (1/2) = 2/3,i.e.the probability of winning by switching the door is 2/3.
These two conditional probabilities are posterior probabilities that adjust the prior probabilities. By comparing the posterior probabilities, it is easy to see that switching doors is the correct decision.
Remark:
The method provided in Analysis 1 is simple, direct, and easy to understand. However, the approach based on Bayes' theorem in Analysis 2 has broader applicability. In fact, if we expand the game to four or more doors, and the host continues to open a door with a goat each time, the method in Analysis 1 becomes more complex. Using the approach with Bayes' theorem, we can discover that in the case of a multi-door game where the host opens a goat door after your initial choice and gives you the opportunity to switch, you can still improve your chances of success by changing your selection. Moreover, even if the host opens another goat door after your second choice and gives you another opportunity to switch, you should still change your selection to increase the probability of success. Therefore, this strategy also applies to situations with multiple selections.
In fact, in the aforementioned multi-round game, each time the host opens a goat door, they provide new useful information. The participant needs to continuously update the (new) posterior probabilities using Bayes' theorem and adjust their choices accordingly to improve the probability of success. This iterative process of refining and updating decisions closely resembles human learning and thinking patterns and is crucial in many applications of Bayesian methods. Due to this characteristic, Bayesian methods play a significant role in the field of artificial intelligence and have become the theoretical foundation of machine learning.
Purpose:
Through this question, students will gain an in-depth understanding and application of Bayesian formulas and an overview of the importance of Bayesian methods in solving practical problems, making their current learning feel meaningful and valuable.