Bayes' Theorem and Conditional Probability

Bayes' theorem is a formula that describes how to update the probabilities of hypotheses when given evidence. It follows simply from the axioms of conditional probability, but can be used to powerfully reason about a wide range of problems involving belief updates.

Given a hypothesis \(H\) and evidence \(E\), Bayes' theorem states that the relationship between the probability of the hypothesis before getting the evidence \(P(H)\) and the probability of the hypothesis after getting the evidence \(P(H \mid E)\) is

Many modern machine learning techniques rely on Bayes' theorem. For instance, spam filters use Bayesian updating to determine whether an email is real or spam, given the words in the email. Additionally, many specific techniques in statistics, such as calculating \(p\)-values or interpreting medical results, are best described in terms of how they contribute to updating hypotheses using Bayes' theorem.

Contents

Explaining Counterintuitive Results

Probability problems are notorious for yielding surprising and counterintuitive results. One famous example--or a pair of examples--is the following:

  1. A couple has 2 children and the older child is a boy. If the probabilities of having a boy or a girl are both 50%, what's the probability that the couple has two boys?
    We already know that the older child is a boy. The probability of two boys is equivalent to the probability that the younger child is a boy, which is \(50\%\).
  2. A couple has two children, of which at least one is a boy. If the probabilities of having a boy or a girl are both \(50\%\), what is the probability that the couple has two boys?

Deriving Bayes' Theorem

Bayes' theorem centers on relating different conditional probabilities. A conditional probability is an expression of how probable one event is given that some other event occurred (a fixed value). For instance, "what is the probability that the sidewalk is wet?" will have a different answer than "what is the probability that the sidewalk is wet given that it rained earlier?"

For a joint probability distribution over events \(A\) and \(B\), \(P(A \cap B)\), the conditional probability of \(A\) given \(B\) is defined as

In the sidewalk example, where \(A\) is "the sidewalk is wet" and \(B\) is "it rained earlier," this expression reads as "the probability the sidewalk is wet given that it rained earlier is equal to the probability that the sidewalk is wet and it rains over the probability that it rains."

Note that \(P(A \cap B)\) is the probability of both \(A\) and \(B\) occurring, which is the same as the probability of \(A\) occurring times the probability that \(B\) occurs given that \(A\) occurred: \(P(B \mid A) \times P(A).\) Using the same reasoning, \(P(A \cap B)\) is also the probability that \(B\) occurs times the probability that \(A\) occurs given that \(B\) occurs: \(P(A \mid B) \times P(B)\). The fact that these two expressions are equal leads to Bayes' Theorem. Expressed mathematically, this is:

\[\begin P(A \mid B) &= \frac, \text < if >P(B) \neq 0, \\ P(B \mid A) &= \frac, \text < if >P(A) \neq 0, \\ \Rightarrow P(A\cap B) &= P(A\mid B)\times P(B)=P(B\mid A)\times P(A), \\ \Rightarrow P(A \mid B) &= \frac , \text < if >P(B) \neq 0. \end\]

Notice that our result for dependent events and for Bayes’ theorem are both valid when the events are independent. In these instances, \(P(A \mid B) = P(A)\) and \(P(B \mid A) = P(B)\), so the expressions simplify.

While this is an equation that applies to any probability distribution over events \(A\) and \(B\), it has a particularly nice interpretation in the case where \(A\) represents a hypothesis \(H\) and \(B\) represents some observed evidence \(E\). In this case, the formula can be written as

This relates the probability of the hypothesis before getting the evidence \(P(H)\), to the probability of the hypothesis after getting the evidence, \(P(H \mid E)\). For this reason, \(P(H)\) is called the prior probability, while \(P(H \mid E)\) is called the posterior probability. The factor that relates the two, \(\frac\), is called the likelihood ratio. Using these terms, Bayes' theorem can be rephrased as "the posterior probability equals the prior probability times the likelihood ratio."

If a single card is drawn from a standard deck of playing cards, the probability that the card is a king is 4/52, since there are 4 kings in a standard deck of 52 cards. Rewording this, if \(\text\) is the event "this card is a king," the prior probability \(P(\text) = \frac = \frac.\)

If evidence is provided (for instance, someone looks at the card) that the single card is a face card, then the posterior probability \(P(\text \mid \text)\) can be calculated using Bayes' theorem:

\[P(\text \mid \text) = \frac P(\text).\]

Since every King is also a face card, \(P(\text \mid \text) = 1\). Since there are 3 face cards in each suit (Jack, Queen, King) , the probability of a face card is \(P(\text) = \frac\). Combining these gives a likelihood ratio of \(\frac <\hspace\frac3\hspace > = \frac\).

Using Bayes' theorem gives \(P(\text \mid \text) = \frac \frac = \frac\). \(_\square\)

\[\frac<1>\] \[\frac\] \[\frac\] \[1\]

You randomly choose a treasure chest to open, and then randomly choose a coin from that treasure chest. If the coin you choose is gold, then what is the probability that you chose chest A?

Bayes' theorem clarifies the two-children problem from the first section:

1. A couple has two children, the older of which is a boy. What is the probability that they have two boys?

2. A couple has two children, one of which is a boy. What is the probability that they have two boys?

\[\] Define three events, \(A\), \(B\), and \(C\), as follows:

\[ \begin A & = \mbox< both children are boys>\\ B & = \mbox< the older child is a boy>\\ C & = \mbox < one of their children is a boy.>\end\]

Question 1 is asking for \(P(A \mid B)\), and Question 2 is asking for \(P(A \mid C)\). The first is computed using the simpler version of Bayes’ theorem:

\[P(A \mid B) = \frac = \frac< \frac\cdot 1 ><\frac> = \frac.\]

To find \(P(A \mid C)\), we must determine \(P(C)\), the prior probability that the couple has at least one boy. This is equal to \(1 - P(\mbox) = 1 - \frac=\frac\). Therefore the desired probability is

\[P(A \mid C) = \frac = \frac<\frac\cdot 1><\frac> = \frac. \ _\square \]

For a similarly paradoxical problem, see the Monty Hall problem.

Visualizing Bayes’ Theorem

Venn diagrams are particularly useful for visualizing Bayes' theorem, since both the diagrams and the theorem are about looking at the intersections of different spaces of events.

A disease is present in 5 out of 100 people, and a test that is 90% accurate (meaning that the test produces the correct result in 90% of cases) is administered to 100 people. If one person in the group tests positive, what is the probability that this one person has the disease?

The intuitive answer is that the one person is 90% likely to have the disease. But we can visualize this to show that it’s not accurate. First, draw the total population and the 5 people who have the disease:

The circle A represents 5 out 100, or 5% of the larger universe of 100 people.

Next, overlay a circle to represent the people who get a positive result on the test. We know that 90% of those with the disease will get a positive result, so need to cover 90% of circle A, but we also know that 10% of the population who does not have the disease will get a positive result, so we need to cover 10% of the non-disease carrying population (the total universe of 100 less circle A).

Circle B is covering a substantial portion of the total population. It actually covers more area than the total portion of the population with the disease. This is because 14 out of the total population of 100 (90% of the 5 people with the disease + 10% of the 95 people without the disease) will receive a positive result. Even though this is a test with 90% accuracy, this visualization shows that any one patient who tests positive (Circle B) for the disease only has a 32.14% (4.5 in 14) chance of actually having the disease.

Diagnosing Disease

Bayes’ theorem can show the likelihood of getting false positives in scientific studies. An in-depth look at this can be found in Bayesian theory in science and math.

Many medical diagnostic tests are said to be \(X\)% accurate, for instance 99% accurate, referring specifically to the probability that the test result is correct given your condition (or lack thereof). This is not the same as the posterior probability of having the disease given the result of the test. To see this in action, consider the following problem.

Submit your answer

The world had been harmed by a widespread Z-virus, which already turned 10% of the world's population into zombies.

The scientists then invented a test kit with the sensitivity of 90% and specificity of 70%: 90% of the infected people will be tested positive while 70% of the non-infected will be tested negative.

If the test kit showed a positive result, what would be the probability that the tested subject was truly zombie?

1% 50% 75% 99%

A disease test is advertised as being 99% accurate: if you have the disease, you will test positive 99% of the time, and if you don't have the disease, you will test negative 99% of the time.

If 1% of all people have this disease and you test positive, what is the probability that you actually have the disease?

More Examples

Balls numbered 1 through 20 are placed in a bag. Three balls are drawn out of the bag without replacement. What is the probability that all the balls have odd numbers on them?

In this situation, the events are not independent. There will be a \(\frac = \frac\) chance that any particular ball is odd. However, the probability that all the balls are odd is not \(\frac\). We do have that the probability that the first ball is odd is \(\frac.\) For the second ball, given that the first ball was odd, there are only 9 odd numbered balls that could be drawn from a total of 19 balls, so the probability is \(\frac\). For the third ball, since the first two are both odd, there are 8 odd numbered balls that could be drawn from a total of 18 remaining balls. So the probability is \(\frac\).

So the probability that all 3 balls are odd numbered is \(\frac \times \frac \times \frac = \frac.\) Notice that \(\frac \approx 0.105\), whereas \(\frac = 0.125.\) \(_\square\)

A family has two children. Given that one of the children is a boy, what is the probability that both children are boys?

We assume that the probability of a child being a boy or girl is \(\frac\). We solve this using Bayes’ theorem. We let \(B\) be the event that the family has one child who is a boy. We let \(A\) be the event that both children are boys. We want to find \(P(A \mid B) = \frac\). We can easily see that \(P(B \mid A) = 1\). We also note that \(P(A) = \frac\) and \(P(B) = \frac\). So \(P(A \mid B) = \frac<1 \times \frac><\frac> = \frac \). \(_\square\)

A family has two children. Given that one of the children is a boy, and that he was born on a Tuesday, what is the probability that both children are boys?

Your first instinct to this question might be to answer \(\frac\), since this is obviously the same question as the previous one. Knowing the day of the week a child is born on can’t possibly give you additional information, right?

Let’s assume that the probability of being born on a particular day of the week is \(\frac\) and is independent of whether the child is a boy or a girl. We let \(B\) be the event that the family has one child who is a boy born on Tuesday and \(A\) be the event that both children are boys, and apply Bayes’ Theorem. We notice right away that \(P(B \mid A)\) is no longer equal to one. Given that there are 7 days of the week, there are 49 possible combinations for the days of the week the two boys were born on, and 13 of these have a boy who was born on a Tuesday, so \(P( B \mid A) = \frac\). \(P(A)\) remains unchanged at \(\frac\). To calculate \(P(B)\), we note that there are \(14^2\ = 196\) possible ways to select the gender and the day of the week the child was born on. Of these, there are \(13^2 = 169\) ways which do not have a boy born on Tuesday, and \(196 - 169 = 27\) which do, so \(P(B) = \frac\). This gives is that \(P(A \mid B) = \frac< \frac \times \frac> <\frac> = \frac\). \(_\square\)

Note: This answer is certainly not \(\frac\), and is actually much closer to \(\frac\).

Submit your answer

Zeb's coin box contains 8 fair, standard coins (heads and tails) and 1 coin which has heads on both sides. He selects a coin randomly and flips it 4 times, getting all heads. If he flips this coin again, what is the probability it will be heads? (The answer value will be from 0 to 1, not as a percentage.)

Submit your answer

There are 10 boxes containing blue and red balls.

The number of blue balls in the \(n^\text\) box is given by \(B(n) = 2^n\).
The number of red balls in the \(n^\text\) box is given by \(R(n) = 1024 - B(n)\).

A box is picked at random, and a ball is chosen randomly from that box. If the ball is blue, and the probability that the \(10^\text\) box was picked can be expressed as \( \frac ab\), where \(a\) and \(b\) are coprime positive integers, find \(a+b\).

More probability questions

Photo credit: http://www.spi-global.com/

Cite as: Bayes' Theorem and Conditional Probability. Brilliant.org. Retrieved from https://brilliant.org/wiki/bayes-theorem/

Master concepts like these

Get started

Learn more in our Applied Probability course, built by experts for you.