4-2 Bayes' Theorem: Positive Determination via Square Area and Calculation Formulas
This statistical topic
We will tackle problems involving finding the probability of rare cookies or positive determinations using Bayes' Theorem.
Preparation of the Official Problem Collection
We will use problems from the "Official Problem Collection." Please have the official problem collection at hand.
Don't worry if you don't have the official problem collection!
Please enjoy learning statistics at your own pace in the "Learn" and "Practice" chapters!
Solving the problem
📘 Official Problem Collection Category
Probability field
Question 2 Bayes' Theorem (Probability of Platypus Cookies)
Exam Date
Statistical Test Grade 2, November 2018, Question 7 (Answer Number 11)
Problem
Please refer to the official problem collection.
How to solve
Problem Intent
Under the following conditions, we will find the probability that a cookie was "manufactured at Factory A" given that it "contains a picture of a platypus."
Probability of product manufacturing factory
Probability of stocking products manufactured at Factory A: 70%
Probability of stocking products manufactured at Factory B: 30%
Probability that a cookie contains a picture of a platypus
Probability that a cookie manufactured at Factory A contains a platypus picture: 2%
Probability that a cookie manufactured at Factory B contains a platypus picture: 8%

Solving with a diagram
Using a square with width 1, height 1, and area 1, we will find the ratio = probability that a stocked cookie was "manufactured at Factory A" given that it "contains a picture of a platypus."

The probability that a stocked cookie "contains a picture of a platypus" is the sum of ① and ② below, which is 0.038.
① 0.7 (cookies manufactured at Factory A) multiplied by 0.02 (ratio containing a platypus picture) = 0.014
② 0.3 (cookies manufactured at Factory B) multiplied by 0.08 (ratio containing a platypus picture) = 0.024
The probability that a stocked cookie was "manufactured at Factory A" given that it "contains a picture of a platypus" is 0.014 (from ①) divided by 0.038, which is 0.3684...
The answer is 0.368.
Solving with Bayes' Theorem
First, we define the events as follows:
・Event of being manufactured at Factory A: $${A}$$
・Event of being manufactured at Factory B: $${B}$$
・Event of containing a picture of a platypus: $${K}$$
The probability we are looking for is the conditional probability $${P(A \mid K)}$$ that the event $${A}$$ (manufactured at Factory A) occurs given that the stocked cookie is the event $${K}$$ (contains a picture of a platypus).
From the problem statement, we obtain the following probabilities:
・Probability of event $${A}$$ (manufactured at Factory A): $${P(A)=0.7}$$
・Probability of event $${B}$$ (manufactured at Factory B): $${P(B)=0.3}$$
・Conditional probability of event $${K}$$ (contains a platypus picture) given event $${A}$$ (manufactured at Factory A): $${P(K \mid A)=0.02}$$
・Conditional probability of event $${K}$$ (contains a platypus picture) given event $${B}$$ (manufactured at Factory B): $${P(K \mid B)=0.08}$$
We apply these values to Bayes' Theorem to calculate the probability.
【Applying Bayes' Theorem】
$$
\begin{align*}
P(A \mid K) &= \cfrac{P(A)\ P(K \mid A)}{P(K)} \\
\\
&=\cfrac{P(A)\ P(K \mid A)}{P(A)\ P(K \mid A)+P(B)\ P(K \mid B)}
\end{align*}
$$
[Calculation Process]
$$
\begin{align*}
P(A \mid K)& = \cfrac{0.7 \times 0.02}{0.7 \times 0.02+0.3\times 0.08}\\
\\
&=\cfrac{0.014}{0.014+0.024}\\
\\
&=0.3684 \cdots
\end{align*}
$$
The answer is 0.368.

Answer
(2) It is 0.368.
Difficulty: Easy
・Knowledge: Conditional probability, multiplication rule of probability, Bayes' theorem
・Calculation skills: Formula construction (low), calculator (low)
・Estimated time: 1 minute
Learn
Menu
Let's approach the problems in the official workbook!
This time, let's solve a similar problem together!
Bayes' Theorem
📕Official Textbook: 2.3 Bayes' Theorem (page 62 onwards)
Similar Problem
Let's consider a positive test result for a disease.
A certain disease is spreading, and 1% of the population is infected.
The test gives a positive result for 90% of those who are infected.
Also, the test gives a positive result for 20% of those who are not infected.
When one person is randomly selected from those who took the test, what is the probability in percent that the person has tested positive and is actually infected?

Events and Probability
Let the event of being infected with the disease be $${A}$$, and the event of testing positive be $${B}$$.
The symbol $${P}$$ is used for probability.
The probability of the event of being infected is expressed as $${P(A)}$$, and since the probability is 0.01, $${P(A)=0.01}$$.
Incidentally, the probability of the event of testing positive is expressed as $${P(B)}$$.
Complementary Events and Probability
The event of not being infected is an event other than the "event $${A}$$ of being infected".
Such an "event other than a certain event $${A}$$" is called a complementary event and is expressed as $${A^C}$$.
The probability of the event of not being infected is expressed as $${P(A^C)}$$, and since the probability is 0.99, $${P(A^C)=0.99}$$.
Adding the probability of event $${A}$$ and the probability of the complementary event $${A^C}$$ equals 1.
$${P(A)+P(A^C)=1}$$.
Incidentally, the probability of the event of not testing positive is expressed as $${P(B^C)}$$.
Let's visualize the probabilities of events and complementary events.

Conditional Probability
The probability of testing positive given that one is infected is expressed as $${P(B \mid A)}$$.
Since the probability is 0.9, $${P(B \mid A)=0.9}$$.
This means $${P(testing positive \mid infected)}$$, which is the probability of "testing positive" given the condition that the event "infected" occurs.
Conditional probabilityis what it is called.
The probability of testing positive given that one is not infected is expressed as $${P(B \mid A^C)}$$.
Since the probability is 0.2, $${P(B \mid A^C)=0.2}$$.
The probability of being infected given that one tests positive is $${P(A \mid B)}$$.
The question of this similar problem is to find the conditional probability $${P(A \mid B)}$$.
Let's visualize it.

Moving on to Bayes' Theorem.
This may be sudden, but here is the definition of conditional probability.
$$
P(A \mid B) = \cfrac{P(B \cap A) }{P(B)}
\tag{1.1}
$$
Multiplying both sides by $${P(B)}$$ and rearranging gives the multiplication rule of probability.
$$
P(B \cap A)=P(B)\ P(A \mid B)
\tag{1.2}
$$
Swap B and A, and perform the same operations as in Equation 1.1 and Equation 1.2.
$$
P(A \cap B)=P(A)\ P(B \mid A)
\tag{1.3}
$$
Since $${P(B \cap A)=P(A \cap B)}$$, we derive the following equation from Equation 1.2 and Equation 1.3.
$$
P(B)\ P(A \mid B)=P(A)\ P(B \mid A)
\tag{1.4}
$$
Divide both sides by $${P(B)}$$.
$$
P(A \mid B)=\cfrac{P(A)\ P(B \mid A)}{P(B)}
\tag{1.5}
$$
The probability $${P(B)}$$ in the denominator on the right side, which is the probability of the "event $${B}$$ where a positive result occurs," is the sum of the following two probabilities:
・The probability $${P(A \cap B)}$$ of the joint event where "event $${A}$$ of having the disease" and "event $${B}$$ of a positive result" occur simultaneously.
・The probability $${P(A^C \cap B)}$$ of the joint event where "event $${A^C}$$ of not having the disease" (the complement of $${A}$$) and "event $${B}$$ of a positive result" occur simultaneously.
$$
P(A \mid B)=\cfrac{P(A)\ P(B \mid A)}{P(A \cap B)+P(A^C \cap B))}
\tag{1.6}
$$
From the multiplication rule of probability (Equation 1.2, Equation 1.3), the following equalities hold for $${P(A \cap B)}$$ and $${P(A^C \cap B)}$$.
$$
P(A \cap B)=P(A)\ P(B \mid A)\\
\\
P(A^C \cap B)=P(A^C)\ P(B \mid A^C)
\tag{1.7}
$$
Substituting Equation 1.7 into Equation 1.6 completes Bayes' Theorem.
$$
P(A \mid B)=\cfrac{P(A)\ P(B \mid A)}{P(A)\ P(B \mid A)+P(A^C)\ P(B \mid A^C)}
\tag{1.8}
$$
Solving similar problems with Bayes' Theorem
Substitute the following values into Equation 1.8 to find the answer.
Probability of the event of having the disease $${P(A)=0.01}$$
Probability of the event of not having the disease $${P(A^C)=0.99}$$
Probability of a positive result if one has the disease $${P(B \mid A)=0.9}$$
The probability of a positive test result when not actually having the disease is $${P(B \mid A^C)=0.2}$$
$$
\begin{align*}
P(A \mid B)&=\cfrac{0.01 \times 0.9}{0.01 \times 0.9+0.99 \times 0.2}\\
\\
&=\cfrac{0.009}{0.09+0.198} \\
\\
&=0.0434 \cdots\\
\end{align*}
$$
The answer is 4.3%.
Let's visualize this with a diagram.
The yellow area represents the "probability of a positive test result $${P(B)}$$".
Of this, the probability of "having the disease and testing positive" $${P(A)\ P(B\mid A)}$$ is the vertical rectangular section on the left, and the probability is 0.009.

The ratio of the probability of "having the disease and testing positive" $${P(A)\ P(B\mid A)=0.009}$$ to the total yellow area $${P(B)=0.009+0.198}$$ is 0.0434...
The answer is 4.3%.

If you are not comfortable with the calculation formulas for Bayes' theorem, try using this method of calculating the area ratio of rectangles to approach Bayes' theorem!
Also, in the conditional probabilities that appear in Bayes' theorem, the order of events is reversed between the right side (the calculation result) and the left side (the basis for the calculation).
By remembering this reversal rule, it might become easier to keep Bayes' theorem in your memory.

To summarize.
When one person is randomly selected from those who were tested, the probability that they tested positive and actually have the disease is 4.3%.
The fact that only 4.3% actually have the disease despite testing positive is...
If you perform the test on people who have symptoms such as a fever, the probability of testing positive and actually having the disease might increase.
(End)

Summary of Formulas
Bayes' Theorem (Event B has a single pattern)
$$
\begin{align*}
P(B \mid A) &= \cfrac{P(B)\ P(A \mid B) }{P(A)}\\
&=\cfrac{P(B)\ P(A \mid B)}{P(B)\ P(A \mid B)+P(B^C)\ P(A \mid B^C)}
\end{align*}
$$
Bayes' Theorem (Event B has multiple patterns)
$$
\begin{align*}
P(B_i \mid A) &= \cfrac{P(B_i)\ P(A \mid B_i) }{P(A)}\\
&=\cfrac{P(B_i)\ P(A \mid B_i)}{\displaystyle \sum^n_{j=1}P(B_j)\ P(A \mid B_j)}
\end{align*}
$$
$${P(B),\ P(B_i)}$$ are called prior probabilities, and $${P(B \mid A),\ P(B_i \mid A)}$$ are called posterior probabilities.
Practice
None this time.
Let's try creating it with a calculator or by hand!
None this time.
Let's try creating it in EXCEL!
We are taking a break this time.
Download EXCEL sample file
There is no file provided this time.
Let's try creating it in Python!
We are taking a break this time.
Download Python sample file
There is no file provided this time.
Conclusion
Bayes' theorem corresponds to the starting point of "Bayesian statistics."
"Bayesian statistics" adopts the concept of having a pre-set prior probability $${P(B)}$$, and using newly acquired information $${\cfrac{P(A \mid B)}{P(A)}}$$ to update the probability to obtain the posterior probability $${P(B \mid A)}$$.
The posterior probability is then continuously updated based on new information.
It dynamically updates probabilities to the latest version as information is acquired.
A commonly introduced practical example of Bayesian statistics is email spam filtering.

Thank you for reading until the end.
Articles in the Relaxed Statistics series
Next article
Previous article
Table of contents
いいなと思ったら応援しよう!
応援ありがとうございます。これからもがんばって記事を作成します!