Definitions

# Bayes' theorem

In probability theory, Bayes' theorem (often called Bayes' law after Thomas Bayes) relates the conditional and marginal probabilities of two random events. It is often used to compute posterior probabilities given observations. For example, a patient may be observed to have certain symptoms. Bayes' theorem can be used to compute the probability that a proposed diagnosis is correct, given that observation. (See example 2)

As a formal theorem, Bayes' theorem is valid in all common interpretations of probability. However, it plays a central role in the debate around the foundations of statistics: frequentist and Bayesian interpretations disagree about the ways in which probabilities should be assigned in applications. Frequentists assign probabilities to random events according to their frequencies of occurrence or to subsets of populations as proportions of the whole, while Bayesians describe probabilities in terms of beliefs and degrees of uncertainty. The articles on Bayesian probability and frequentist probability discuss these debates at greater length.

## Statement of Bayes' theorem

Bayes' theorem relates the conditional and marginal probabilities of events A and B, where B has a non-vanishing probability:

$P\left(A|B\right) = frac\left\{P\left(B | A\right), P\left(A\right)\right\}\left\{P\left(B\right)\right\}.$

Each term in Bayes' theorem has a conventional name:

Intuitively, Bayes' theorem in this form describes the way in which one's beliefs about observing 'A' are updated by having observed 'B'.

## An example

Suppose there is a co-ed school having 60% boys and 40% girls as students. The girl students wear trousers or skirts in equal numbers; the boys all wear trousers. An observer sees a (random) student from a distance; all they can see is that this student is wearing trousers. What is the probability this student is a girl?

It is clear that the probability is less than 40%, but by how much? Is it half that, since only half the girls are wearing trousers? The correct answer can be computed using Bayes' theorem.

The event A is that the student observed is a girl, and the event B is that the student observed is wearing trousers. To compute P(A|B), we first need to know:

• P(A), or the probability that the student is a girl regardless of any other information. Since the observers sees a random student, meaning that all students have the same probability of being observed, and the fraction of girls among the students is 40%, this probability equals 0.4.
• P(A'), or the probability that the student is a boy regardless of any other information (A' is the complementary event to A). This is 60%, or 0.6.
• P(B|A), or the probability of the student wearing trousers given that the student is a girl. As they are as likely to wear skirts as trousers, this is 0.5.
• P(B|A'), or the probability of the student wearing trousers given that the student is a boy. This is given as 1.
• P(B), or the probability of a (randomly selected) student wearing trousers regardless of any other information. Since P(B) = P(B|A)P(A) + P(B|A')P(A'), this is .

Given all this information, the probability of the observer having spotted a girl given that the observed student is wearing trousers can be computed by substituting these values in the formula:

$P\left(A|B\right) = frac\left\{P\left(B|A\right) P\left(A\right)\right\}\left\{P\left(B\right)\right\} = frac\left\{0.5 times 0.4\right\}\left\{0.8\right\} = 0.25,.$

As expected, it is less than 40%, but more than half that.

Another, essentially equivalent way of obtaining the same result is as follows. Assume, for concreteness, that there are 100 students, 60 boys and 40 girls. Among these, 60 boys and 20 girls wear trousers. All together there are 80 trouser-wearers, of which 20 are girls. Therefore the chance that a random trouser-wearer is a girl equals .

It is often helpful when calculating conditional probabilities to create a simple table containing the number of occurrences of each outcome, or the relative frequencies of each outcome, for each of the independent variables. The table below illustrates the use of this method for the above girl-or-boy example.

Girls Boys Total
Trousers
20
60
80
Skirts
20
0
20
Total
40
60
100

## Bayes' theorem in terms of likelihood

Bayes' theorem can also be interpreted in terms of likelihood:

$P\left(A|B\right) propto L\left(A | b\right), P\left(A\right).$

Here L(A|b) is the likelihood of A given fixed b. The rule is then an immediate consequence of the relationship $P\left(B | A\right) propto L\left(A | B\right)$.

With this terminology, the theorem may be paraphrased as

$mbox\left\{posterior\right\} = frac\left\{mbox\left\{likelihood\right\} times mbox\left\{prior\right\}\right\} \left\{alpha\right\}$
(where $alpha$ is a normalising constant equal to P(B)).

In words: the posterior probability is proportional to the product of the prior probability and the likelihood.

## Derivation from conditional probabilities

To derive the theorem, we start from the definition of conditional probability. The probability of event A given event B is

$P\left(A|B\right)=frac\left\{P\left(A cap B\right)\right\}\left\{P\left(B\right)\right\}.$

Equivalently, the probability of event B given event A is

$P\left(B|A\right) = frac\left\{P\left(A cap B\right)\right\}\left\{P\left(A\right)\right\}. !$

Rearranging and combining these two equations, we find

$P\left(A|B\right), P\left(B\right) = P\left(A cap B\right) = P\left(B|A\right), P\left(A\right). !$

This lemma is sometimes called the product rule for probabilities. Dividing both sides by P(B), providing that it is non-zero, we obtain Bayes' theorem:

$P\left(A|B\right) = frac\left\{P\left(A cap B\right)\right\}\left\{P\left(B\right)\right\} = frac\left\{P\left(B|A\right),P\left(A\right)\right\}\left\{P\left(B\right)\right\}. !$

## Alternative forms of Bayes' theorem

Bayes' theorem is often embellished by noting that

$P\left(B\right) = P\left(Acap B\right) + P\left(A^Ccap B\right) = P\left(B|A\right) P\left(A\right) + P\left(B|A^C\right) P\left(A^C\right),$

where AC is the complementary event of A (often called "not A"). So the theorem can be restated as the following formula

$P\left(A|B\right) = frac\left\{P\left(B | A\right), P\left(A\right)\right\}\left\{P\left(B|A\right) P\left(A\right) + P\left(B|A^C\right) P\left(A^C\right)\right\}. !$

More generally, where {Ai} forms a partition of the event space,

$P\left(A_i|B\right) = frac\left\{P\left(B | A_i\right), P\left(A_i\right)\right\}\left\{sum_j P\left(B|A_j\right),P\left(A_j\right)\right\} , !$

for any Ai in the partition.

### Bayes' theorem in terms of odds and likelihood ratio

Bayes' theorem can also be written neatly in terms of a likelihood ratio Λ and odds O as

$O\left(A|B\right)=O\left(A\right) cdot Lambda \left(A|B\right)$

where $O\left(A|B\right)=frac\left\{P\left(A|B\right)\right\}\left\{P\left(A^C|B\right)\right\} !$ are the odds of A given B,

and $O\left(A\right)=frac\left\{P\left(A\right)\right\}\left\{P\left(A^C\right)\right\} !$ are the odds of A by itself,

while $Lambda \left(A|B\right) = frac\left\{L\left(A|B\right)\right\}\left\{L\left(A^C|B\right)\right\} = frac\left\{P\left(B|A\right)\right\}\left\{P\left(B|A^C\right)\right\} !$ is the likelihood ratio.

### Bayes' theorem for probability densities

There is also a version of Bayes' theorem for continuous distributions. It is somewhat harder to derive, since probability densities, strictly speaking, are not probabilities, so Bayes' theorem has to be established by a limit process; see Papoulis (citation below), Section 7.3 for an elementary derivation. Bayes' theorem for probability densities is formally similar to the theorem for probabilities:

$f_X\left(x|Y=y\right) = frac\left\{f_\left\{X,Y\right\}\left(x,y\right)\right\}\left\{f_Y\left(y\right)\right\} = frac\left\{f_Y\left(y|X=x\right),f_X\left(x\right)\right\}\left\{f_Y\left(y\right)\right\} = frac\left\{f_Y\left(y|X=x\right),f_X\left(x\right)\right\}\left\{int_\left\{-infty\right\}^\left\{infty\right\} f_Y\left(y|X=xi \right),f_X\left(xi \right),dxi \right\}.!$

There is an analogous statement of the law of total probability, which is used in the denominator:

$f_Y\left(y\right) = int_\left\{-infty\right\}^\left\{infty\right\} f_Y\left(y|X=x \right),f_X\left(x\right),dx .!$

As in the discrete case, the terms have standard names.

$f_\left\{X,Y\right\}\left(x,y\right),$ is the joint distribution of X and Y,
$f_X\left(x|Y=y\right),$ is the posterior distribution of X given Y=y,
$f_Y\left(y|X=x\right) = L\left(x|y\right),$ is (as a function of x) the likelihood function of X given Y=y,
and
$f_X\left(x\right),$
and
$f_Y\left(y\right)!$

are the marginal distributions of X and Y respectively, with $f_X\left(x\right),$ being the prior distribution of X.

### Abstract Bayes' theorem

Given two absolutely continuous probability measures $P sim Q$ on the probability space $\left(Omega, mathcal\left\{F\right\}\right)$ and a sigma-algebra $mathcal\left\{G\right\} subset mathcal\left\{F\right\}$, the abstract Bayes theorem for a $mathcal\left\{F\right\}$-measurable random variable $X$ becomes

$E_P\left[X|mathcal\left\{G\right\}\right] = frac\left\{E_Q\left[frac\left\{dP\right\}\left\{dQ\right\} X |mathcal\left\{G\right\}\right]\right\}\left\{E_Q\left[frac\left\{dP\right\}\left\{dQ\right\}|mathcal\left\{G\right\}\right]\right\}$.

Proof :

by definition of conditional probability,

$E_P\left[X|mathcal\left\{G\right\}\right] = frac\left\{E_P\left[X 1_mathcal\left\{G\right\}\right]\right\}\left\{E_P\left[mathcal\left\{G\right\}\right]\right\}$

and we have also

$E_Q\left[frac\left\{dP\right\}\left\{dQ\right\} X|mathcal\left\{G\right\}\right] = frac\left\{E_Q\left[frac\left\{dP\right\}\left\{dQ\right\} X 1_mathcal\left\{G\right\}\right]\right\}\left\{E_Q\left[mathcal\left\{G\right\}\right]\right\} = frac\left\{E_P\left[X 1_mathcal\left\{G\right\}\right]\right\}\left\{E_Q\left[mathcal\left\{G\right\}\right]\right\}$

$E_Q\left[frac\left\{dP\right\}\left\{dQ\right\}|mathcal\left\{G\right\}\right] = frac\left\{E_Q\left[frac\left\{dP\right\}\left\{dQ\right\} 1_mathcal\left\{G\right\}\right]\right\}\left\{E_Q\left[mathcal\left\{G\right\}\right]\right\} = frac\left\{E_P\left[1_mathcal\left\{G\right\}\right]\right\}\left\{E_Q\left[mathcal\left\{G\right\}\right]\right\}$

This formulation is used in Kalman filtering to find Zakai equations. It is also used in financial mathematics for change of numeraire techniques.

### Extensions of Bayes' theorem

Theorems analogous to Bayes' theorem hold in problems with more than two variables. For example:

$P\left(A|B cap C\right) = frac\left\{P\left(A\right) , P\left(B|A\right) , P\left(C|A cap B\right)\right\}\left\{P\left(B\right) , P\left(C|B\right)\right\},.$

This can be derived in a few steps from Bayes' theorem and the definition of conditional probability:

$P\left(A|B cap C\right) = frac\left\{P\left(A cap B cap C\right)\right\}\left\{P\left(B cap C\right)\right\} = frac\left\{P\left(C|A cap B\right) , P\left(A cap B\right)\right\}\left\{P\left(B\right) , P\left(C|B\right)\right\} = frac\left\{P\left(A\right) , P\left(B|A\right) , P\left(C|A cap B\right)\right\}\left\{P\left(B\right) , P\left(C|B\right)\right\},.$

Similarly,

$P\left(A|B cap C\right) = frac\left\{P\left(B|A cap C\right) , P\left(A|C\right)\right\}\left\{P\left(B|C\right)\right\},,$

which can be regarded as a conditional Bayes' Theorem, and can be derived by as follows:

$P\left(A|B cap C\right) = frac\left\{P\left(A cap B cap C\right)\right\}\left\{P\left(B cap C\right)\right\} = frac\left\{P\left(B|A cap C\right) , P\left(A|C\right) , P\left(C\right)\right\}\left\{P\left(C\right) , P\left(B|C\right)\right\} = frac\left\{P\left(B|A cap C\right) , P\left(A|C\right)\right\}\left\{P\left(B|C\right)\right\},.$

A general strategy is to work with a decomposition of the joint probability, and to marginalize (integrate) over the variables that are not of interest. Depending on the form of the decomposition, it may be possible to prove that some integrals must be 1, and thus they fall out of the decomposition; exploiting this property can reduce the computations very substantially. A Bayesian network, for example, specifies a factorization of a joint distribution of several variables in which the conditional probability of any one variable given the remaining ones takes a particularly simple form (see Markov blanket).

## Further examples

### Example 1: Drug testing

Bayes' theorem is useful in evaluating the result of drug tests. Suppose a certain drug test is 99% sensitive and 99% specific, that is, the test will correctly identify a drug user as testing positive 99% of the time, and will correctly identify a non-user as testing negative 99% of the time. This would seem to be a relatively accurate test, but Bayes' theorem will reveal a potential flaw. Let's assume a corporation decides to test its employees for opium use, and 0.5% of the employees use the drug. We want to know the probability that, given a positive drug test, an employee is actually a drug user. Let "D" be the event of being a drug user and "N" indicate being a non-user. Let "+" be the event of a positive drug test. We need to know the following:

• P(D), or the probability that the employee is a drug user, regardless of any other information. This is 0.005, since 0.5% of the employees are drug users. This is the prior probability of D.
• P(N), or the probability that the employee is not a drug user. This is , or 0.995.
• P(+|D), or the probability that the test is positive, given that the employee is a drug user. This is 0.99, since the test is 99% accurate.
• P(+|N), or the probability that the test is positive, given that the employee is not a drug user. This is 0.01, since the test will produce a false positive for 1% of non-users.
• P(+), or the probability of a positive test event, regardless of other information. This is 0.0149 or 1.49%, which is found by adding the probability that a true positive result will appear (= 99% x 0.5% = 0.495%) plus the probability that a false positive will appear (= 1% x 99.5% = 0.995%). This is the prior probability of +.

Given this information, we can compute the posterior probability P(D|+) of an employee who tested positive actually being a drug user:

begin\left\{align\right\}P\left(D|+\right) & = frac\left\{P\left(+ | D\right) P\left(D\right)\right\}\left\{P\left(+\right)\right\}
& = frac{P(+ | D) P(D)}{P(+ | D) P(D) + P(+ | N) P(N)} & = frac{0.99 times 0.005}{0.99 times 0.005 + 0.01 times 0.995} & = 0.3322.end{align}

Despite the apparently high accuracy of the test, the probability that an employee who tested positive actually did use drugs is only about 33%, so it is actually more likely that the employee is not a drug user. The rarer the condition for which we are testing, the greater the percentage of positive tests that will be false positives.

### Example 2: Bayesian inference

Applications of Bayes' theorem often assume the philosophy underlying Bayesian probability that uncertainty and degrees of belief can be measured as probabilities. One such example follows. For additional worked out examples, including simpler examples, please see the article on the examples of Bayesian inference.

We describe the marginal probability distribution of a variable A as the prior probability distribution or simply the 'prior'. The conditional distribution of A given the "data" B is the posterior probability distribution or just the 'posterior'.

Suppose we wish to know about the proportion r of voters in a large population who will vote "yes" in a referendum. Let n be the number of voters in a random sample (chosen with replacement, so that we have statistical independence) and let m be the number of voters in that random sample who will vote "yes". Suppose that we observe n = 10 voters and m = 7 say they will vote yes. From Bayes' theorem we can calculate the probability distribution function for r using

$f\left(r | n=10, m=7\right) =$
frac {f(m=7 | r, n=10) , f(r)} {int_0^1 f(m=7|r, n=10) , f(r) , dr}. !

From this we see that from the prior probability density function f(r) and the likelihood function L(r) = f(m = 7|r, n = 10), we can compute the posterior probability density function f(r|n = 10, m = 7).

The prior probability density function f(r) summarizes what we know about the distribution of r in the absence of any observation. We provisionally assume in this case that the prior distribution of r is uniform over the interval [0, 1]. That is, f(r) = 1. If some additional background information is found, we should modify the prior accordingly. However before we have any observations, all outcomes are equally likely.

Under the assumption of random sampling, choosing voters is just like choosing balls from an urn. The likelihood function L(r) = P(m = 7|r, n = 10,) for such a problem is just the probability of 7 successes in 10 trials for a binomial distribution.

$P\left(m=7 | r, n=10\right) = \left\{10 choose 7\right\} , r^7 , \left(1-r\right)^3.$

As with the prior, the likelihood is open to revision -- more complex assumptions will yield more complex likelihood functions. Maintaining the current assumptions, we compute the normalizing factor,

$int_0^1 P\left(m=7|r, n=10\right) , f\left(r\right) , dr = int_0^1 \left\{10 choose 7\right\} , r^7 , \left(1-r\right)^3 , 1 , dr = \left\{10 choose 7\right\} , frac\left\{1\right\}\left\{1320\right\} !$

and the posterior distribution for r is then

$f\left(r | n=10, m=7\right) =$
frac{{10 choose 7} , r^7 , (1-r)^3 , 1} {{10 choose 7} , frac{1}{1320}} = 1320 , r^7 , (1-r)^3

for r between 0 and 1, inclusive.

One may be interested in the probability that more than half the voters will vote "yes". The prior probability that more than half the voters will vote "yes" is 1/2, by the symmetry of the uniform distribution. In comparison, the posterior probability that more than half the voters will vote "yes", i.e., the conditional probability given the outcome of the opinion poll – that seven of the 10 voters questioned will vote "yes" – is

$1320int_\left\{1/2\right\}^1 r^7\left(1-r\right)^3,dr approx 0.887, !$

which is about an "89% chance".

### Example 3: The Monty Hall problem

We are presented with three doors - red, green, and blue - one of which has a prize. We choose the red door, which is not opened until the presenter performs an action. The presenter who knows what door the prize is behind, and who must open a door, but is not permitted to open the door we have picked or the door with the prize, opens the blue door and reveals that there is no prize behind it and subsequently asks if we wish to change our mind about our initial selection of red. What is the probability that the prize is behind each of the green and red doors?

Let us call the situation that the prize is behind a given door Ar, Ag, and Ab.

To start with, $P\left(A_r\right) = P\left(A_g\right) = P\left(A_b\right) = frac 1 3$, and to make things simpler we shall assume that we have already picked the red door.

Let us call B "the presenter opens the blue door". Without any prior knowledge, we would assign this a probability of 50%.

• In the situation where the prize is behind the red door, the host is free to pick between the green or the blue door at random. Thus, $P\left(B|A_r\right) = 1/2$
• In the situation where the prize is behind the green door, the host must pick the blue door. Thus, $P\left(B|A_g\right) = 1$
• In the situation where the prize is behind the blue door, the host must pick the green door. Thus, $P\left(B|A_b\right) = 0$

Thus,

$begin\left\{matrix\right\} P\left(A_r|B\right) & = frac\left\{P\left(B | A_r\right) P\left(A_r\right)\right\}\left\{P\left(B\right)\right\} & = frac\left\{frac 1 2 cdot frac 1 3\right\}\left\{frac 1 2\right\} & = frac 1 3 P\left(A_g|B\right) & = frac\left\{P\left(B | A_g\right) P\left(A_g\right)\right\}\left\{P\left(B\right)\right\} & = frac\left\{1 cdot frac 1 3\right\}\left\{frac 1 2\right\} & = frac 2 3 P\left(A_b|B\right) & = frac\left\{P\left(B | A_b\right) P\left(A_b\right)\right\}\left\{P\left(B\right)\right\} & = frac\left\{0 cdot frac 1 3\right\}\left\{frac 1 2\right\} & = 0. end\left\{matrix\right\}$

So, we should always choose the green door.

Note how this depends on the value of P(B).

## Historical remarks

An investigation by a statistics professor (Stigler 1983) suggests that Bayes' theorem was discovered by Nicholas Saunderson some time before Bayes.

Bayes' theorem is named after the Reverend Thomas Bayes (1702–1761), who studied how to compute a distribution for the parameter of a binomial distribution (to use modern terminology). His friend, Richard Price, edited and presented the work in 1763, after Bayes' death, as An Essay towards solving a Problem in the Doctrine of Chances. Pierre-Simon Laplace replicated and extended these results in an essay of 1774, apparently unaware of Bayes' work.

One of Bayes' results (Proposition 5) gives a simple description of conditional probability, and shows that it can be expressed independently of the order in which things occur:

If there be two subsequent events, the probability of the second b/N and the probability of both together P/N, and it being first discovered that the second event has also happened, from hence I guess that the first event has also happened, the probability I am right [i.e., the conditional probability of the first event being true given that the second has also happened] is P/b.

Note that the expression says nothing about the order in which the events occurred; it measures correlation, not causation. His preliminary results, in particular Propositions 3, 4, and 5, imply the result now called Bayes' Theorem (as described above), but it does not appear that Bayes himself emphasized or focused on that result.

Bayes' main result (Proposition 9 in the essay) is the following: assuming a uniform distribution for the prior distribution of the binomial parameter p, the probability that p is between two values a and b is


frac {int_a^b {n+m choose m} p^m (1-p)^n,dp} {int_0^1 {n+m choose m} p^m (1-p)^n,dp} !

where m is the number of observed successes and n the number of observed failures.

What is "Bayesian" about Proposition 9 is that Bayes presented it as a probability for the parameter p. So, one can compute probability for an experimental outcome, but also for the parameter which governs it, and the same algebra is used to make inferences of either kind.

Bayes states his question in a way that might make the idea of assigning a probability distribution to a parameter palatable to a frequentist. He supposes that a billiard ball is thrown at random onto a billiard table, and that the probabilities p and q are the probabilities that subsequent billiard balls will fall above or below the first ball.

Stephen Fienberg describes the evolution of the field from "inverse probability" at the time of Bayes and Laplace, and even of Harold Jeffreys (1939) to "Bayesian" in the 1950's. The irony is that this label was introduced by R.A. Fisher in a derogatory sense. So, historically, Bayes was not a "Bayesian". It is actually unclear whether or not he was a Bayesian in the modern sense of the term, i.e. whether or not he was interested in inference or merely in probability: the 1763 essay is more of a probability paper.

## References

### Versions of the essay

• Thomas Bayes (1763), "An Essay towards solving a Problem in the Doctrine of Chances. By the late Rev. Mr. Bayes, F. R. S. communicated by Mr. Price, in a letter to John Canton, A. M. F. R. S.", Philosophical Transactions, Giving Some Account of the Present Undertakings, Studies and Labours of the Ingenious in Many Considerable Parts of the World 53:370–418.
• Thomas Bayes (1763/1958) "Studies in the History of Probability and Statistics: IX. Thomas Bayes' Essay Towards Solving a Problem in the Doctrine of Chances", Biometrika 45:296–315. (Bayes' essay in modernized notation)
• Thomas Bayes "An essay towards solving a Problem in the Doctrine of Chances" (Bayes' essay in the original notation)

### Commentaries

• G. A. Barnard (1958) "Studies in the History of Probability and Statistics: IX. Thomas Bayes' Essay Towards Solving a Problem in the Doctrine of Chances", Biometrika 45:293–295. (biographical remarks)
• Daniel Covarrubias. "An Essay Towards Solving a Problem in the Doctrine of Chances" (an outline and exposition of Bayes' essay)
• Stephen M. Stigler (1982). "Thomas Bayes' Bayesian Inference," Journal of the Royal Statistical Society, Series A, 145:250–258. (Stigler argues for a revised interpretation of the essay; recommended)
• Isaac Todhunter (1865). A History of the Mathematical Theory of Probability from the time of Pascal to that of Laplace, Macmillan. Reprinted 1949, 1956 by Chelsea and 2001 by Thoemmes.
• An Intuitive Explanation of Bayesian Reasoning (includes biography)