Back to homeMathematics · AP Statistics · Change subject
Start for free
AP Stats · Mathematics
Chance and Probability · Probability

Bayes' Theorem

Before you start, make sure you know: Conditional probability (Algebra 2)
Before you start, make sure you know: Trees (Geometry)

Your school runs a rapid screening test for a virus. The test is positive for 90% of people who are sick, and it gives a false alarm for 5% of healthy people. Only 2% of students are actually sick. Your test comes back positive. Is there a 90% chance you are sick? Not even close, and by the end of this page you will see exactly why.

The trick is to stop reading the tree forward. You already know the effect (a positive test), and you are asking about the cause (being sick). Turning a tree around like this is called Bayes' Theorem.

Reversing the Tree

In a tree diagram, you start with the causes and move toward the effect: "if the student takes the bus, the chance of being late is 8%." That is a forward question.

A Bayes question runs backward: "the student is late — what is the chance they took the bus?" The effect has already happened, and you want to know which branch it came from.

Tree diagram showing two causes B1 and B2 leading to event A, with a dashed arrow showing that Bayes' Theorem works backward from A to the causes. P(B₁)P(B₂) P(A|B₁)P(A|B₂) Bayes question: given A, which branch was it most likely to come from?
Practice★☆☆Not started
To get to school, a student can go by bus ($80\,\%$ of the time) or by bicycle ($20\,\%$). When they go by bus, they arrive late $10\,\%$ of the days due to traffic.…

To get to school, a student can go by bus ($80\,\%$ of the time) or by bicycle ($20\,\%$). When they go by bus, they arrive late $10\,\%$ of the days due to traffic. When they go by bicycle, they only arrive late $5\,\%$ of the time. If one day the student arrives late to class, calculate the probability that they went 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 some stitching defect, whereas in factory $B$ defects appear in $5\,\%$ of the production. A customer buys a pair of sneakers and discovers they have a stitching defect. Calculate the probability that they were manufactured in factory $B$.

Solve
Practice★☆☆Not started
A video game store sells consoles of two brands: "N-Switch" and "PlayPro". $65\,\%$ of the sales are of PlayPro and the rest are N-Switch. The technical service reports…

A video game store sells consoles of two brands: "N-Switch" and "PlayPro". $65\,\%$ of the sales are of PlayPro and the rest are N-Switch. The technical service reports that $3\,\%$ of the PlayPros are returned due to a factory defect, whereas for the N-Switch the return percentage is $2\,\%$. If a customer returns a defective console, what is the probability that it is a PlayPro?

Solve

A Four-Step Plan

Every Bayes problem can be solved the same way. Follow the steps in order and it never gets messy.

Flow chart of four steps for solving Bayes' Theorem problems: list the causes, identify the effect, draw the tree to find P(A), then apply Bayes. 1. Causes 2. Effect A 3. Tree → P(A) 4. Bayes
Practice★☆☆Not started
On a streaming* platform, $60\,\%$ of the series are in-house productions, while the rest are from external production companies. It is known that $15\,\%$ of the…

On a streaming platform, $60\,\%$ of the series are in-house productions, while the rest are from external production companies. It is known that $15\,\%$ of the in-house series are of the science fiction genre, whereas in the external ones this percentage rises to $25\,\%$. If we choose a series at random and it turns out to be science fiction, what is the probability that it is an in-house production of the platform?

0.60 0.40 0.15 0.85 0.25 0.75 In-house External Sci-Fi Others Sci-Fi Others
Solve
Practice★☆☆Not started
In a high school, $40\,\%$ of the 12th grade students are in the Science track and $60\,\%$ in Social Sciences. It has been observed that $85\,\%$ of the Science…

In a high school, $40\,\%$ of the 12th grade students are in the Science track and $60\,\%$ in Social Sciences. It has been observed that $85\,\%$ of the Science students and $90\,\%$ of the Social Sciences students pass English class. If we choose a student at random who is known to have passed English, what is the probability that they belong to the Science track?

Solve
Practice★★☆Not started
An e-sports team plays its tournament matches under two network conditions: "Low Latency" ($P=0,75$) and "High Latency" ($P=0,25$). When the latency is low, the team…

An e-sports team plays its tournament matches under two network conditions: "Low Latency" ($P=0,75$) and "High Latency" ($P=0,25$). When the latency is low, the team wins $80\,\%$ of its matches. However, if the latency is high, its probability of winning drops to $40\,\%$. Knowing that the team has just won a match, what is the probability that they were playing with high latency?

B A G G̅ G G̅ Low Lat. High Lat. Wins Loses Wins Loses P(B) = 0.75 P(A) = 0.25 P(G|B) = 0.80 P(G̅|B) = 0.20 P(G|A) = 0.40 P(G̅|A) = 0.60 Knowing they won... P(A|G) = ? ...prob. of High Lat.?
Solve

Diagnostic Tests and False Positives

Medical and screening tests are the classic Bayes situation. Two numbers describe a test:

  • Sensitivity is $P(\text{positive} \mid \text{has the condition})$, the true positive rate.

  • False positive rate is $P(\text{positive} \mid \text{does not have it})$. The test's specificity is $1 - $ this rate.

Neither of these is the probability you actually want, $P(\text{has the condition} \mid \text{positive})$. That also depends on how common the condition is.

A very helpful trick is to imagine a big group, say 10,000 people, and count.

Bar showing 670 positive tests out of 10,000 students: 180 true positives and 490 false positives, so only about 26.9 percent of positives are sick. Out of 10,000 students: 200 sick, 9,800 healthy Everyone who tests positive (670 people): 180 sick 490 healthy 180 ÷ 670 ≈ 26.9% of positives are truly sick

Back to the start: a positive result means about a 27% chance of being sick, not 90%. The test is good, but the healthy group is so large that its 5% of false alarms (490 people) outnumbers the 180 true positives.

Practice★☆☆Not started
A test to detect a food allergy gives a positive result in $98\,\%$ of the people who actually suffer from the allergy. However, it also gives a "false positive"…

A test to detect a food allergy gives a positive result in $98\,\%$ of the people who actually suffer from the allergy. However, it also gives a "false positive" (positive without having the allergy) in $4\,\%$ of healthy people. We know that in a population $10\,\%$ of the people are allergic. If a person chosen at random tests positive, calculate the probability that they are actually allergic.

Population Actual Condition Test Result Joint Probability 0.10 0.90 0.98 0.02 0.04 0.96 Allergic (A) Healthy (S) Positive (+) Negative (-) Positive (+) Negative (-) P(A ∩ +) = 0.10 × 0.98 P(A ∩ -) = 0.10 × 0.02 P(S ∩ +) = 0.90 × 0.04 P(S ∩ -) = 0.90 × 0.96 P(Alérgico | Positivo) = ? Bayes' Theorem
Solve
Practice★★☆Not started
A social network uses an artificial intelligence algorithm to detect hate comments. It is known that $5\,\%$ of the published comments are actually inappropriate. The…

A social network uses an artificial intelligence algorithm to detect hate comments. It is known that $5\,\%$ of the published comments are actually inappropriate. The algorithm correctly identifies as "inappropriate" $98\,\%$ of the comments that actually are. However, it mistakenly labels as "inappropriate" $3\,\%$ of the comments that are respectful. 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
At a high-performance sports center, a detection test for a banned substance is carried out. It is known that only $0,5\%$ of the athletes consume this substance. The…

At a high-performance sports center, a detection test for a banned substance is carried out. It is known that only $0,5\%$ of the athletes consume this substance. The test has a reliability such that it tests positive in $96\%$ of the cases where the athlete has consumed the substance (sensitivity). However, the test also yields $2\%$ of "false positives" in clean athletes. If an athlete tests positive, calculate the probability that they are actually innocent and have not consumed the substance.

Solve

Three or More Causes

Nothing changes when there are three causes. Draw three branches and add three terms in the denominator.

The denominator $P(A)$ is the same whatever cause you ask about. So to compare causes or find "the most likely one," compute $P(A)$ once and only change the numerator.

One bar representing the probability of a stale bun, 0.042, split into three pieces for bakeries X, Y and Z whose sizes give their posterior probabilities. Whole bar = P(stale bun) = 0.042 X: 0.010 Y: 0.012 Z: 0.020 23.8% 28.6% 47.6% Same denominator for every cause; only the numerator changes.
Practice★★☆Not started
A last-mile logistics company distributes packages in a city using three types of vehicles: electric vans ($60\,\%$), motorcycles ($30\,\%$) and cargo bicycles…

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

Solve
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, B $30\,\%$ and C $25\,\%$. It…

A manufacturer of electronic components for smartphones has three production lines: A, B and C. Line A produces $45\,\%$ of the components, B $30\,\%$ and C $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 reasoning which production line is most likely to have manufactured it.

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

A multinational technology company uses three different suppliers for the microchips in its new gaming laptops. Supplier $A$ provides $45\%$ of the chips, supplier $B$ provides $35\%$, and the rest come from supplier $C$. It is known from previous quality controls 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 Good Defective Good Defective Good 0.45 0.35 0.20 0.01 0.99 0.02 0.98 0.03 0.97
Solve

Tricky Wording: Complements and Unknowns

On harder problems, the work is in reading the question carefully. The calculation is still the four steps.

The event you observe may be a "not"

If you are given $P(A \mid B_i)$ but the problem says that $A$ did not happen, use $P(A^C \mid B_i) = 1 - P(A \mid B_i)$ for every cause. The same goes for a cause: "not Viral" means adding up all the other causes, or computing $1 - P(\text{Viral} \mid \text{effect})$.

An unknown rate

Sometimes one rate is missing, but the answer to the Bayes question is given. Then you write Bayes' formula with the unknown in it and solve the equation.

Tree for the two machines: X with probability 2/3 and defect rate p, Y with probability 1/3 and defect rate 0.06. X: 2/3 Y: 1/3 defective: p defective: 0.06
Practice★★☆Not started
A recycling center processes containers coming from two districts of the city, North and South. $60\,\%$ of the containers come from the North district. At the…

A recycling center processes containers coming from two districts of the city, North and South. $60\,\%$ of the containers come from the North district. At the processing plant, it is detected that $10\,\%$ of the containers from the North are incorrectly sorted by citizens, whereas in the South district this percentage rises to $15\,\%$. If the conveyor belt operator selects a container at random and checks that it is correctly sorted, what is the probability that it comes from the North district?

Solve
Practice★★★Not started
In a study on reading habits in teenagers, the sample was divided into three groups according to daily screen time: Low ($20\%$), Medium ($50\%$) and High ($30\%$). The…

In a study on reading habits in teenagers, the sample was divided into three groups according to daily screen time: Low ($20\%$), Medium ($50\%$) and High ($30\%$). The probability of a young person in the Low group reading at least one book a month is $0,7$; for the Medium group it is $0,4$ and for the High group it is $0,15$. If we select a teenager at random and they claim not to have read any books in the last month, calculate the probability that they belong to the "High" screen consumption group.

Solve
Practice★★★Not started
A factory has two machines, $M_1$ and $M_2$, which produce the same part. $M_1$ produces three times as many parts as $M_2$. The percentage of defective parts from $M_1$…

A factory has two machines, $M_1$ and $M_2$, which produce the same part. $M_1$ produces three times as many parts as $M_2$. The percentage of defective parts from $M_1$ is $k\%$ and from $M_2$ is $4\%$. It is known that if a part is chosen at random and turns out to be defective, the probability that it comes from machine $M_2$ is $4/13$. Calculate the value of $k$ and, subsequently, the probability that a randomly chosen part is defective.

3/4 1/4 k% 100-k% 4% 96% M₁ M₂ D D' D D' ROUTES TO DEFECTIVE (D) P(M₁∩D) = 3/4 · k% P(M₂∩D) = 1/4 · 4% P(M₂|D) = 4/13
Solve

Summary

See all the exercises in this section