Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Bayes' theorem
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== ===Recreational mathematics=== Bayes' rule and computing [[Conditional probability|conditional probabilities]] provide a method to solve a number of popular puzzles, such as the [[Three Prisoners problem]], the [[Monty Hall problem]], the [[Boy or Girl paradox|Two Child problem]], and the [[Two envelopes problem|Two Envelopes problem]].{{cn|date=April 2025}} ===Drug testing=== Suppose, a particular test for whether someone has been using cannabis is 90% [[Sensitivity (tests)|sensitive]], meaning the [[true positive rate]] (TPR) = 0.90. Therefore, it leads to 90% true positive results (correct identification of drug use) for cannabis users. The test is also 80% [[Specificity (tests)|specific]], meaning [[true negative rate]] (TNR) = 0.80. Therefore, the test correctly identifies 80% of non-use for non-users, but also generates 20% false positives, or [[false positive rate]] (FPR) = 0.20, for non-users. Assuming 0.05 [[prevalence]], meaning 5% of people use cannabis, what is the [[probability]] that a random person who tests positive is really a cannabis user? The [[Positive predictive value]] (PPV) of a test is the proportion of persons who are actually positive out of all those testing positive, and can be calculated from a sample as: :PPV = True positive / Tested positive If sensitivity, specificity, and prevalence are known, PPV can be calculated using Bayes' theorem. Let <math>P(\text{User}\vert \text{Positive}) </math> mean "the probability that someone is a cannabis user given that they test positive", which is what PPV means. We can write: :<math> \begin{align} P(\text{User}\vert \text{Positive}) &= \frac{P(\text{Positive}\vert \text{User}) P(\text{User})}{P(\text{Positive})} \\ &= \frac{P(\text{Positive}\vert\text{User}) P(\text{User})}{P(\text{Positive}\vert\text{User}) P(\text{User}) + P(\text{Positive}\vert\text{Non-user}) P(\text{Non-user})} \\[8pt] &= \frac{0.90 \times 0.05}{0.90 \times 0.05 + 0.20 \times 0.95} = \frac{0.045}{0.045 + 0.19} \approx 19\% \end{align}</math> The denominator <math> P(\text{Positive}) = P(\text{Positive}\vert\text{User}) P(\text{User}) + P(\text{Positive}\vert\text{Non-user}) P(\text{Non-user}) </math> is a direct application of the [[Law of Total Probability]]. In this case, it says that the probability that someone tests positive is the probability that a user tests positive times the probability of being a user, plus the probability that a non-user tests positive, times the probability of being a non-user. This is true because the classifications user and non-user form a [[partition of a set]], namely the set of people who take the drug test. This combined with the definition of [[conditional probability]] results in the above statement. In other words, if someone tests positive, the probability that they are a cannabis user is only 19%—because in this group, only 5% of people are users, and most positives are false positives coming from the remaining 95%. [[File:Bayes-rule3.png|thumb|right|Using a frequency box to show <math>P(\text{User}\vert \text{Positive}) </math> visually by comparison of shaded areas. Note how small the pink area of true positives is compared to the blue area of false positives.]] If 1,000 people were tested: * 950 are non-users and 190 of them give false positive (0.20 × 950) * 50 of them are users and 45 of them give true positive (0.90 × 50) The 1,000 people thus have 235 positive tests, of which only 45 are genuine, about 19%. ====Sensitivity or specificity==== The importance of [[Specificity (tests)|specificity]] can be seen by showing that even if sensitivity is raised to 100% and specificity remains at 80%, the probability that someone who tests positive is a cannabis user rises only from 19% to 21%, but if the sensitivity is held at 90% and the specificity is increased to 95%, the probability rises to 49%. {| class="wikitable" style="display:inline-table;" ! {{diagonal split header|Actual|Test}} ! style="width:5ex;"|Positive ! style="width:5ex;"|Negative ! rowspan="5" style="padding:0;"| ! Total |- ! User | style="text-align:right" | '''45''' | style="text-align:right" | 5 | style="text-align:right" | 50 |- ! Non-user | style="text-align:right" | 190 | style="text-align:right" | 760 | style="text-align:right" | 950 |- | colspan="5" style="padding:0;"| |- ! Total | style="text-align:right" | '''235''' | style="text-align:right" | 765 | style="text-align:right" | 1000 |- | colspan="5" style="padding:0 0 1ex 0;border:none;background:transparent;"| 90% sensitive, 80% specific, PPV=45/235 ≈ 19% |} {| class="wikitable" style="display:inline-table;" ! {{diagonal split header|Actual|Test}} ! style="width:5ex;"|Positive ! style="width:5ex;"|Negative ! rowspan="5" style="padding:0;"| ! Total |- ! User | style="text-align:right" | '''50''' | style="text-align:right" | 0 | style="text-align:right" | 50 |- ! Non-user | style="text-align:right" | 190 | style="text-align:right" | 760 | style="text-align:right" | 950 |- | colspan="5" style="padding:0;"| |- ! Total | style="text-align:right" | '''240''' | style="text-align:right" | 760 | style="text-align:right" | 1000 |- | colspan="5" style="padding:0 0 1ex 0;border:none;background:transparent;"| 100% sensitive, 80% specific, PPV=50/240 ≈ 21% |} {| class="wikitable" style="display:inline-table;" ! {{diagonal split header|Actual|Test}} ! style="width:5ex;"|Positive ! style="width:5ex;"|Negative ! rowspan="5" style="padding:0;"| ! Total |- ! User | style="text-align:right" | '''45''' | style="text-align:right" | 5 | style="text-align:right" | 50 |- ! Non-user | style="text-align:right" | 47 | style="text-align:right" | 903 | style="text-align:right" | 950 |- | colspan="5" style="padding:0;"| |- ! Total | style="text-align:right" | '''92''' | style="text-align:right" | 908 | style="text-align:right" | 1000 |- | colspan="5" style="padding:0 0 1ex 0;border:none;background:transparent;"| 90% sensitive, 95% specific, PPV=45/92 ≈ 49% |} ===Cancer rate=== If all patients with pancreatic cancer have a certain symptom, it does not follow that anyone who has that symptom has a 100% chance of getting pancreatic cancer. Assuming the incidence rate of pancreatic cancer is 1/100000, while 10/99999 healthy individuals have the same symptoms worldwide, the probability of having pancreatic cancer given the symptoms is 9.1%, and the other 90.9% could be "false positives" (that is, falsely said to have cancer; "positive" is a confusing term when, as here, the test gives bad news). Based on incidence rate, the following table presents the corresponding numbers per 100,000 people. {| class=wikitable ! {{diagonal split header|Cancer|Symptom}} ! style="width:5ex;"|Yes ! style="width:5ex;"|No ! rowspan="5" style="padding:0;"| ! Total |- ! Yes | style="text-align:right" | 1 | style="text-align:right" | 0 | style="text-align:right" | 1 |- ! No | style="text-align:right" | 10 | style="text-align:right" | 99989 | style="text-align:right" | 99999 |- | colspan="5" style="padding:0;"| |- ! style="width:15ex;"|Total | style="text-align:right" | 11 | style="text-align:right" | 99989 | style="text-align:right" | 100000 |} Which can then be used to calculate the probability of having cancer when you have the symptoms: :<math> \begin{align} P(\text{Cancer}|\text{Symptoms}) &= \frac{P(\text{Symptoms}|\text{Cancer}) P(\text{Cancer})}{P(\text{Symptoms})} \\ &= \frac{P(\text{Symptoms}|\text{Cancer}) P(\text{Cancer})}{P(\text{Symptoms}|\text{Cancer}) P(\text{Cancer}) + P(\text{Symptoms}|\text{Non-Cancer}) P(\text{Non-Cancer})} \\[8pt] &= \frac{1 \times 0.00001}{1 \times 0.00001 + (10/99999) \times 0.99999} = \frac1{11} \approx 9.1\% \end{align}</math> ===Defective item rate=== {| class="wikitable floatright" ! {{diagonal split header|<br />Machine|Condition}} ! style="width:5ex;"|Defective ! style="width:5ex;"|Flawless ! rowspan="6" | ! Total |- ! A | style="text-align:right" | 10 | style="text-align:right" | 190 | style="text-align:right" | 200 |- ! B | style="text-align:right" | 9 | style="text-align:right" | 291 | style="text-align:right" | 300 |- ! C | style="text-align:right" | '''5''' | style="text-align:right" | 495 | style="text-align:right" | 500 |- | colspan="5" style="padding:0;"| |- ! Total | style="text-align:right" | '''24''' | style="text-align:right" | 976 | style="text-align:right" | 1000 |} A factory produces items using three machines—A, B, and C—which account for 20%, 30%, and 50% of its output, respectively. Of the items produced by machine A, 5% are defective, while 3% of B's items and 1% of C's are defective. If a randomly selected item is defective, what is the probability it was produced by machine C? Once again, the answer can be reached without using the formula by applying the conditions to a hypothetical number of cases. For example, if the factory produces 1,000 items, 200 will be produced by A, 300 by B, and 500 by C. Machine A will produce 5% × 200 = 10 defective items, B 3% × 300 = 9, and C 1% × 500 = 5, for a total of 24. Thus 24/1000 (2.4%) of the total output will be defective and the likelihood that a randomly selected defective item was produced by machine C is 5/24 (~20.83%). This problem can also be solved using Bayes' theorem: Let ''X<sub>i</sub>'' denote the event that a randomly chosen item was made by the ''i'' <sup>th</sup> machine (for ''i'' = A,B,C). Let ''Y'' denote the event that a randomly chosen item is defective. Then, we are given the following information: :<math>P(X_A) = 0.2, \quad P(X_B) = 0.3, \quad P(X_C) = 0.5.</math> If the item was made by the first machine, then the probability that it is defective is 0.05; that is, ''P''(''Y'' | ''X''<sub>A</sub>) = 0.05. Overall, we have :<math>P(Y| X_A) = 0.05, \quad P(Y |X_B) = 0.03, \quad P(Y| X_C) = 0.01.</math> To answer the original question, we first find ''P''(Y). That can be done in the following way: :<math>P(Y) = \sum_i P(Y| X_i) P(X_i) = (0.05)(0.2) + (0.03)(0.3) + (0.01)(0.5) = 0.024.</math> Hence, 2.4% of the total output is defective. We are given that ''Y'' has occurred and we want to calculate the conditional probability of ''X''<sub>C</sub>. By Bayes' theorem, :<math>P(X_C|Y) = \frac{P(Y | X_C) P(X_C)}{P(Y)} = \frac{0.01 \cdot 0.50}{0.024} = \frac{5}{24}</math> Given that the item is defective, the probability that it was made by machine C is 5/24. C produces half of the total output but a much smaller fraction of the defective items. Hence the knowledge that the item selected was defective enables us to replace the prior probability ''P''(''X''<sub>C</sub>) = 1/2 by the smaller posterior probability ''P''(X<sub>C</sub> | ''Y'') = 5/24.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)