Bayes' Theorem
Bayes' Theorem is one of the most well-known and useful results in the area of probability and statistics, and particularly in the study of conditional probability. Basically, Bayes' Theorem tells us how to calculate the probability of an event when we have prior information about that event.
This theorem is a highly used tool because of its simplicity and its quick application in different areas of knowledge, for example in medicine, biology, technology, business, or in any area where it's necessary to have certainty about an event given prior information. Additionally, it's common to use this tool consecutively to obtain greater certainty if the problem requires it.
Below we will state this theorem and solve some exercises to better illustrate this important result.
Bayes' Theorem: Let
be mutually exclusive events whose union is the sample space
, that is,

If
is another event, then

where
represents the probability of event
called the prior probability,
represents the probability of event
given event
also known as the posterior probability, and
is the total probability of event
Equation (1) is known as Bayes' formula.
Solved Examples of Bayes' Theorem
There are two boxes: the first contains 3 red balls and 2 blue balls, while the second contains 2 red balls and 8 blue balls. A coin is flipped; if heads is obtained, a ball is drawn from the first box, and if tails is obtained, a ball is drawn from the second box. If it is known that the ball obtained is blue, what is the probability that it came from the first box?
Consider the following events and their probabilities:
"A ball is drawn from box I" 
"A ball is drawn from box II" 
Additionally, consider the event
"A blue ball is drawn." The exercise also gives us the following probabilities:

We are interested in finding
, that is, the probability that the ball was drawn from box I given that it came out blue. Following Bayes' formula we have:

Using the same data from the previous exercise, if it is known that the ball obtained is red, what is the probability that it came from the second box?
Consider the following events and their probabilities:
"A ball is drawn from box I" 
"A ball is drawn from box II" 
Additionally, consider the event
"A red ball is drawn." The exercise also gives us the following probabilities:

We are interested in finding
, that is, the probability that the ball was drawn from box II given that it came out red. Following Bayes' formula we have:

There are two boxes: the first contains 3 red balls and 2 blue balls, while the second contains 2 red balls and 8 blue balls. A die is rolled; if 1 or 2 is obtained, a ball is drawn from the first box, and if 3, 4, 5, or 6 is obtained, a ball is drawn from the second box. If it is known that the ball obtained is blue, what is the probability that it came from the first box?
Consider the following events and their probabilities:
"A ball is drawn from box I" 
"A ball is drawn from box II" 
Additionally, consider the event
"A blue ball is drawn." The exercise also gives us the following probabilities:

We are interested in finding
, that is, the probability that the ball was drawn from box I given that it came out blue. Following Bayes' formula we have:

In a certain school, 12% of students use AI to complete their schoolwork. A teacher uses an AI detector that is 90% accurate when the work was done with AI and has a 5% false positive rate when the work was not done with AI. (That is, if a student who did not use AI is tested, then with a probability of 0.05, the test result will indicate they used AI). If the teacher receives a result that the work was done with AI, what is the probability of being wrong?
Consider the following events and their probabilities:
"The student uses AI" 
"The student does not use AI" 
Additionally, consider the event
"The test is positive." The exercise also gives us the following probabilities:

We are interested in finding
, that is, the probability that the student did not use AI given that the test came back positive. Following Bayes' formula we have:

In a fast food restaurant, 30% of customers are children. There are two combo meals for sale, with combo 1 being chosen by 60% of children and 20% of adults. If the order delivered is combo 2, what is the probability that the order is for a child?
Consider the following events and their probabilities:
"The customer is a child" 
"The customer is an adult" 
Additionally, consider the event
"The order is combo 2." The exercise also gives us the following probabilities:

We are interested in finding
, that is, the probability that the order is for a child given that it is combo 2. Following Bayes' formula we have:

The probability of an accident occurring in a factory that has an alarm is
. The probability that the alarm sounds if an incident has occurred is
, and the probability that it sounds if no incident has occurred is
. Assuming the alarm has gone off, what is the probability that no incident has occurred?
Consider the following events and their probabilities:
"An incident occurs" 
"No incident occurs" 
Additionally, consider the event
"The alarm sounds" and the event
"The alarm does not sound." The exercise also gives us the following probabilities:

The information above can be summarized in the following tree diagram:

We are interested in finding
, that is, the probability that no incident has occurred given that the alarm has sounded. Following Bayes' formula we have:

A laboratory blood test has a 95% effectiveness rate for detecting a certain disease when it is actually present. However, the test also produces a "false positive" result for 1% of healthy people tested. (That is, if a healthy person is tested, then with a probability of 0.01, the test result will indicate they have the disease). If 0.5% of the population actually has the disease, what is the probability that a person has the disease given that the test result is positive?
Consider the event
"Has the disease" whose probability is 
and the event
"The result is positive."
We know the laboratory has a 95% effectiveness rate for detecting a certain disease when it is actually present, so we have:

Now consider the event
"Does not have the disease"
whose probability is

and the event
"The result is negative."
The hypotheses tell us that

We are interested in finding
, that is, the probability that a person is sick given that the test came back positive. Following Bayes' formula we have:

At a certain stage of a criminal investigation, the inspector in charge is 60% convinced of the guilt of a certain suspect. Suppose, however, that new evidence is discovered showing that the criminal has a certain characteristic. If 20% of the population possesses this characteristic, how certain should the inspector be of the suspect's guilt now if it turns out the suspect has this characteristic?
Consider the event
"The suspect is guilty"
whose probability, according to the exercise, is
. Also, consider the event
"An innocent person matches the evidence."
From the hypotheses it follows that
that is, someone who matches the evidence given that they are guilty is always true. Furthermore, if the event
"The suspect is innocent,"
then it follows that

We are interested in finding
, that is, the probability of being guilty given that they match the new evidence. Following Bayes' formula we have:

A nail factory has 2 machines that produce 30% and 70% of the nails they manufacture. The percentage of defective nails from each machine is 2% and 3%, respectively. If a nail is randomly selected from production and it was defective, what is the probability that it was manufactured by machine 1?
Consider the following events with their respective probabilities:
"Nails manufactured by machine 1" 
"Nails manufactured by machine 2" 
"The manufactured nails are defective" 
We are interested in finding
, that is, the probability that a nail randomly selected from production was manufactured by machine 1 given that it came out defective. Following Bayes' formula we have:

20% of a company's employees are engineers and another 20% are economists. 75% of engineers hold a managerial position and 50% of economists do as well, while only 20% of non-engineers and non-economists hold a managerial position. What is the probability that a randomly chosen manager is an engineer?
Consider the following events and their probabilities:
"The employees are engineers" 
"The employees are economists" 
"The employees have another career" 
Additionally, consider the event
"the employee holds a managerial position." The exercise also gives us the following probabilities:

The information above can be summarized in the following tree diagram:

We are interested in finding
, that is, the probability that an employee is an engineer given that we know in advance that he or she is a manager. Following Bayes' formula we have:

Summarize with AI:








