Back to homeMathematics · High School Year 3 · Social Sciences · Change subject
Start for free
Prep 3 SS · Mathematics
Chance and probability · Probability

Bayes' Theorem

Before you start, make sure you know: Conditional probability (High School Year 2 (semesters 3 and 4))
Before you start, make sure you know: Tree diagrams (High School Year 1 (semesters 1 and 2))

A lab test comes back positive: what is the probability that the person really has the condition? You can't answer that by looking at the tree forward, as in total probability, but by inverting it: you already know the effect happened and you are asking about the cause. That inversion is Bayes' theorem, and it works just as well for finding out which factory a defective part came from, which channel a customer arrived through, or whether an email filter made a mistake.

Bayes' theorem

In a tree, each complete path is calculated by multiplying its branches. When you already know the effect happened, you only care about the paths that end in it. The question is: of all those paths, what share goes through the cause you are interested in?

The denominator is the total probability of the effect: the branches of all the causes, not just the one for the cause you are asking about. The idea is the same as in conditional probability: one part out of the total of the cases that satisfy what you already know.

Tree diagram that illustrates how Bayes' theorem reverses direction to calculate the probability of the cause from the observed effect. P(cause 1)P(cause 2) P(effect | cause 1)P(effect | cause 2) Bayes question: ← from the effect, which branch is most likely to have happened?
Practice★☆☆Not started
To get to the center, a student can go by bus ($80\,\%$ of the time) or by bicycle ($20\,\%$). When traveling by bus, they arrive late $10\,\%$ of the time due to…

To get to the center, a student can go by bus ($80\,\%$ of the time) or by bicycle ($20\,\%$). When traveling by bus, they arrive late $10\,\%$ of the time due to traffic. When traveling by bicycle, they only arrive late $5\,\%$ of the time. If on a given day the student arrives late for class, calculate the probability that they traveled by bus.

Solve
Practice★☆☆Not started
A sneaker brand manufactures its models in two different factories: $70\,\%$ in factory $A$ and $30\,\%$ in factory $B$. Quality control has detected that $2\,\%$ of the…

A sneaker brand manufactures its models in two different factories: $70\,\%$ in factory $A$ and $30\,\%$ in factory $B$. Quality control has detected that $2\,\%$ of the sneakers from factory $A$ have a stitching defect, whereas in factory $B$ defects appear in $5\,\%$ of production. A customer buys a pair of sneakers and discovers that they have a stitching defect. Calculate the probability that they were manufactured in factory $B$.

Solve
Practice★☆☆Not started
In a software development company, $70\,\%$ of the programmers use the Python language and $30\,\%$ use Java. It is estimated that $10\,\%$ of the code written in Python…

In a software development company, $70\,\%$ of the programmers use the Python language and $30\,\%$ use Java. It is estimated that $10\,\%$ of the code written in Python contains critical syntax errors, while in Java this percentage is $15\,\%$. If a critical syntax error is detected in a piece of code, what is the probability that it was written in Python?

Solve

Strategy: the four steps

Diagram of the four steps for solving Bayes problems: causes, effect, tree with total probability, and final quotient. 1. causes 2. effect 3. tree → total 4. Bayes
Practice★☆☆Not started
An email filter automatically classifies messages as spam. The filter correctly marks $98\,\%$ of emails that are truly spam as spam. However, it also sends $4\,\%$ of…

An email filter automatically classifies messages as spam. The filter correctly marks $98\,\%$ of emails that are truly spam as spam. However, it also sends $4\,\%$ of legitimate emails to the spam folder. It is estimated that $10\,\%$ of incoming email to an inbox is spam. If a randomly chosen email has been marked as spam, calculate the probability that it is actually spam.

Population True Status Outcome Joint Probability 0.10 0.90 0.98 0.02 0.04 0.96 Spam (S) Normal (N) Flagged (+) Clean (-) Flagged (+) Clean (-) P(S ∩ +) = 0.10 × 0.98 P(S ∩ -) = 0.10 × 0.02 P(N ∩ +) = 0.90 × 0.04 P(N ∩ -) = 0.90 × 0.96 P(Spam | Marcado) = ? Bayes' theorem
Solve
Practice★★☆Not started
At a health center, a study is being conducted on the efficacy of a diagnostic test for a food allergy that affects $8\,\%$ of the youth population. Clinical data…

At a health center, a study is being conducted on the efficacy of a diagnostic test for a food allergy that affects $8\,\%$ of the youth population. Clinical data indicate that if a person suffers from the allergy, the test gives a positive result in $95\,\%$ of cases. On the other hand, if the person does not suffer from the allergy, the test gives a "false positive" (positive result without being ill) in $4\,\%$ of instances. If a young person is chosen at random and their test result is positive, calculate the probability that they actually suffer from that allergy.

Allergy (A) Healthy (A') Test + Test - Test + Test - 0.08 0.92 0.95 0.05 0.04 0.96 0.08 × 0.95 = 0.076 0.92 × 0.04 = 0.0368
Solve
Practice★★☆Not started
In a city, $70\,\%$ of citizens use a mobile app to pay for public transportation, whereas the rest use a physical card. It is observed that $15\,\%$ of those using the…

In a city, $70\,\%$ of citizens use a mobile app to pay for public transportation, whereas the rest use a physical card. It is observed that $15\,\%$ of those using the app have reading issues at the ticket validator, compared to $5\,\%$ of those using a physical card. If a validator emits a reading error signal, what is the probability that the user is trying to pay with the mobile app?

Solve

Three or more causes: which one is most likely?

Diagram showing how the Bayes calculation for several causes shares a single total probability in the denominator. P(effect) (just once, sum of all paths) cause 1 | effect cause 2 | effect cause 3 | effect same denominator in all three; only the numerator changes
Practice★★☆Not started
A manufacturer of electronic components for smartphones has three production lines: A, B, and C. Line A produces $45\,\%$ of the components, line B produces $30\,\%$,…

A manufacturer of electronic components for smartphones has three production lines: A, B, and C. Line A produces $45\,\%$ of the components, line B produces $30\,\%$, and line C produces $25\,\%$. It is known that the probability of a component being defective is $1\,\%$ on line A, $2\,\%$ on line B, and $3\,\%$ on line C. If a component is selected at random and turns out to be defective, determine with justification which production line is most likely to have manufactured it.

Solve
Practice★★☆Not started
A last-mile logistics company delivers packages in a city using three types of vehicles: electric vans ($60\,\%$), motorbikes ($30\,\%$), and cargo bicycles ($10\,\%$).…

A last-mile logistics company delivers packages in a city using three types of vehicles: electric vans ($60\,\%$), motorbikes ($30\,\%$), and cargo bicycles ($10\,\%$). The probability that a package arrives late is $2\,\%$ if delivered by van, $5\,\%$ if by motorbike, and $8\,\%$ if by bicycle. If a customer calls to complain because their package has arrived late, what is the probability that the courier was on a cargo bicycle?

Solve
Practice★★★Not started
Three streaming channels ($N$, $H$, and $D$) share the subscriber market in a city in proportions of $40\%$, $30\%$, and $30\%$, respectively. The probability that a…

Three streaming channels ($N$, $H$, and $D$) share the subscriber market in a city in proportions of $40\%$, $30\%$, and $30\%$, respectively. The probability that a subscriber of $N$ cancels their subscription this month is $0.05$; for $H$ it is $0.08$, and for $D$ it is $0.12$. If we choose at random a citizen who has just cancelled their subscription to one of these channels, what is the probability that they were a customer of $D$?

Solve

Diagnostic tests: the case that causes the most confusion

A very clear way to see it is a table with an imaginary population of $10{,}000$ young people. Take an allergy that affects $8\,\%$, with a test that comes back positive in $95\,\%$ of people with the allergy and gives a false positive in $4\,\%$ of those without it:

Positive Negative Total
With allergy 760 40 800
Without allergy 368 8,832 9,200
Total 1,128 8,872 10,000

Of the $1{,}128$ positives, $760$ have the allergy and $368$ do not. The probability of having the allergy given a positive is $760/1128 \approx 0.674$.

Two bars: the population with 8 % having the condition and 92 % without it, and below, the positive test results, split into true positives and false positives. Population (10,000 young people) 8 % 92 % without the condition Positive test results (1,128) true 67 % false 33 % The true positives come from the small 8 %; the false ones, from the large 92 %.
Practice★★☆Not started
A social network uses an artificial intelligence algorithm to detect hate speech comments. It is known that $5\,\%$ of published comments are actually inappropriate. The…

A social network uses an artificial intelligence algorithm to detect hate speech comments. It is known that $5\,\%$ of published comments are actually inappropriate. The algorithm correctly identifies $98\,\%$ of comments that are truly inappropriate as "inappropriate". However, it wrongly labels $3\,\%$ of respectful comments as "inappropriate". If the system has just blocked a comment for marking it as "inappropriate", what is the probability that the comment was actually respectful?

Solve
Practice★★★Not started
A tech multinational uses three different suppliers for the microchips in its new gaming laptops. Supplier $A$ supplies $45\%$ of the chips, supplier $B$ supplies…

A tech multinational uses three different suppliers for the microchips in its new gaming laptops. Supplier $A$ supplies $45\%$ of the chips, supplier $B$ supplies $35\%$, and the remainder come from supplier $C$. It is known from previous quality checks that $1\%$ of the chips from $A$ are defective, whereas for $B$ and $C$ these percentages are $2\%$ and $3\%$, respectively. A user buys a laptop and, after a month of use, suffers a critical failure due to the microchip. Calculate the probability that the defective chip was supplied by supplier $B$.

A B C Defective Non-defective Defective Non-defective Defective Non-defective 0.45 0.35 0.20 0.01 0.99 0.02 0.98 0.03 0.97
Solve
Practice★★★Not started
A precision parts factory uses a computer vision machine to inspect production quality. It is known that only $0.5\%$ of the manufactured parts have a defect. The…

A precision parts factory uses a computer vision machine to inspect production quality. It is known that only $0.5\%$ of the manufactured parts have a defect. The machine correctly detects $96\%$ of defective parts, but also erroneously marks $2\%$ of non-defective parts as defective. If the machine has just marked a part as defective, calculate the probability that the part is actually in perfect condition.

Solve

Summary

See all the exercises in this section