StatlectThe Digital Textbook
Index > Fundamentals of probability

Bayes' rule

Bayes' rule, named after the English mathematician Thomas Bayes, is a rule for computing conditional probabilities.

The rule

Let A and $B$ be two events. Denote their probabilities by [eq1] and [eq2] and suppose that both [eq3] and [eq4]. Denote by [eq5] the conditional probability of A given $B$ and by [eq6] the conditional probability of $B$ given A. Bayes' rule states that:[eq7]

Bayes' rule is easily proved as follows:


Using the conditional probability formula:[eq8]and:[eq9]The second formula is re-arranged as follows:[eq10]which is then plugged into the first formula:[eq11]

The following example shows how Bayes' rule can be applied in a practical situation:

Example An HIV test gives a positive result with probability 98% when the patient is indeed affected by HIV, while it gives a negative result with 99% probability when the patient is not affected by HIV. If a patient is drawn at random from a population in which 0,1% of individuals are affected by HIV and he is found positive, what is the probability that he is indeed affected by HIV? In probabilistic terms, what we know about this problem can be formalized as follows:[eq12]Furthermore, the unconditional probability of being found positive can be derived using the law of total probability:[eq13]Therefore, using Bayes' rule:[eq14]Therefore, even if the test is conditionally very accurate, the unconditional probability of being affected by HIV when found positive is less than 10 per cent!


The quantities involved in Bayes' rule:[eq15]often take the following names:

  1. [eq16] is called prior probability or, simply, prior;

  2. [eq17] is called conditional probability or likelihood;

  3. [eq18] is called marginal probability;

  4. [eq19] is called posterior probability or, simply, posterior.

Solved exercises

Below you can find some exercises with explained solutions:

  1. Exercise set 1 (use Bayes' rule to compute posterior probabilities)

The book

Most learning materials found on this website are now available in a traditional textbook format.