Notes on Lesson 2: Total probability formula and Bayes' formula (Maths 12 Chan troi sang tao, Chapter VI)
Lesson summary
Given two events and with .
Suppose and are two random events satisfying and .
You can picture event as the "destination", while and are two paths leading to it.
This content is not yet available in English. It is shown below in the original Vietnamese.
- Sử dụng được công thức xác suất toàn phần và công thức Bayes
In medicine, a rapid test can give a positive result, but whether the person actually has the disease depends on the rate of the disease in the community. Today's lesson will equip you with two powerful tools: the total probability formula, which helps compute the probability of an event by splitting it into cases, and Bayes' formula, which helps "reverse" the problem to find the cause when the result is known. These two formulas are useful not only in medical testing but also in many other real situations such as product inspection, weather forecasting,...
Key ideas: what do you need to know?
The total probability formula
- Given two events and with . Then we have the formula: This formula is called the total probability formula.
- In many problems, event often plays the role of the "cause" (for example: a shipment, a production line, a disease status), while event is the "result" whose probability we need to compute.
- The condition ensures that both and can occur, and the conditional probabilities , are all defined.
- Example: A factory has two workshops I and II. Workshop I produces 40% of the products, workshop II produces 60% of the products. The defective rate of workshop I is 2%, of workshop II is 1%. Let be the event "the product is defective", be the event "the product was made by workshop I". Then , , , . Applying the formula: .
In plain words: You can picture event as the "destination", while and are two paths leading to it. To compute the probability of reaching the destination, add the probabilities of the two ways: going along path and then reaching , and going along path and then reaching . Each way is a multiplication: the probability of choosing the path times the probability of reaching the destination once on that path. Why multiply and then add? Because the two paths are two cases that cannot happen at the same time, while within each case the two steps happen one after the other. The condition makes sure that both paths can be chosen, and the conditional probability is defined.
Phrase by phrase
- total probability formula
- The formula for computing the probability of event as the sum of the products of the probability of each case with the corresponding conditional probability.Example: .
- The condition for both events and to be able to occur, and the conditional probabilities , to be defined.Example: If then is not defined.
- event is the cause, is the result
- In many problems, is usually the known information (such as the product rate of a workshop), while is what we care about (such as a defective product).Example: : the product was made by workshop I; : the product is defective.
Common mistakesConfusing with : the problem gives the defective-product rate of workshop I as 2%, that is , but then uses 0.02 as the probability that a product comes from workshop I. You need to identify correctly which is the condition: the event after the sign is the condition.
Bayes' formula
- Suppose and are two random events satisfying and . Then: This formula is called Bayes' formula.
- Note:
- Bayes' formula still holds for any event : when and , we have ; this form is also called Bayes' formula (the denominator is usually computed with the total probability formula).
- Bayes' formula allows computing a conditional probability in the reverse direction: from the result that has occurred, infer the probability of the cause .
- Example: A factory has two workshops I and II. Workshop I produces 40% of the products, workshop II produces 60% of the products. The defective rate of workshop I is 2%, of workshop II is 1%. A product is checked at random and found to be defective. Compute the probability that this product was made by workshop I. Let be the event "the product is defective", be the event "the product was made by workshop I". We have , , , . By Bayes' formula: .
In plain words: The total probability formula helps you go from cause to result: knowing the rate of each workshop and the defective rate of each workshop, you can compute the probability of picking a defective product. Bayes' formula helps you go backwards: holding the defective product in your hand, you want to know which workshop it came from. The numerator is exactly the contribution of workshop to the probability , while the denominator is the whole . So is the share of in the total, so it always lies between 0 and 1. The condition is required, because only makes sense when can occur.
Phrase by phrase
- Bayes' formula
- The formula for conditional probability in the reverse direction, from the result deducing the cause .Example: .
- The condition for the conditional probability to be determined.Example: If then cannot be calculated.
- Bayes' formula with denominator
- Another way of writing Bayes' formula, valid for any event (when ), in which the denominator is exactly the probability of event (already calculated with the total probability formula).Example: .
Common mistakesComputing Bayes by dividing by the contribution of the very source you are looking for instead of dividing by , so the result always comes out as 1.
Described by a tree diagram
- A tree diagram is a visual tool for describing the total probability formula and Bayes' formula.
- From the root , draw two branches and (or more branches if there are more cases). On branch write , on branch write .
- From each node and , draw branches to and . On branch write , on branch write , on branch write , on branch write .
- There are two tree branches leading to , namely and . By the multiplication rule along a path, the probability of path is , and of path is . By the addition rule over the branches, .
- Bayes' formula on the tree: equals the probability of path divided by the sum of the probabilities of the paths leading to .
In plain words: A tree diagram is just the total probability formula and Bayes' formula drawn as a picture. Start from the root and go up: whichever branch you turn into, multiply by the probability written on that branch, and when you reach the destination , add the probabilities of all the paths leading to . To find out "which branch it came from", take the probability of that path and divide it by the sum of the probabilities of the paths to . Why is the multiplication rule correct? Because going along branch and then to are two consecutive steps, so we use the multiplication rule for conditional probability. The tree is especially handy when the experiment has many stages, because each stage is one branching.
Phrase by phrase
- tree diagram
- A drawing that splits into branches stage by stage, each path from root to tip represents one case.Example: The first stage shows and , the second stage shows and .
- multiplication rule along a path
- The probability of a path equals the product of the probabilities written on the branches of that path.Example: Path has probability .
- addition rule over the branches
- The probability of event equals the sum of the probabilities of all the paths leading to .Example: .
- Bayes on the tree
- The conditional probability equals the probability of the path through to divided by the sum of the probabilities of the paths to .Example: .
TipOn a tree diagram: multiply along a path, add over the routes; Bayes means taking one path and dividing by the sum of all paths to the same endpoint.
Procedure for solving problems with the total probability formula and Bayes' formula
- Step 1: Name the events. Identify the complete system of events (usually the "origins" such as workshops, batches, disease status) and the outcome event whose probability is to be calculated.
- Step 2: Write the prior probabilities of the events in the complete system and the conditional probabilities of the outcome event given each event in the system. Check that the sum of the prior probabilities equals 1.
- Step 3: Calculate the probability of the outcome event using the total probability formula.
- Step 4: If the problem asks in reverse (given the result, ask about the origin), use Bayes' formula, taking the contribution of the origin you need divided by the probability of the outcome event.
- After calculating, check: the sum of the posterior probabilities of all the origins must equal 1.
In plain words: These four steps are like a recipe: prepare the ingredients (name the events), measure (write the probabilities), cook (calculate), and taste again (check). Many students go wrong just because they read the problem and rush straight into calculating, which leads to confusion between and . The key sentence for telling them apart: an event that comes with phrases like "given that", "having drawn" is usually the condition, that is, the event after the sign. The final check step is well worth doing, because if the sum of the posteriors is not 1 then something is certainly wrong somewhere.
Phrase by phrase
- complete system
- A group of events that are pairwise mutually exclusive and whose union is the certain event, covering every possibility.Example: The two workshops I and II form a complete system.
- prior probability
- The probability of an event in the complete system, known before there is any information about the result.Example: is the prior probability of the event "the product was made by workshop I".
- posterior probability
- The probability of an event in the complete system after the result is known to have happened.Example: is the posterior probability of the event "the product was made by workshop I" given that the product is defective.
- check that the sum of the posteriors equals 1
- After calculating, the sum of the posterior probabilities of all the origins must equal 1 because they still form a complete system.Example: .
Worked examples
Example 1
A box has 4 red balls and 6 blue balls, the balls differ only in colour. Two balls are drawn at random one after another, and the ball drawn is not put back in the box. Let be the event "the second ball is red". Calculate using the total probability formula.
Show the solution to example 1
Step 1: Let be the event "the first marble is red". Then is the event "the first marble is blue". The two events and form a complete system.
Step 2: Prior probability: , .
Step 3: Conditional probability: if the first marble is red, then 3 red remain among 9 marbles, so . If the first marble is blue, then 4 red still remain among 9 marbles, so .
Why: Drawing without replacement, so the denominator for the second draw is 9, and the numerator depends on the color of the marble drawn.
Step 4: Apply the total probability formula: .
Result: .
Common mistakesAdding the prior probabilities without checking that they sum to 1, or forgetting one source in the complete system, so is missing.
Example 2
A factory has two workshops I and II. Workshop I produces 40% of the products, workshop II produces 60% of the products. The defective rate of workshop I is 2%, of workshop II is 1%. Take one product at random. a) Find the probability that it is defective. b) Given that the product taken is defective, find the probability that it was produced by workshop I.
Show the solution to example 2
Step 1: Let be the event "the product is defective", be the event "the product was produced by workshop I". Then is the event "the product was produced by workshop II". The two events and form a complete system.
Step 2: , . The conditional probabilities: , .
Step 3: a) Apply the total probability formula: .
Why: The two workshops are two sources that cannot happen at the same time, each source is one multiplication, then add them up.
Step 4: b) By Bayes' formula: .
Step 5: Check: , and , it matches.
Result: a) ; b) .
Example 3
A rapid SARS-CoV-2 test gives a positive result for 76.2% of cases that are truly infected with the virus and a negative result for 99.1% of cases that are truly not infected with the virus. Suppose the infection rate in a community is 1%. A person in that community takes the test and gets a positive result. Is the chance that the person is truly infected with the virus high or low?
Show the solution to example 3
Step 1: Let be the event "the person tested has a positive result", be the event "the person tested is truly infected with the virus". The two events and form a complete system.
Step 2: The infection rate is 1%, so , .
Step 3: Conditional probability: the test is positive for 76.2% of cases that are truly infected, so . The test is negative for 99.1% of cases that are truly not infected, so , hence .
Why: The specificity of 99.1% refers to a negative result when not infected, so you must take the complement to get the false positive probability.
Step 4: Apply the total probability formula: .
Step 5: By Bayes' formula: .
Why: Positive results mostly come from the large group of people who are not infected, so the probability of actually being infected is only about 46.1%, even though the sensitivity is as high as 76.2%.
Result: , that is about 46.1%, lower than 50%, so the chance of truly being infected with the virus is low.
Common mistakesUsing the specificity 0.90 as in the testing problem, while 0.90 is the probability of a negative result when there is no disease, so you must take .
TipRemember the order with the phrase "total probability goes forward, Bayes goes backward": total probability from the source to the result, Bayes from the result back to the source.
Example 4
A box has 5 red balls and 3 blue balls. Take one ball at random, look at its color, then put it back in the box. Then take another ball at random. Let be the event "the second ball is red". a) Draw a tree diagram describing the experiment, writing the probabilities on the branches. b) Find using the rule of adding the paths. c) Given that the second ball is red, find the probability that the first ball is also red.
Show the solution to example 4
Step 1: Let be the event "the first ball is red". The first level of the tree has two branches: branch labelled , branch labelled .
Step 2: Because the ball is put back in the box, the second draw still has 8 balls. From each first-level branch, two branches split off toward and : on the branch toward write and , on the branch toward write and .
Step 3: b) Multiplication rule along a path: the path then has probability ; the path then has probability . Addition rule over the routes: .
Why: Because the ball is put back in the box, the two draws are independent, so the probability for the second draw does not change; the result matches intuition.
Step 4: c) Bayes on the tree: .
Result: a) The tree has 4 paths, two branches at each level; b) ; c) .
Common mistakesIn a tree diagram, adding the probabilities along a branch instead of multiplying along one path, or multiplying the probabilities of two different paths.
Example 5
A quarantine station uses a test to detect a disease in livestock. The rate of livestock with the disease is 4%. For livestock with the disease, the test is positive with probability 0.92; for livestock without the disease, the test is positive with probability 0.06. a) Make a raw data table for 1000 animals. b) Find the probability that an animal tests positive. c) Given that an animal tests positive, find the probability that it actually has the disease.
Show the solution to example 5
Step 1: For 1000 animals: the number with the disease is , the number without the disease is 960. Among the 40 animals with the disease, the number testing positive is , rounded to 37; among the 960 animals without the disease, the number testing positive is , rounded to 58.
Step 2: Raw data table (rows are test results, columns are disease status):
| With disease | Without disease | Sum | |
|---|---|---|---|
| Positive | 37 | 58 | 95 |
| Negative | 3 | 902 | 905 |
| Sum | 40 | 960 | 1000 |
Step 3: b) Read along the positive row: .
Why: This is exactly the total probability formula , only slightly different because of rounding to whole numbers.
Step 4: c) Read along the positive row, in the with-disease cell: . The exact value by Bayes' formula is , slightly different because of rounding the number of animals.
Why: The number of false positives (58) is greater than the number of true positives (37), so even with a positive test, the chance of actually having the disease is under 40%.
Result: a) The table as above; b) ; c) .
TipIn the raw data table : the prior probability is read down a column, as the column sum divided by ; the conditional probability is the cell divided by the column sum ; the posterior is the cell divided by the row sum .
Terms
- total probability formula
- The formula for the probability of event as the sum of the products of the probability of each case with the corresponding conditional probability.Example: .
- Bayes' formula
- The formula for conditional probability in the reverse direction, inferring the cause from the result.Example: .
- prior probability
- The probability of an event in the complete system, known before observing the result.Example: .
- posterior probability
- The probability of an event in the complete system after knowing that the result has occurred.Example: .
- tree diagram
- A drawing that splits into branches stage by stage, each path from root to tip represents one case.Example: Level 1 is labelled , level 2 is labelled .
- multiplication rule along a path
- The probability of a path equals the product of the probabilities written on the branches of that path.Example: .
- addition rule over the branches
- The probability of event equals the sum of the probabilities of all the paths leading to .Example: .
- complete system
- A group of events that are pairwise mutually exclusive and whose union is the certain event.Example: and form a complete system.
Practise similar problems
Practice questions from the Ket noi tri thuc series on the same ideas as this lesson. Answer each one and get it marked straight away.