Skip to content
Gioi Toan
Start learning
A smiling die next to a coin

Notes on Lesson 2: Total probability formula. Bayes' formula (Maths 12 Canh Dieu, Chapter VI)

Lesson summary

Given two events AA and BB with 0<P(B)<10 < P(B) < 1.

Then: P(B∣A)=P(B)⋅P(A∣B)P(A).P(B \mid A) = \frac{P(B) \cdot P(A \mid B)}{P(A)}. The formula above is called Bayes' formula.

Picture event AA as the "destination", and BB and B‾\overline{B} as two roads leading to it.

This content is not yet available in English. It is shown below in the original Vietnamese.

  • Dùng công thức xác suất toàn phần, công thức Bayes giải bài toán xác suất đơn giản và thực tiễn

In medicine, a test may have high sensitivity, but when a person receives a positive result, what is the probability that the person really has the disease? The answer depends not only on the sensitivity but also on the proportion of people with the disease in the community. This lesson helps you calculate the probability of an event by splitting it into cases through the total probability formula, then reversing the problem to find the cause once the result is known, using Bayes' formula. These are powerful tools for solving probability problems in practice, especially in medicine, product quality testing, and many other fields.

Practise similar problems

Key ideas: what do you need to know?

Total probability formula

  • Given two events AA and BB with 0<P(B)<10 < P(B) < 1. Then we have the formula: P(A)=P(B)⋅P(A∣B)+P(B‾)⋅P(A∣B‾).P(A) = P(B) \cdot P(A \mid B) + P(\overline{B}) \cdot P(A \mid \overline{B}). The formula above is called the total probability formula.
  • In many problems, event BB often plays the role of the "cause" (such as sex, product origin, disease status), while event AA is the "result" whose probability we need to calculate. The condition 0<P(B)<10 < P(B) < 1 ensures that both BB and B‾\overline{B} can occur and that the conditional probabilities P(A∣B)P(A \mid B), P(A∣B‾)P(A \mid \overline{B}) are defined.
  • Meaning: Event AA can occur along two "paths": either together with BB, or together with B‾\overline{B}. The probability of AA is the sum of the probabilities of going through each path and then reaching AA.
  • Example: A factory has two production lines. Line I produces 60% of the products, line II produces 40%. The defective rate of line I is 2%, of line II is 5%. Take a product at random. Let BB be the event "the product is made by line I", then P(B)=0,6P(B)=0,6, P(B‾)=0,4P(\overline{B})=0,4. Let AA be the event "the product is defective". We have P(A∣B)=0,02P(A \mid B)=0,02, P(A∣B‾)=0,05P(A \mid \overline{B})=0,05. By the total probability formula: P(A)=0,6⋅0,02+0,4⋅0,05=0,012+0,02=0,032P(A)=0,6 \cdot 0,02 + 0,4 \cdot 0,05 = 0,012 + 0,02 = 0,032.

In plain words: Picture event AA as the "destination", and BB and B‾\overline{B} as two roads leading to it. To know the likelihood of reaching the destination, you add two ways: going along road BB and then reaching AA, and going along road B‾\overline{B} and then reaching AA. Each way is a multiplication: the probability of choosing the road times the probability of reaching the destination once on that road. Why multiply before adding? Because the two ways are two cases that do not happen at the same time, while within each case the two steps happen one after the other. The condition 0<P(B)<10 < P(B) < 1 ensures that both roads can be taken and that all conditional probabilities are defined.

Phrase by phrase
total probability formula
The formula for calculating the probability of event AA as the sum of the products of the probability of each case with the corresponding conditional probability.Example: P(A)=P(B)P(A∣B)+P(B‾)P(A∣B‾)P(A) = P(B)P(A \mid B) + P(\overline{B})P(A \mid \overline{B}).
0<P(B)<10 < P(B) < 1
The condition for both BB and B‾\overline{B} to be able to occur, and for the conditional probabilities to be defined.Example: If P(B)=0P(B) = 0 then P(A∣B)P(A \mid B) is not defined.
paths
A picture way of saying it: event AA can occur in two directions, either together with BB, or together with B‾\overline{B}.Example: A defective product can come from line I or line II.

Common mistakesAdding the probabilities of the cases without checking that the sum equals 1, or forgetting one case so that P(A)P(A) is missing.

Bayes' formula

  • For two events AA, BB with P(A)>0P(A) > 0 and P(B)>0P(B) > 0. Then: P(B∣A)=P(B)⋅P(A∣B)P(A).P(B \mid A) = \frac{P(B) \cdot P(A \mid B)}{P(A)}. The formula above is called Bayes' formula.
  • Remark: Given two events AA, BB with P(A)>0P(A) > 0, 0<P(B)<10 < P(B) < 1. Since P(A)=P(B)⋅P(A∣B)+P(B‾)⋅P(A∣B‾)P(A) = P(B) \cdot P(A \mid B) + P(\overline{B}) \cdot P(A \mid \overline{B}), Bayes' formula also has the form: P(B∣A)=P(B)⋅P(A∣B)P(B)⋅P(A∣B)+P(B‾)⋅P(A∣B‾).P(B \mid A) = \frac{P(B) \cdot P(A \mid B)}{P(B) \cdot P(A \mid B) + P(\overline{B}) \cdot P(A \mid \overline{B})}.
  • Meaning: Bayes' formula lets us calculate the probability of event BB when we know that event AA has occurred. It helps "reverse" from the result AA to infer the cause BB.
  • Example: A disease has a rate of 0.1% in the community. A test has sensitivity 100% (people with the disease always give a positive result) and a false positive rate of 5% (people without the disease still give a positive result 5% of the time). A person takes the test and receives a positive result. Calculate the probability that the person really has the disease.

Solution: Let BB be the event "the person has the disease", AA be the event "the test is positive". We have P(B)=0,001P(B)=0,001, P(B‾)=0,999P(\overline{B})=0,999, P(A∣B)=1P(A \mid B)=1, P(A∣B‾)=0,05P(A \mid \overline{B})=0,05. By Bayes' formula: P(B∣A)=0,001⋅10,001⋅1+0,999⋅0,05=0,0010,001+0,04995≈0,0196.P(B \mid A) = \frac{0,001 \cdot 1}{0,001 \cdot 1 + 0,999 \cdot 0,05} = \frac{0,001}{0,001 + 0,04995} \approx 0,0196. So the probability of having the disease is about 1.96%.

In plain words: The total probability formula goes from cause to result: knowing the proportion of each source and the defective rate of each source, we can calculate the probability that a drawn product is defective. Bayes' formula goes the other way: holding a defective product, we ask which source it came from. The numerator is exactly the contribution of source BB to P(A)P(A), the denominator is the whole of P(A)P(A). Therefore P(B∣A)P(B \mid A) is the share of source BB in the total, so it always lies between 0 and 1. The condition P(A)>0P(A) > 0 is required, because P(B∣A)P(B \mid A) only makes sense when AA can occur.

Phrase by phrase
Bayes' formula
The formula for calculating conditional probability in the reverse direction, from the result AA inferring the cause BB.Example: P(B∣A)=P(B)P(A∣B)P(A)P(B \mid A) = \frac{P(B)P(A \mid B)}{P(A)}.
false positive
The case where a test gives a positive result but the person does not actually have the disease.Example: A false positive rate of 5% means that among people who do not have the disease, 5% get a positive result.
P(A)>0P(A) > 0
The condition for the conditional probability P(B∣A)P(B \mid A) to be defined.Example: If P(A)=0P(A) = 0 then P(B∣A)P(B \mid A) cannot be calculated.

Common mistakesCalculating Bayes by dividing by the contribution of the very source being sought instead of dividing by P(A)P(A), so the result always comes out as 1.

Describe with a tree diagram

  • A visual method for describing the law of total probability is a tree diagram. From the root OO, draw two branches OBOB and OB‾O\overline{B}, and on each branch write the probabilities P(B)P(B) and P(B‾)P(\overline{B}). From each node BB, B‾\overline{B}, draw two branches to AA and A‾\overline{A}, and on these branches write the conditional probabilities P(A∣B)P(A \mid B), P(A‾∣B)P(\overline{A} \mid B), P(A∣B‾)P(A \mid \overline{B}), P(A‾∣B‾)P(\overline{A} \mid \overline{B}).
  • There are two tree branches leading to AA, namely OBAOBA and OB‾AO\overline{B}A. By the multiplication rule for probabilities, the probability of the path OBAOBA is P(B)⋅P(A∣B)P(B) \cdot P(A \mid B), and of the path OB‾AO\overline{B}A is P(B‾)⋅P(A∣B‾)P(\overline{B}) \cdot P(A \mid \overline{B}). Since these two paths are mutually exclusive, the probability of AA is the sum: P(A)=P(B)P(A∣B)+P(B‾)P(A∣B‾)P(A) = P(B)P(A \mid B) + P(\overline{B})P(A \mid \overline{B}). This is exactly the law of total probability.
  • The tree diagram also helps compute conditional probability by Bayes' formula: P(B∣A)P(B \mid A) equals the probability of the path OBAOBA divided by the sum of the probabilities of the paths leading to AA.
  • Example: In a flower-picking game there are 10 flowers, of which 5 have a prize slip. You, Binh, pick first, then you, An, pick. Draw a tree diagram and calculate the probability that An picks a flower with a prize.

Solution: Let BB be the event "Binh picks a flower with a prize", AA the event "An picks a flower with a prize". We have P(B)=510=12P(B)=\frac{5}{10}=\frac{1}{2}, P(B‾)=12P(\overline{B})=\frac{1}{2}, P(A∣B)=49P(A \mid B)=\frac{4}{9}, P(A∣B‾)=59P(A \mid \overline{B})=\frac{5}{9}. The tree diagram has two levels: the first level is the branches BB and B‾\overline{B}, the second level is the branches AA and A‾\overline{A} from each node. The probability that An picks a flower with a prize is P(A)=12⋅49+12⋅59=12P(A) = \frac{1}{2} \cdot \frac{4}{9} + \frac{1}{2} \cdot \frac{5}{9} = \frac{1}{2}.

In plain words: The tree diagram is just the law of total probability and Bayes' formula drawn as a picture. Start from the root: whichever branch you turn into, multiply by that branch's probability, and when you reach the end AA, add the paths together. To find out "which branch did it come from", take that branch's path and divide by the sum of the paths leading to AA. Why is the multiplication rule correct? Because going along branch BB and then to AA are two consecutive steps, so you use the multiplication rule for conditional probability. The tree is especially handy when the experiment has many levels, because each level is one branching.

Phrase by phrase
tree diagram
A drawing that splits into branches level by level, where each path from root to tip represents one case.Example: The first level shows P(B)P(B), P(B‾)P(\overline{B}); the second level shows P(A∣B)P(A \mid B), P(A∣B‾)P(A \mid \overline{B}).
multiplication rule along a path
The probability of a path equals the product of the probabilities written on the branches of that path.Example: The path OBAOBA has probability P(B)⋅P(A∣B)P(B) \cdot P(A \mid B).
addition rule for the routes
The probability of the event AA equals the sum of the probabilities of the paths leading to AA.Example: P(A)=P(B)P(A∣B)+P(B‾)P(A∣B‾)P(A) = P(B)P(A \mid B) + P(\overline{B})P(A \mid \overline{B}).

TipOn the tree diagram: multiply along a path, add the paths; Bayes means taking one path and dividing by the sum of the paths to the same destination.

Procedure for solving problems with the law of total probability and Bayes' formula

  • Step 1: Let BB be the "cause" event (source, production line, disease status, ...) with 0<P(B)<10<P(B)<1, and AA the "result" event whose probability is to be calculated. The two events BB and B‾\overline B cover all possibilities.
  • Step 2: Determine P(B)P(B), P(B‾)=1−P(B)P(\overline B)=1-P(B) and the conditional probabilities P(A∣B)P(A\mid B), P(A∣B‾)P(A\mid \overline B).
  • Step 3: Calculate P(A)P(A) using the law of total probability: P(A)=P(B)P(A∣B)+P(B‾)P(A∣B‾)P(A)=P(B)P(A\mid B)+P(\overline B)P(A\mid \overline B).
  • Step 4: If the problem asks for the probability of the cause BB given the result AA, use Bayes' formula: P(B∣A)=P(B)P(A∣B)P(A)P(B\mid A)=\frac{P(B)P(A\mid B)}{P(A)}.
  • Check: P(B∣A)+P(B‾∣A)=1P(B\mid A)+P(\overline B\mid A)=1.
  • Example: A type of component is produced by two factories, I and II. The defective rate of factory I is 4%, of factory II is 3%. In a lot there are 80 products from factory I and 120 products from factory II. Take one component at random. a) Calculate the probability that the component is good. b) Suppose the component is defective, which factory is more likely to have produced it?

Solution: Let BB be the event "the component was produced by factory I", then P(B)=80200=0,4P(B)=\frac{80}{200}=0,4, P(B‾)=0,6P(\overline B)=0,6. Let AA be the event "the component is defective". P(A∣B)=0,04P(A\mid B)=0,04, P(A∣B‾)=0,03P(A\mid \overline B)=0,03. a) The probability that the component is good is 1−P(A)1-P(A). We have P(A)=0,4⋅0,04+0,6⋅0,03=0,016+0,018=0,034P(A)=0,4\cdot0,04+0,6\cdot0,03=0,016+0,018=0,034. So P(good)=0,966P(\text{good})=0,966. b) P(B∣A)=0,0160,034≈0,4706P(B\mid A)=\frac{0,016}{0,034}\approx0,4706, P(B‾∣A)=0,0180,034≈0,5294P(\overline B\mid A)=\frac{0,018}{0,034}\approx0,5294. So a defective component is more likely to have been produced by factory II.

In plain words: These four steps are like going to the market with a shopping list: name things first, write down the quantitative data, compute the sum, and only then answer the question. Many students go wrong just because they read the problem and rush straight into calculating, mixing up P(A∣B)P(A\mid B) and P(B∣A)P(B\mid A). The key sentence for telling them apart: an event that comes with phrases like "given that" or "already drawn" is usually the condition, that is, the event after the sign ∣\mid. The final check step is well worth doing, because if P(B∣A)+P(B‾∣A)≠1P(B\mid A)+P(\overline B\mid A)\neq1 then something has certainly gone wrong somewhere.

Phrase by phrase
cause event
An event that only indicates the origin, the production line, the disease status, ... is usually called a BB with 0<P(B)<10<P(B)<1.Example: BB is the event "the component was produced by factory I".
outcome event
The event we observe, whose probability we need to compute, is usually called a AA.Example: AA is the event "the component is defective".
check the result
After using the Bayes formula, the sum P(B∣A)+P(B‾∣A)P(B\mid A)+P(\overline B\mid A) must equal 1.Example: 0,4706+0,5294=10,4706+0,5294=1.

Worked examples

Example 1

A box has 4 red marbles and 6 blue marbles, and the marbles differ only in colour. Two marbles are drawn at random one after another, and the drawn marble is not put back into the box. Let AA be the event "the second marble is red". Compute P(A)P(A) using the total probability formula.

Show the solution to example 1

Step 1: Let BB be the event "the first marble is red". Then B‾\overline{B} is the event "the first marble is blue". The two events BB and B‾\overline{B} are complementary events.
Step 2: Probability: P(B)=410=0,4P(B) = \frac{4}{10} = 0,4, P(B‾)=610=0,6P(\overline{B}) = \frac{6}{10} = 0,6.
Step 3: Conditional probability: if the first marble is red, then 3 red remain among 9 marbles, so P(A∣B)=39=13P(A \mid B) = \frac{3}{9} = \frac{1}{3}. If the first marble is blue, then 4 red still remain among 9 marbles, so P(A∣B‾)=49P(A \mid \overline{B}) = \frac{4}{9}.
Why: Drawing without replacement means the denominator of the second draw is 9, and the numerator depends on the colour of the marble already drawn.
Step 4: Apply the total probability formula: P(A)=P(B)P(A∣B)+P(B‾)P(A∣B‾)=0,4⋅13+0,6⋅49=410⋅39+610⋅49=1290+2490=3690=25=0,4P(A) = P(B)P(A \mid B) + P(\overline{B})P(A \mid \overline{B}) = 0,4 \cdot \frac{1}{3} + 0,6 \cdot \frac{4}{9} = \frac{4}{10} \cdot \frac{3}{9} + \frac{6}{10} \cdot \frac{4}{9} = \frac{12}{90} + \frac{24}{90} = \frac{36}{90} = \frac{2}{5} = 0,4.
Result: P(A)=0,4P(A) = 0,4.

Example 2

A factory has two production lines. Line I produces 60% of the products, and line II produces 40% of the products. The defective rate of line I is 2%, and of line II is 5%. One product is taken at random. a) Compute the probability that this product is defective. b) Given that the product taken is defective, compute the probability that it was produced by line I.

Show the solution to example 2

Step 1: Let BB be the event "the product was produced by line I", and B‾\overline{B} be the event "the product was produced by line II". The two events BB and B‾\overline{B} are complementary events. Let AA be the event "the product is defective".
Step 2: P(B)=0,6P(B) = 0,6, P(B‾)=0,4P(\overline{B}) = 0,4, check 0,6+0,4=10,6 + 0,4 = 1. The conditional probabilities: P(A∣B)=0,02P(A \mid B) = 0,02, P(A∣B‾)=0,05P(A \mid \overline{B}) = 0,05.
Step 3: a) Apply the total probability formula: P(A)=0,6⋅0,02+0,4⋅0,05=0,012+0,02=0,032P(A) = 0,6 \cdot 0,02 + 0,4 \cdot 0,05 = 0,012 + 0,02 = 0,032.
Why: The two lines are two branches that do not happen at the same time, each branch is one multiplication, and then we add them up.
Step 4: b) By the Bayes formula: P(B∣A)=P(B)P(A∣B)P(A)=0,0120,032=0,375P(B \mid A) = \frac{P(B)P(A \mid B)}{P(A)} = \frac{0,012}{0,032} = 0,375.
Step 5: Check: P(B‾∣A)=0,020,032=0,625P(\overline{B} \mid A) = \frac{0,02}{0,032} = 0,625 and 0,375+0,625=10,375 + 0,625 = 1, they match.
Result: a) P(A)=0,032P(A) = 0,032; b) P(B∣A)=0,375P(B \mid A) = 0,375.

Common mistakesConfusing P(A∣B)P(A \mid B) with P(B∣A)P(B \mid A): the problem gives the defect rate of line I as 2%, that is P(A∣B)=0,02P(A \mid B) = 0,02, but then uses 0.02 as the probability that a product comes from line I.

Example 3

A disease has a prevalence of 1% in the community. A test has a sensitivity of 95% (a person with the disease tests positive with probability 0.95) and a specificity of 90% (a person without the disease tests negative with probability 0.90). A person takes the test and gets a positive result. Compute the probability that this person really has the disease.

Show the solution to example 3

Step 1: Let BB be the event "the person has the disease", and AA be the event "the test result is positive". The two events BB and B‾\overline{B} are complementary events.
Step 2: P(B)=0,01P(B) = 0,01, P(B‾)=0,99P(\overline{B}) = 0,99. The sensitivity gives P(A∣B)=0,95P(A \mid B) = 0,95. The specificity 0.90 is the probability of a negative result when the person does not have the disease, so P(A∣B‾)=1−0,90=0,10P(A \mid \overline{B}) = 1 - 0,90 = 0,10.
Why: Specificity talks about negative results, so we must take the complement to get the false positive probability.
Step 3: P(A)=0,01⋅0,95+0,99⋅0,10=0,0095+0,099=0,1085P(A) = 0,01 \cdot 0,95 + 0,99 \cdot 0,10 = 0,0095 + 0,099 = 0,1085.
Step 4: P(B∣A)=0,00950,1085≈0,0876P(B \mid A) = \frac{0,0095}{0,1085} \approx 0,0876.
Why: Positive results mostly come from the large group of people without the disease, so the probability of really having the disease is only about 8.76%, even though the sensitivity is as high as 95%.
Result: P(B∣A)≈0,0876P(B \mid A) \approx 0,0876, that is about 8.76%.

Common mistakesUsing the specificity 0.90 as P(A∣B‾)P(A \mid \overline{B}) in the test problem, while 0.90 is the probability of a negative result when there is no disease, one must take 1−0,90=0,101 - 0,90 = 0,10.

Example 4

There are two boxes of marbles. Box I has 4 red marbles and 6 blue marbles; box II has 6 red marbles and 4 blue marbles. A box is chosen at random, and then one marble is drawn at random from that box. a) Compute the probability that the marble drawn is red. b) Given that the marble drawn is red, compute the probability that it belongs to box I.

Show the solution to example 4

Step 1: Let BB be the event "choose box I", B‾\overline{B} be the event "choose box II". The two events BB and B‾\overline{B} are complementary events. Let AA be the event "the marble drawn is red".
Step 2: P(B)=P(B‾)=12=0,5P(B)=P(\overline{B})=\frac{1}{2}=0,5. The conditional probabilities: P(A∣B)=410=0,4P(A\mid B)=\frac{4}{10}=0,4, P(A∣B‾)=610=0,6P(A\mid \overline{B})=\frac{6}{10}=0,6.
Step 3: a) Apply the total probability formula: P(A)=P(B)P(A∣B)+P(B‾)P(A∣B‾)=0,5⋅0,4+0,5⋅0,6=0,2+0,3=0,5P(A)=P(B)P(A\mid B)+P(\overline{B})P(A\mid \overline{B})=0,5\cdot0,4+0,5\cdot0,6=0,2+0,3=0,5.
Step 4: b) By Bayes' formula: P(B∣A)=P(B)P(A∣B)P(A)=0,5⋅0,40,5=0,20,5=0,4P(B\mid A)=\frac{P(B)P(A\mid B)}{P(A)}=\frac{0,5\cdot0,4}{0,5}=\frac{0,2}{0,5}=0,4.
Check: P(B‾∣A)=0,5⋅0,60,5=0,6P(\overline{B}\mid A)=\frac{0,5\cdot0,6}{0,5}=0,6 and 0,4+0,6=10,4+0,6=1, they match.
Result: a) P(A)=0,5P(A)=0,5; b) P(B∣A)=0,4P(B\mid A)=0,4.

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 5

A box has 5 red balls and 3 blue balls. Draw one ball at random, look at its colour, then put it back in the box. After that, draw one more ball at random. Let AA be the event "the second ball is red". a) Draw a tree diagram describing the experiment, writing the probabilities on the branches. b) Calculate P(A)P(A) using the rule of adding the paths. c) Given that the second ball is red, calculate the probability that the first ball is also red.

Show the solution to example 5

Step 1: Let BB be the event "the first ball is red". The first level of the tree has two branches: branch BB labelled 58\frac{5}{8}, branch B‾\overline{B} labelled 38\frac{3}{8}.
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 towards AA and A‾\overline{A}: on the branch towards AA write 58\frac{5}{8}, on the branch towards A‾\overline{A} write 38\frac{3}{8}, the same on both first-level branches.
Step 3: b) Multiplication rule along a path: the path BB then AA has probability 58⋅58=2564\frac{5}{8} \cdot \frac{5}{8} = \frac{25}{64}; the path B‾\overline{B} then AA has probability 38⋅58=1564\frac{3}{8} \cdot \frac{5}{8} = \frac{15}{64}. Addition rule for the paths: P(A)=2564+1564=4064=58P(A) = \frac{25}{64} + \frac{15}{64} = \frac{40}{64} = \frac{5}{8}.
Why: Because the ball is put back in the box, the two draws are independent, the probability on the second draw does not change; the result 58\frac{5}{8} matches intuition.
Step 4: c) Bayes on the tree: P(B∣A)=25/6440/64=2540=58P(B \mid A) = \frac{25/64}{40/64} = \frac{25}{40} = \frac{5}{8}.
Result: a) The tree has 4 paths, two branches at each level; b) P(A)=58P(A) = \frac{5}{8}; c) P(B∣A)=58P(B \mid A) = \frac{5}{8}.

Common mistakesIn the tree diagram, adding the probabilities on the branches instead of multiplying along one path, or multiplying the probabilities of two different paths.

Example 6

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 2x2 raw data table for 1000 animals. b) Calculate the probability that an animal tests positive. c) Given that an animal tests positive, calculate the probability that it really has the disease.

Show the solution to example 6

Step 1: For 1000 animals: the number with the disease is 1000⋅0,04=401000 \cdot 0,04 = 40, the number without the disease is 960. Among the 40 animals with the disease, the number testing positive is 40⋅0,92=36,840 \cdot 0,92 = 36,8, round to 37; among the 960 animals without the disease, the number testing positive is 960⋅0,06=57,6960 \cdot 0,06 = 57,6, round to 58.
Step 2: The 2x2 table (rows are test results, columns are disease status):

With diseaseWithout diseaseSum
Positive375895
Negative3902905
Sum409601000

Step 3: b) Read along the positive row: P(A)=951000=0,095P(A) = \frac{95}{1000} = 0,095.
Why: This is exactly the total probability formula 0,04⋅0,92+0,96⋅0,06=0,0368+0,0576=0,09440,04 \cdot 0,92 + 0,96 \cdot 0,06 = 0,0368 + 0,0576 = 0,0944, only slightly different because of rounding to whole numbers.
Step 4: c) Read along the positive row, the cell with disease: P(B∣A)=3795≈0,3895P(B \mid A) = \frac{37}{95} \approx 0,3895. The exact calculation by Bayes' formula: 0,03680,0944≈0,3898\frac{0,0368}{0,0944} \approx 0,3898, slightly off because of rounding the numbers of animals.
Why: The number of false positives (58) is larger than the number of true positives (37), so even with a positive result, the chance of really having the disease is under 40%.
Result: a) The table as above; b) P(A)≈0,095P(A) \approx 0,095; c) P(B∣A)≈0,3895P(B \mid A) \approx 0,3895.

TipIn the 2x2 table: the probability of the cause BB is read along the column, equal to the column sum divided by nn; the conditional probability P(A∣B)P(A\mid B) takes the cell A,BA,B divided by the column sum BB; the probability P(B∣A)P(B\mid A) takes the cell A,BA,B divided by the row sum AA.

Terms

Total probability formula
The formula for calculating the probability of event AA as the sum of the products of the probability of each case with the corresponding conditional probability.Example: P(A)=P(B)P(A∣B)+P(B‾)P(A∣B‾)P(A) = P(B)P(A \mid B) + P(\overline{B})P(A \mid \overline{B}).
Bayes' formula
The formula for calculating conditional probability in the reverse direction, from the result deducing the cause.Example: P(B∣A)=P(B)P(A∣B)P(A)P(B \mid A) = \frac{P(B)P(A \mid B)}{P(A)}.
Tree diagram
A drawing that splits into branches level by level, where each path from root to tip represents one case.Example: Floor one says P(B)P(B), floor two says P(A∣B)P(A \mid B).
The multiplication rule along the path
The probability of a path equals the product of the probabilities written on the branches of that path.Example: The path OBAOBA has probability P(B)⋅P(A∣B)P(B) \cdot P(A \mid B).
The addition rule for the branches
The probability of the event AA equals the sum of the probabilities of the paths leading to AA.Example: P(A)=P(B)P(A∣B)+P(B‾)P(A∣B‾)P(A) = P(B)P(A \mid B) + P(\overline{B})P(A \mid \overline{B}).
False positive
The case where a test gives a positive result but the person does not actually have the disease.Example: A false positive rate of 5% means that among people who do not have the disease, 5% get a positive result.

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.