Bayes' theorem

Bayes' theorem(alternativelyBayes' laworBayes' rule, afterThomas Bayes) gives a mathematical rule for invertingconditional probabilities, allowing one to find the probability of a cause given its effect.For example, if the risk of developing health problems is known to increase with age, Bayes' theorem allows the risk to someone of a known age to be assessed more accurately by conditioning it relative to their age, rather than assuming that the person is typical of the population as a whole. Based on Bayes' law, both the prevalence of a disease in a given population and the error rate of an infectious disease test must be taken into account to evaluate the meaning of a positive test result and avoid thebase-rate fallacy.
One of Bayes' theorem's many applications isBayesian inference, an approach tostatistical inference, where it is used to invert the probability ofobservationsgiven a model configuration (i.e., thelikelihood function) to obtain the probability of the model configuration given the observations (i.e., theposterior probability).
Bayes' theorem is named afterThomas Bayes(/beɪz/), a minister, statistician, and philosopher. Bayes used conditional probability to provide an algorithm (his Proposition 9) that uses evidence to calculate limits on an unknown parameter. His work was published in 1763 asAn Essay Towards Solving a Problem in the Doctrine of Chances. Bayes studied how to compute a distribution for the probability parameter of abinomial distribution(in modern terminology). After Bayes's death, his family gave his papers to a friend, the minister, philosopher, and mathematicianRichard Price.
Price significantly edited the unpublished manuscript for two years before sending it to a friend who read it aloud at theRoyal Societyon 23 December 1763.Price editedBayes's major work "An Essay Towards Solving a Problem in the Doctrine of Chances" (1763), which appeared inPhilosophical Transactions,and contains Bayes' theorem. Price wrote an introduction to the paper that provides some of the philosophical basis ofBayesian statisticsand chose one of the two solutions Bayes offered. In 1765, Price was elected a Fellow of the Royal Society in recognition of his work on Bayes's legacy.On 27 April, a letter sent to his friendBenjamin Franklinwas read out at the Royal Society, and later published, in which Price applies this work to population and computing 'life-annuities'.
Independently of Bayes,Pierre-Simon Laplaceused conditional probability to formulate the relation of an updatedposterior probabilityfrom a prior probability, given evidence. He reproduced and extended Bayes's results in 1774, apparently unaware of Bayes's work, in 1774, and summarized his results inThéorie analytique des probabilités(1812).TheBayesian interpretationof probability was developed mainly by Laplace.
About 200 years later,Sir Harold Jeffreysput Bayes's algorithm and Laplace's formulation on anaxiomaticbasis, writing in a 1973 book that Bayes' theorem "is to the theory of probability what thePythagorean theoremis to geometry".
Stephen Stiglerused a Bayesian argument to conclude that Bayes' theorem was discovered byNicholas Saunderson, a blind English mathematician, some time before Bayes,but that is disputed.Martyn Hooperand Sharon McGraynehave argued that Richard Price's contribution was substantial:
F. Thomas Brussreviewed Bayes' work "An essay towards solving a problem in the doctrine of chances" as communicated by Price.He agrees with Stigler's fine analysis in many points, but not as far as the question of priority is concerned. Bruss underlines the intuitive part of Bayes' formula and adds independent arguments of Bayes' probable motivation for his work. He concludes that, unless the contrary is really proven, we are entitled to be faithful to the name "Bayes' Theorem" or "Bayes' formula".
Bayes' theorem is stated mathematically as the following equation:
whereA{\displaystyle A}andB{\displaystyle B}areeventsandP(B)≠0{\displaystyle P(B)\neq 0}.
Bayes' theorem may be derived from the definition ofconditional probability:
whereP(A∩B){\displaystyle P(A\cap B)}is the probability of both A and B being true. Similarly,
Solving forP(A∩B){\displaystyle P(A\cap B)}and substituting into the above expression forP(A|B){\displaystyle P(A\vert B)}yields Bayes' theorem:
For two continuousrandom variablesXandY, Bayes' theorem may be analogously derived from the definition ofconditional density:
Therefore,
LetPYx{\displaystyle P_{Y}^{x}}be the conditional distribution ofY{\displaystyle Y}givenX=x{\displaystyle X=x}and letPX{\displaystyle P_{X}}be the distribution ofX{\displaystyle X}. The joint distribution is thenPX,Y(dx,dy)=PYx(dy)PX(dx){\displaystyle P_{X,Y}(dx,dy)=P_{Y}^{x}(dy)P_{X}(dx)}. The conditional distributionPXy{\displaystyle P_{X}^{y}}ofX{\displaystyle X}givenY=y{\displaystyle Y=y}is then determined by
PXy(A)=E(1A(X)|Y=y){\displaystyle P_{X}^{y}(A)=E(1_{A}(X)|Y=y)}
Existence and uniqueness of the neededconditional expectationis a consequence of theRadon–Nikodym theorem. This was formulated byKolmogorovin 1933. Kolmogorov underlines the importance of conditional probability, writing, "I wish to call attention to  ... the theory of conditional probabilities and conditional expectations".Bayes' theorem determines the posterior distribution from the prior distribution. Uniqueness requires continuity assumptions.Bayes' theorem can be generalized to include improper prior distributions such as the uniform distribution on the real line.ModernMarkov chain Monte Carlomethods have boosted the importance of Bayes' theorem, including in cases with improper priors.
Bayes' rule and computingconditional probabilitiesprovide a method to solve a number of popular puzzles, such as theThree Prisoners problem, theMonty Hall problem, theTwo Child problem, and theTwo Envelopes problem.
Suppose, a particular test for whether someone has been using cannabis is 90%sensitive, meaning thetrue 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%specific, meaningtrue negative rate(TNR) = 0.80. Therefore, the test correctly identifies 80% of non-use for non-users, but also generates 20% false positives, orfalse positive rate(FPR) = 0.20, for non-users.
Assuming 0.05prevalence, meaning 5% of people use cannabis, what is theprobabilitythat a random person who tests positive is really a cannabis user?
ThePositive 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:
If sensitivity, specificity, and prevalence are known, PPV can be calculated using Bayes' theorem. LetP(User|Positive){\displaystyle P({\text{User}}\vert {\text{Positive}})}mean "the probability that someone is a cannabis user given that they test positive", which is what PPV means. We can write:
The denominatorP(Positive)=P(Positive|User)P(User)+P(Positive|Non-user)P(Non-user){\displaystyle P({\text{Positive}})=P({\text{Positive}}\vert {\text{User}})P({\text{User}})+P({\text{Positive}}\vert {\text{Non-user}})P({\text{Non-user}})}is a direct application of theLaw 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 apartition of a set, namely the set of people who take the drug test. This combined with the definition ofconditional probabilityresults 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%.
If 1,000 people were tested:
The 1,000 people thus have 235 positive tests, of which only 45 are genuine, about 19%.
The importance ofspecificitycan 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%.
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.
Which can then be used to calculate the probability of having cancer when you have the symptoms:
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: LetXidenote the event that a randomly chosen item was made by theimachine (fori= A,B,C). LetYdenote the event that a randomly chosen item is defective. Then, we are given the following information:
If the item was made by the first machine, then the probability that it is defective is 0.05; that is,P(Y|XA) = 0.05. Overall, we have
To answer the original question, we first findP(Y). That can be done in the following way:
Hence, 2.4% of the total output is defective.
We are given thatYhas occurred and we want to calculate the conditional probability ofXC. By Bayes' theorem,
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 probabilityP(XC) = 1/2 by the smaller posterior probabilityP(XC|Y) = 5/24.
The interpretation of Bayes' rule depends on theinterpretation of probabilityascribed to the terms. The two predominant interpretations are described below.
In theBayesian (or epistemological) interpretation, probability measures a "degree of belief". Bayes' theorem links the degree of belief in a proposition before and after accounting for evidence. For example, suppose it is believed with 50% certainty that a coin is twice as likely to land heads than tails. If the coin is flipped a number of times and the outcomes observed, that degree of belief will probably rise or fall, but might remain the same, depending on the results. For propositionAand evidenceB,
For more on the application of Bayes' theorem under the Bayesian interpretation of probability, seeBayesian inference.
In thefrequentist interpretation, probability measures a "proportion of outcomes". For example, suppose an experiment is performed many times.P(A) is the proportion of outcomes with propertyA(the prior) andP(B) is the proportion with propertyB.P(B|A) is the proportion of outcomes with propertyBout ofoutcomes with propertyA, andP(A|B) is the proportion of those withAout ofthose withB(the posterior).
The role of Bayes' theorem can be shown with tree diagrams. The two diagrams partition the same outcomes byAandBin opposite orders, to obtain the inverse probabilities. Bayes' theorem links the different partitionings.
Anentomologistspots what might, due to the pattern on its back, be a raresubspeciesofbeetle. A full 98% of the members of the rare subspecies have the pattern, soP(Pattern | Rare) = 98%. Only 5% of members of the common subspecies have the pattern. The rare subspecies is 0.1% of the total population. How likely is the beetle having the pattern to be rare: what isP(Rare | Pattern)?
From the extended form of Bayes' theorem (since any beetle is either rare or common),
For eventsAandB, provided thatP(B) ≠ 0,
In many applications, for instance inBayesian inference, the eventBis fixed in the discussion and we wish to consider the effect of its having been observed on our belief in various possible eventsA. In such situations the denominator of the last expression, the probability of the given evidenceB, is fixed; what we want to vary isA. Bayes' theorem shows that the posterior probabilities areproportionalto the numerator, so the last equation becomes:
In words, the posterior is proportional to the prior times the likelihood.
If eventsA1,A2, ..., are mutually exclusive and exhaustive, i.e., one of them is certain to occur but no two can occur together, we can determine the proportionality constant by using the fact that their probabilities must add up to one. For instance, for a given eventA, the eventAitself and its complement ¬Aare exclusive and exhaustive. Denoting the constant of proportionality byc, we have:
Adding these two formulas we deduce that:
or
Another form of Bayes' theorem for two competing statements or hypotheses is:
For an epistemological interpretation:
For propositionAand evidence or backgroundB,
Often, for somepartition{Aj} of thesample space, theevent spaceis given in terms ofP(Aj) andP(B|Aj). It is then useful to computeP(B) using thelaw of total probability:
P(B)=∑jP(B∩Aj),{\displaystyle P(B)=\sum _{j}P(B\cap A_{j}),}
Or (using the multiplication rule for conditional probability),
In the special case whereAis abinary variable:
Consider asample spaceΩ generated by tworandom variablesXandYwith known probability distributions. In principle, Bayes' theorem applies to the eventsA= {X=x} andB= {Y=y}.
Terms become 0 at points where either variable has finiteprobability density. To remain useful, Bayes' theorem can be formulated in terms of the relevant densities (seeDerivation).
IfXis continuous andYis discrete,
where eachf{\displaystyle f}is a density function.
IfXis discrete andYis continuous,
If bothXandYare continuous,
A continuous event space is often conceptualized in terms of the numerator terms. It is then useful to eliminate the denominator using thelaw of total probability. ForfY(y), this becomes an integral:
Bayes' theorem inodds formis:
where
is called theBayes factororlikelihood ratio. The odds between two events is simply the ratio of the probabilities of the two events. Thus:
Thus the rule says that the posterior odds are the prior odds times theBayes factor; in other words, the posterior is proportional to the prior times the likelihood.
In the special case thatA1=A{\displaystyle A_{1}=A}andA2=¬A{\displaystyle A_{2}=\neg A}, one writesO(A)=O(A:¬A)=P(A)/(1−P(A)){\displaystyle O(A)=O(A:\neg A)=P(A)/(1-P(A))}, and uses a similar abbreviation for the Bayes factor and for the conditional odds. The odds onA{\displaystyle A}is by definition the odds for and againstA{\displaystyle A}. Bayes' rule can then be written in the abbreviated form
or, in words, the posterior odds onA{\displaystyle A}equals the prior odds onA{\displaystyle A}times the likelihood ratio forA{\displaystyle A}given informationB{\displaystyle B}. In short,posterior odds equals prior odds times likelihood ratio.
For example, if a medical test has asensitivityof 90% and aspecificityof 91%, then the positive Bayes factor isΛ+=P(True Positive)/P(False Positive)=90%/(100%−91%)=10{\displaystyle \Lambda _{+}=P({\text{True Positive}})/P({\text{False Positive}})=90\%/(100\%-91\%)=10}. Now, if theprevalenceof this disease is 9.09%, and if we take that as the prior probability, then the prior odds is about 1:10. So after receiving a positive test result, the posterior odds of having the disease becomes 1:1, which means that the posterior probability of having the disease is 50%. If a second test is performed in serial testing, and that also turns out to be positive, then the posterior odds of having the disease becomes 10:1, which means a posterior probability of about 90.91%. The negative Bayes factor can be calculated to be 91%/(100%-90%)=9.1, so if the second test turns out to be negative, then the posterior odds of having the disease is 1:9.1, which means a posterior probability of about 9.9%.
The example above can also be understood with more solid numbers: assume the patient taking the test is from a group of 1,000 people, 91 of whom have the disease (prevalence of 9.1%). If all 1,000 take the test, 82 of those with the disease will get a true positive result (sensitivity of 90.1%), 9 of those with the disease will get a false negative result (false negative rateof 9.9%), 827 of those without the disease will get a true negative result (specificity of 91.0%), and 82 of those without the disease will get a false positive result (false positive rate of 9.0%). Before taking any test, the patient's odds for having the disease is 91:909. After receiving a positive result, the patient's odds for having the disease is
which is consistent with the fact that there are 82 true positives and 82 false positives in the group of 1,000.
Where theconditional probabilityP(A|B){\displaystyle P(A\vert B)}isdefined, it can be seen to capture the implicationB→A{\displaystyle B\to A}. The probabilistic calculus then mirrors or even generalizes various logical inference rules. Beyond, for example, assigning binary truth values, here one assigns probability values to statements. The assertionB→A{\displaystyle B\to A}is captured by the assertionP(A|B)=1{\displaystyle P(A\vert B)=1}, i.e. that the conditional probability take the extremal probability value1{\displaystyle 1}. Likewise, the assertion of a negation of an implication is captured by the assignment of0{\displaystyle 0}.So, for example, ifP(A)=1{\displaystyle P(A)=1}, then (if it is defined)P(A|B)=1{\displaystyle P(A\vert B)=1}, which entailsA→(B→A){\displaystyle A\to (B\to A)}, theimplication introductionin logic.
Similarly, as the product of two probabilities equaling1{\displaystyle 1}necessitates that both factors are also1{\displaystyle 1}, one finds that Bayes' theorem
entails(A∧(A→B))↔(B∧(B→A)){\displaystyle {\big (}A\land (A\to B){\big )}\leftrightarrow {\big (}B\land (B\to A){\big )}}, which now also includesmodus ponens.
For positive valuesP(A){\displaystyle P(A)}, if it equalsP(B){\displaystyle P(B)}, then the two conditional probabilities are equal as well, and vice versa. Note that this mirrors the generally valid(A↔B)↔((A→B)↔(B→A)){\displaystyle (A\leftrightarrow B)\leftrightarrow {\big (}(A\to B)\leftrightarrow (B\to A){\big )}}.
On the other hand, reasoning about either of the probabilities equalling0{\displaystyle 0}classicallyentails the following contrapositive form of the above:(¬B∨¬(B→A))↔(¬A∨¬(A→B)){\displaystyle {\big (}\neg B\lor \neg (B\to A){\big )}\leftrightarrow {\big (}\neg A\lor \neg (A\to B){\big )}}.
Bayes' theorem with negatedA{\displaystyle A}gives
Ruling out the extremal caseP(¬A)=0{\displaystyle P(\neg A)=0}(i.e.P(A)=1{\displaystyle P(A)=1}), one hasP(B|¬A)=P(B)⋅1−P(A|B)1−P(A){\displaystyle P(B\vert \neg A)=P(B)\cdot {\tfrac {1-P(A\vert B)}{1-P(A)}}}and in particular
Ruling out also the extremal caseP(B)=0{\displaystyle P(B)=0}, one finds they attain the maximum1{\displaystyle 1}simultaneously:
which (at least when having ruled outexplosiveantecedents) captures the classicalcontrapositionprinciple
Bayes' theorem represents a special case of deriving inverted conditional opinions insubjective logicexpressed as:
whereϕ~{\displaystyle {\widetilde {\phi }}}denotes the operator for inverting conditional opinions. The argument(ωB|AS,ωB|¬AS){\displaystyle (\omega _{B\vert A}^{S},\omega _{B\vert \lnot A}^{S})}denotes a pair of binomial conditional opinions given by sourceS{\displaystyle S}, and the argumentaA{\displaystyle a_{A}}denotes theprior probability(aka. thebase rate) ofA{\displaystyle A}. The pair of derivative inverted conditional opinions is denoted(ωA|~BS,ωA|~¬BS){\displaystyle (\omega _{A{\tilde {|}}B}^{S},\omega _{A{\tilde {|}}\lnot B}^{S})}. The conditional opinionωA|BS{\displaystyle \omega _{A\vert B}^{S}}generalizes the probabilistic conditionalP(A|B){\displaystyle P(A\vert B)}, i.e. in addition to assigning a probability the sourceS{\displaystyle S}can assign any subjective opinion to the conditional statement(A|B){\displaystyle (A\vert B)}. A binomial subjective opinionωAS{\displaystyle \omega _{A}^{S}}is the belief in the truth of statementA{\displaystyle A}with degrees of epistemic uncertainty, as expressed by sourceS{\displaystyle S}. Every subjective opinion has a corresponding projected probabilityP(ωAS){\displaystyle P(\omega _{A}^{S})}. The application of Bayes' theorem to projected probabilities of opinions is ahomomorphism, meaning that Bayes' theorem can be expressed in terms of projected probabilities of opinions:
Hence, the subjective Bayes' theorem represents a generalization of Bayes' theorem.
A version of Bayes' theorem for 3 eventsresults from the addition of a third eventC{\displaystyle C}, withP(C)>0,{\displaystyle P(C)>0,}on which all probabilities are conditioned:
Using thechain rule
And, on the other hand
The desired result is obtained by identifying both expressions and solving forP(A|B∩C){\displaystyle P(A\vert B\cap C)}.
In genetics, Bayes' rule can be used to estimate the probability that someone has a specific genotype. Many people seek to assess their chances of being affected by a genetic disease or their likelihood of being a carrier for a recessive gene of interest. A Bayesian analysis can be done based on family history orgenetic testingto predict whether someone will develop a disease or pass one on to their children. Genetic testing and prediction is common among couples who plan to have children but are concerned that they may both be carriers for a disease, especially in communities with low genetic variance.
Example of a Bayesian analysis table for a female's risk for a disease based on the knowledge that the disease is present in her siblings but not in her parents or any of her four children. Based solely on the status of the subject's siblings and parents, she is equally likely to be a carrier as to be a non-carrier (this likelihood is denoted by the Prior Hypothesis). The probability that the subject's four sons would all be unaffected is 1/16 (1⁄2⋅1⁄2⋅1⁄2⋅1⁄2) if she is a carrier and about 1 if she is a non-carrier (this is the Conditional Probability). The Joint Probability reconciles these two predictions by multiplying them together. The last line (the Posterior Probability) is calculated by dividing the Joint Probability for each hypothesis by the sum of both joint probabilities.
Parental genetic testing can detect around 90% of known disease alleles in parents that can lead to carrier or affected status in their children. Cystic fibrosis is a heritable disease caused by an autosomal recessive mutation on the CFTR gene,located on the q arm of chromosome 7.
Here is a Bayesian analysis of a female patient with a family history of cystic fibrosis (CF) who has tested negative for CF, demonstrating how the method was used to determine her risk of having a child born with CF: because the patient is unaffected, she is either homozygous for the wild-type allele, or heterozygous. To establish prior probabilities, a Punnett square is used, based on the knowledge that neither parent was affected by the disease but both could have been carriers:
Given that the patient is unaffected, there are only three possibilities. Within these three, there are two scenarios in which the patient carries the mutant allele. Thus the prior probabilities are2⁄3and1⁄3.
Next, the patient undergoes genetic testing and tests negative for cystic fibrosis. This test has a 90% detection rate, so the conditional probabilities of a negative test are 1/10 and 1. Finally, the joint and posterior probabilities are calculated as before.
After carrying out the same analysis on the patient's male partner (with a negative test result), the chance that their child is affected is the product of the parents' respective posterior probabilities for being carriers times the chance that two carriers will produce an affected offspring (1⁄4).
Bayesian analysis can be done using phenotypic information associated with a genetic condition. When combined with genetic testing, this analysis becomes much more complicated. Cystic fibrosis, for example, can be identified in a fetus with an ultrasound looking for an echogenic bowel, one that appears brighter than normal on a scan. This is not a foolproof test, as an echogenic bowel can be present in a perfectly healthy fetus. Parental genetic testing is very influential in this case, where a phenotypic facet can be overly influential in probability calculation. In the case of a fetus with an echogenic bowel, with a mother who has been tested and is known to be a CF carrier, the posterior probability that the fetus has the disease is very high (0.64). But once the father has tested negative for CF, the posterior probability drops significantly (to 0.16).
Risk factor calculation is a powerful tool in genetic counseling and reproductive planning but cannot be treated as the only important factor. As above, incomplete testing can yield falsely high probability of carrier status, and testing can be financially inaccessible or unfeasible when a parent is not present.