# Bayes' theorem

In probability theory and statistics,

**Bayes' theorem**describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if the risk of developing health problems is known to increase with age, Bayes’s theorem allows the risk to an individual of a known age to be assessed more accurately than simply assuming that the individual is typical of the population as a whole.

One of the many applications of Bayes’s theorem is Bayesian inference, a particular approach to statistical inference. When applied, the probabilities involved in Bayes’ theorem may have different probability interpretations. With Bayesian probability interpretation, the theorem expresses how a degree of belief, expressed as a probability, should rationally change to account for the availability of related evidence. Bayesian inference is fundamental to Bayesian statistics.

Bayes’s theorem is named after Reverend Thomas Bayes, who first used conditional probability to provide an algorithm that uses evidence to calculate limits on an unknown parameter, published as

*An Essay towards solving a Problem in the Doctrine of Chances*. In what he called a scholium, Bayes extended his algorithm to any unknown prior cause. Independently of Bayes, Pierre-Simon Laplace in 1774, and later in his 1812

*Théorie analytique des probabilités*, used conditional probability to formulate the relation of an updated posterior probability from a prior probability, given evidence. Sir Harold Jeffreys put Bayes's algorithm and Laplace’s formulation on an axiomatic basis, writing that Bayes’s theorem “is to the theory of probability what the Pythagorean theorem is to geometry.”

## Statement of theorem

Bayes’s theorem is stated mathematically as the following equation:where and are events and.

- is a conditional probability: the likelihood of event occurring given that is true.
- is also a conditional probability: the likelihood of event occurring given that is true.
- and are the probabilities of observing and respectively; they are known as the marginal probability.
## Examples

### Drug testing

A particular test for whether someone has been using cannabis is 90% sensitive and 80% specific, meaning it leads to 90% true positive results for cannabis users and 80% true negative results for non-users, but also generates 20% false positives for non-users. Assuming 5% of people use cannabis, what is the probability that a random person who tests positive is really a cannabis user?Let mean "the probability that someone is a cannabis user given that they test positive." Then we can write:

Even if someone tests positive, the probability they are a cannabis user is only 19%, because in this group only 5% of people are users, most positives are false positives coming from the remaining 95%.

If 1,000 people were tested:

- 950 are non-users and 190 of them give false positive
- 50 of them are users and 45 of them give true positive

The importance of specificity can be seen by calculating that even if sensitivity is raised to 100% and specificity remains at 80%, the probability of someone testing positive really being a cannabis user only rises from 19% to 21%, but if the sensitivity is held at 90% and the specificity is increased to 95%, the probability rises to 49%.

### Cancer rate

Even if 100% of patients with pancreatic cancer have a certain symptom, when someone has the same symptom, it does not mean that this person has a 100% chance of getting pancreatic cancer. Assume the incidence rate of pancreatic cancer is 1/100000, while 1/10000 healthy individuals have the same symptoms worldwide, the probability of having pancreatic cancer given the symptoms is only 9.1%, and the other 90.9% could be "false positives".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 more complicated example

A factory produces an item 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; similarly, 3% of machine B's items and 1% of machine 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 Machine A, 300 by Machine B, and 500 by Machine C. Machine A will produce 5% × 200 = 10 defective items, Machine B 3% × 300 = 9, and Machine C 1% × 500 = 5, for a total of 24. Thus, the likelihood that a randomly selected defective item was produced by machine C is 5/24.

This problem can also be solved using Bayes' Theorem: Let

*X*denote the event that a randomly chosen item was made by the

_{i}*i*

^{th}machine. Let

*Y*denote 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*= 0.05. Overall, we have

To answer the original question, we first find

*P*. That can be done in the following way:

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*

_{C}. By Bayes’ theorem,

Given that the item is defective, the probability that it was made by machine C is 5/24. Although machine C produces half of the total output, it produces 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*= 1/2 by the smaller posterior probability

*P*= 5/24.

## Interpretations

The interpretation of Bayes’ Rule depends on the interpretation of probability ascribed to the terms. The two main interpretations are described below. Figure 2 shows a geometric visualization similar to Figure 1. Gerd Gigerenzer and co-authors have pushed hard for teaching Bayes Rule this way, with special emphasis on teaching it to physicians. An example is Will Kurt's webpage,"Bayes' Theorem with Lego," later turned into the book,*Bayesian Statistics the Fun Way: Understanding Statistics and Probability with Star Wars, LEGO, and Rubber Ducks.*Zhu and Gigerenzer found in 2006 that whereas 0% of 4th, 5th, and 6th-graders could solve word problems after being taught with formulas, 19%, 39%, and 53% could after being taught with frequency boxes, and that the learning was either thorough or zero.

### Bayesian interpretation

In the Bayesian 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 even remain the same, depending on the results. For proposition*A*and evidence

*B*,

For more on the application of Bayes' theorem under the Bayesian interpretation of probability, see Bayesian inference.

### Frequentist interpretation

In the frequentist interpretation, probability measures a “proportion of outcomes.” For example, suppose an experiment is performed many times.*P*is the proportion of outcomes with property

*A*and

*P*is the proportion with property

*B*.

*P*is the proportion of outcomes with property

*B*

*out of*outcomes with property

*A*, and

*P*is the proportion of those with

*A*

*out of*those with

*B*.

The role of Bayes’ theorem is best visualized with tree diagrams such as Figure 3. The two diagrams partition the same outcomes by

*A*and

*B*in opposite orders, to obtain the inverse probabilities. Bayes' theorem links the different partitionings.

#### Example

An entomologist spots what might, due to the pattern on its back, be a rare subspecies of beetle. A full 98% of the members of the rare subspecies have the pattern, so*P*= 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 is

*P*?

From the extended form of Bayes’ theorem,

## Forms

### Events

#### Simple form

For events*A*and

*B*, provided that

*P*≠ 0,

In many applications, for instance in Bayesian inference, the event

*B*is fixed in the discussion, and we wish to consider the impact of its having been observed on our belief in various possible events

*A*. In such a situation the denominator of the last expression, the probability of the given evidence

*B*, is fixed; what we want to vary is

*A*. Bayes’ theorem then shows that the posterior probabilities are proportional to the numerator, so the last equation becomes:

In words, the posterior is proportional to the prior times the likelihood.

If events

*A*

_{1},

*A*

_{2},..., 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 event

*A*, the event

*A*itself and its complement ¬

*A*are exclusive and exhaustive. Denoting the constant of proportionality by

*c*we have

Adding these two formulas we deduce that

or

#### Alternative form

Another form of Bayes’ theorem for two competing statements or hypotheses is:For an epistemological interpretation:

For proposition

*A*and evidence or background

*B*,

- is the prior probability, the initial degree of belief in
*A*. - is the corresponding initial degree of belief in
*not-A*, that*A*is false, where - is the conditional probability or likelihood, the degree of belief in
*B*given that proposition*A*is true. - is the conditional probability or likelihood, the degree of belief in
*B*given that proposition*A*is false. - is the posterior probability, the probability of
*A*after taking into account*B*.#### Extended form

*P*and

*P*. It is then useful to compute

*P*using the law of total probability:

In the special case where

*A*is a binary variable:

### Random variables

Consider a sample space Ω generated by two random variables*X*and

*Y*. In principle, Bayes’ theorem applies to the events

*A*= and

*B*= .

However, terms become 0 at points where either variable has finite probability density. To remain useful, Bayes’ theorem must be formulated in terms of the relevant densities.

#### Simple form

If*X*is continuous and

*Y*is discrete,

where each is a density function.

If

*X*is discrete and

*Y*is continuous,

If both

*X*and

*Y*are continuous,

#### Extended form

A continuous event space is often conceptualized in terms of the numerator terms. It is then useful to eliminate the denominator using the law of total probability. For*f*, this becomes an integral:

_{Y}### Bayes’ rule

Bayes’ theorem in odds form is:where

is called the Bayes factor or likelihood 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 the Bayes factor, or in other words, the posterior is proportional to the prior times the likelihood.

In the special case that and, one writes, and uses a similar abbreviation for the Bayes factor and for the conditional odds. The odds on is by definition the odds for and against. Bayes’ rule can then be written in the abbreviated form

or, in word, the posterior odds on equals the prior odds on times the likelihood ratio for given information. In short,

**posterior odds equals prior odds times likelihood ratio**.

## Derivation

### For events

Bayes’ theorem may be derived from the definition of conditional probability:where is the joint probability of both A and B being true, because

### For random variables

For two continuous random variables*X*and

*Y*, Bayes’ theorem may be analogously derived from the definition of conditional density:

Therefore,

## Correspondence to other mathematical frameworks

### Propositional logic

*Bayes’ theorem*represents a generalisation of contraposition which in propositional logic can be expressed as:

The corresponding formula in terms of probability calculus is Bayes' theorem which in its expanded form is expressed as:

In the equation above the conditional probability generalizes the logical statement, i.e. in addition to assigning TRUE or FALSE we can also assign any probability to the statement. The term denotes the prior probability of. Assume that is equivalent to being TRUE, and that is equivalent to being FALSE. It is then easy to see that when i.e. when is TRUE. This is because so that the fraction on the right-hand side of the equation above is equal to 1, and hence which is equivalent to being TRUE. Hence, Bayes’ theorem represents a generalization of contraposition.

### Subjective logic

*Bayes’ theorem*represents a special case of conditional inversion in subjective logic expressed as:

where denotes the operator for conditional inversion. The argument denotes a pair of binomial conditional opinions given by source, and the argument denotes the prior probability of. The pair of inverted conditional opinions is denoted. The conditional opinion generalizes the probabilistic conditional, i.e. in addition to assigning a probability the source can assign any subjective opinion to the conditional statement. A binomial subjective opinion is the belief in the truth of statement with degrees of uncertainty, as expressed by source. Every subjective opinion has a corresponding projected probability. The projected probability of opinions applied to Bayes’ theorem produces a homomorphism so that Bayes’ theorem can be expressed in terms of the projected probabilities of opinions:

Hence, the subjective Bayes’ theorem represents a generalization of Bayes’ theorem.

## Generalizations

### Conditioned version

A conditioned version of the Bayes' theorem results from the addition of a third event on which all probabilities are conditioned:#### Derivation

Using the chain ruleAnd, on the other hand

The desired result is obtained by identifying both expressions and solving for.

## History

Bayes’ theorem was named after Thomas Bayes, who studied how to compute a distribution for the probability parameter of a binomial distribution. Bayes’s unpublished manuscript was significantly edited by Richard Price before it was posthumously read at the Royal Society. Price edited Bayes’s major work “An Essay towards solving a Problem in the Doctrine of Chances”, which appeared in*Philosophical Transactions*, and contains Bayes’ theorem. Price wrote an introduction to the paper which provides some of the philosophical basis of Bayesian statistics. In 1765, he was elected a Fellow of the Royal Society in recognition of his work on the legacy of Bayes.

The French mathematician Pierre-Simon Laplace reproduced and extended Bayes's results in 1774, apparently unaware of Bayes's work. The Bayesian interpretation of probability was developed mainly by Laplace.

Stephen Stigler used a Bayesian argument to conclude that Bayes’ theorem was discovered by Nicholas Saunderson, a blind English mathematician, some time before Bayes; that interpretation, however, has been disputed.

Martyn Hooper and Sharon McGrayne have argued that Richard Price's contribution was substantial:

## Use in Genetic Prediction and Testing

In genetics, Bayes’ theorem can be used to calculate the probability of an individual having a specific genotype. Many people seek to approximate 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 or genetic testing, in order to predict whether an individual will develop a disease or pass one on to their children. Genetic testing and prediction is a common practice among couples who plan to have children but are concerned that they may both be carriers for a disease, especially within communities with low genetic variance.The first step in Bayesian analysis for genetics is to propose mutually exclusive hypotheses: for a specific allele, an individual either is or is not a carrier. Next, four probabilities are calculated: Prior Probability, Conditional Probability, Joint Probability, and Posterior Probability. This type of analysis can be done based purely on family history of a condition or in concert with genetic testing.

### Using Pedigree to Calculate Probabilities

Example of a Bayesian Analysis Table for a female individual’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. However, the probability that the subject’s four sons would all be unaffected is 1/16 if she is a carrier, about 1 if she is a non-carrier. The Joint Probability reconciles these two predictions by multiplying them together. The last line is calculated by dividing the Joint Probability for each hypothesis by the sum of both joint probabilities.### Using genetic test results

Prenatal genetic testing, while still a controversial practice, can detect around 90% of known disease alleles in parents that can lead to carrier or affected status in their child. Cystic fibrosis is a heritable disease caused by an autosomal recessive mutation on the CFTR gene, located on the q arm of chromosome 7.Bayesian analysis of a female patient with a family history of cystic fibrosis, who has tested negative for CF, demonstrating how this 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:

W Homozygous for the wild- type allele | M Heterozygous | |

W Homozygous for the wild- type allele | WW | MW |

M Heterozygous | MW | MM |

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 are ⅔ and ⅓.

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.

Hypothesis | Hypothesis 1: Patient is a carrier | Hypothesis 2: Patient is not a carrier |

Prior Probability | 2/3 | 1/3 |

Conditional Probability of a negative test | 1/10 | 1 |

Joint Probability | 1/15 | 1/3 |

Posterior Probability | 1/6 | 5/6 |

After carrying out the same analysis on the patient’s male partner, the chances of their child being affected is equal to the product of the parents’ respective prior probabilities for being carriers times the chances that two carriers will produce an affected offspring.

### Genetic testing done in parallel with other risk factor identification.

Bayesian analysis can be done using phenotypic information associated with a genetic condition, and when combined with genetic testing this analysis becomes much more complicated. Cystic Fibrosis, for example, can be identified in a fetus through an ultrasound looking for an echogenic bowel, meaning one that appears brighter than normal on a scan2. 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 actually has the disease is very high. However, once the father has tested negative for CF, the posterior probability drops significantly.Risk factor calculation is a powerful tool in genetic counseling and reproductive planning, but it cannot be treated as the only important factor to consider. 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.