WorldClass Statistics · Probability

Conditional probability

There can be rich relationships between two or more variables that are useful to understand. For example a car insurance company will consider information about a person’s driving history to assess the risk that they will be responsible for an accident. These types of relationships are the realm of conditional probabilities.

Exploring probabilities with a contingency table

The photo_classify data set represents a classifier a sample of 1822 photos from a photo sharing website. Data scientists have been working to improve a classifier for whether the photo is about fashion or not, and these 1822 photos represent a test for their classifier. Each photo gets two classifications: the first is called mach_learn and gives a classification from a machine learning (ML) system of either pred_fashion or pred_not. Each of these 1822 photos have also been classified carefully by a team of people, which we take to be the source of truth; this variable is called truth and takes values fashion and not. Figure 3.11 summarizes the results.

truth
fashion not Total
pred_fashion 197 22 219
mach_learn pred_not 112 1491 1603
Total 309 1513 1822

Figure 3.11. Contingency table summarizing the photo_classify data set.
A Venn diagram is shown, using boxes instead of circles, for the two categories of "ML Predicts Fashion" and "Fashion Photos" that partially overlap. The section of the rectangle for ML Predicts Fashion that is non-overlapping is labeled with 0.01. The section of the rectangle for Fashion Photos that is non-overlapping is labeled with 0.06. The overlapping section is labeled with 0.11. Outside of the rectangles is a label for "Neither" with a value 0.82.

Figure 3.12. A Venn diagram using boxes for the photo_classify data set.

Example 3.26

If a photo is actually about fashion, what is the chance the ML classifier correctly identified the photo as being about fashion?


We can estimate this probability using the data. Of the 309 fashion photos, the ML algorithm correctly classified 197 of the photos: P(mach_learn is pred_fashion given truth is fashion)=197309=0.638\begin{aligned} P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion} given \texttt{truth} is \texttt{fashion}}) = \frac{197{}}{309{}} = 0.638 \end{aligned}

Example 3.27

We sample a photo from the data set and learn the ML algorithm predicted this photo was not about fashion. What is the probability that it was incorrect and the photo is about fashion?


If the ML classifier suggests a photo is not about fashion, then it comes from the second row in the data set. Of these 1603 photos, 112 were actually about fashion: P(truth is fashion given mach_learn is pred_not)=1121603=0.070\begin{aligned} P(\text{\texttt{truth} is \texttt{fashion} given \texttt{mach\_{}learn} is \texttt{pred\_{}not}}) = \frac{112{}}{1603{}} = 0.070 \end{aligned}

Marginal and joint probabilities

Figure 3.11 includes row and column totals for each variable separately in the photo_classify data set. These totals represent marginal probabilities for the sample, which are the probabilities based on a single variable without regard to any other variables. For instance, a probability based solely on the mach_learn variable is a marginal probability: P(mach_learn is pred_fashion)=2191822=0.12\begin{aligned} P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}) = \frac{219{}}{1822{}} = 0.12 \end{aligned} A probability of outcomes for two or more variables or processes is called a joint probability: P(mach_learn is pred_fashion and truth is fashion)=1971822=0.11\begin{aligned} P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion} and \texttt{truth} is \texttt{fashion}}) = \frac{197{}}{1822{}} = 0.11 \end{aligned} It is common to substitute a comma for “and” in a joint probability, although using either the word “and” or a comma is acceptable:

P(mach_learn is pred_fashion, truth is fashion)P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion}, \texttt{truth} is \texttt{fashion}})
means the same thing as
P(mach_learn is pred_fashion and truth is fashion)P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion} and \texttt{truth} is \texttt{fashion}})

Marginal and joint probabilities

If a probability is based on a single variable, it is a marginal probability. The probability of outcomes for two or more variables or processes is called a joint probability.

We use table proportions to summarize joint probabilities for the photo_classify sample. These proportions are computed by dividing each count in Figure 3.11 by the table’s total, 1822, to obtain the proportions in Figure 3.13. The joint probability distribution of the mach_learn and truth variables is shown in Figure 3.14.

truth: fashion truth: not Total
mach_learn: pred_fashion 0.1081 0.0121 0.1202
mach_learn: pred_not 0.0615 0.8183 0.8798
Total 0.1696 0.8304 1.00

Figure 3.13. Probability table summarizing the photo_classify data set.
Joint outcome Probability
mach_learn is pred_fashion and truth is fashion 0.1081
mach_learn is pred_fashion and truth is not 0.0121
mach_learn is pred_not and truth is fashion 0.0615
mach_learn is pred_not and truth is not 0.8183
Total 1.0000

Figure 3.14. Joint probability distribution for the photo_classify data set.

Guided Practice 3.28

Verify Figure 3.14 represents a probability distribution: events are disjoint, all probabilities are non-negative, and the probabilities sum to 1.1

We can compute marginal probabilities using joint probabilities in simple cases. For example, the probability a randomly selected photo from the data set is about fashion is found by summing the outcomes where truth takes value fashion: P(truth is fashion)=P(mach_learn is pred_fashion and truth is fashion)+P(mach_learn is pred_not and truth is fashion)=0.1081+0.0615=0.1696\begin{aligned} P(\text{\texttt{truth} is \texttt{fashion}{}}) &= P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion} and \texttt{truth} is \texttt{fashion}{}}) \\ & \qquad + P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}not} and \texttt{truth} is \texttt{fashion}{}}) \\ &= 0.1081 + 0.0615 \\ &= 0.1696 \end{aligned}

Defining conditional probability

The ML classifier predicts whether a photo is about fashion, even if it is not perfect. We would like to better understand how to use information from a variable like mach_learn to improve our probability estimation of a second variable, which in this example is truth.

The probability that a random photo from the data set is about fashion is about 0.17. If we knew the machine learning classifier predicted the photo was about fashion, could we get a better estimate of the probability the photo is actually about fashion? Absolutely. To do so, we limit our view to only those 219 cases where the ML classifier predicted that the photo was about fashion and look at the fraction where the photo was actually about fashion: P(truth is fashion given mach_learn is pred_fashion)=197219=0.900\begin{aligned} P(\text{\texttt{truth} is \texttt{fashion} given \texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}) = \frac{197{}}{219{}} = 0.900 \end{aligned} We call this a conditional probability because we computed the probability under a condition: the ML classifier prediction said the photo was about fashion.

There are two parts to a conditional probability, the outcome of interest and the condition. It is useful to think of the condition as information we know to be true, and this information usually can be described as a known outcome or event. We generally separate the text inside our probability notation into the outcome of interest and the condition with a vertical bar: P(truth is fashion given mach_learn is pred_fashion)=P(truth is fashion ∣ mach_learn is pred_fashion)=197219=0.900\begin{aligned} && P(\text{\texttt{truth} is \texttt{fashion} given \texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}) \\ && \quad = P(\text{\texttt{truth} is \texttt{fashion}\ }| \text{\ \texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}) = \frac{197{}}{219{}} = 0.900 \end{aligned} The vertical bar “∣|” is read as given.

In the last equation, we computed the probability a photo was about fashion based on the condition that the ML algorithm predicted it was about fashion as a fraction: P(truth is fashion ∣ mach_learn is pred_fashion)=# cases where truth is fashion and mach_learn is pred_fashion# cases where mach_learn is pred_fashion=197219=0.900\begin{aligned} & P(\text{\texttt{truth} is \texttt{fashion}\ }| \text{\ \texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}) \\ &\quad = \frac{\text{\# cases where \texttt{truth} is \texttt{fashion} and \texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}} {\text{\# cases where \texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}} \\ &\quad = \frac{197{}}{219{}} = 0.900 \end{aligned} We considered only those cases that met the condition, mach_learn is pred_fashion, and then we computed the ratio of those cases that satisfied our outcome of interest, photo was actually about fashion.

Frequently, marginal and joint probabilities are provided instead of count data. For example, disease rates are commonly listed in percentages rather than in a count format. We would like to be able to compute conditional probabilities even when no counts are available, and we use the last equation as a template to understand this technique.

We considered only those cases that satisfied the condition, where the ML algorithm predicted fashion. Of these cases, the conditional probability was the fraction representing the outcome of interest, that the photo was about fashion. Suppose we were provided only the information in Figure 3.13, i.e. only probability data. Then if we took a sample of 1000 photos, we would anticipate about 12.0% or 0.120×1000=1200.120\times 1000 = 120 would be predicted to be about fashion (mach_learn is pred_fashion). Similarly, we would expect about 10.8% or 0.108×1000=1080.108\times 1000 = 108 to meet both the information criteria and represent our outcome of interest. Then the conditional probability can be computed as P(truth is fashion ∣ mach_learn is pred_fashion)=# (truth is fashion and mach_learn is pred_fashion)# (mach_learn is pred_fashion)=108120=0.1080.120=0.90\begin{aligned} &P(\text{\texttt{truth} is \texttt{fashion}}\ |\ \text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}) \\ &= \frac{\text{\# (\texttt{truth} is \texttt{fashion} and \texttt{mach\_{}learn} is \texttt{pred\_{}fashion})}} {\text{\# (\texttt{mach\_{}learn} is \texttt{pred\_{}fashion})}} \\ &= \frac{108}{120} = \frac{0.108}{0.120} = 0.90 \end{aligned} Here we are examining exactly the fraction of two probabilities, 0.108 and 0.120, which we can write as P(truth is fashion and mach_learn is pred_fashion)andP(mach_learn is pred_fashion).\begin{aligned} P(\text{\texttt{truth} is \texttt{fashion} and \texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}) \quad\text{and}\quad P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}). \end{aligned} The fraction of these probabilities is an example of the general formula for conditional probability.

Conditional probability

The conditional probability of outcome AA given condition BB is computed as the following: P(A∣B)=P(A and B)P(B)\begin{aligned} P(A | B) = \frac{P(A\text{ and }B)}{P(B)} \end{aligned}

Guided Practice 3.29

(a) Write out the following statement in conditional probability notation: “The probability that the ML prediction was correct, if the photo was about fashion”. Here the condition is now based on the photo’s truth status, not the ML algorithm.
(b) Determine the probability from part (a). Table 3.13 may be helpful.2

Guided Practice 3.30

(a) Determine the probability that the algorithm is incorrect if it is known the photo is about fashion.
(b) Using the answers from part (a) and Guided Practice 3.29(b), compute P(mach_learn is pred_fashion ∣ truth is fashion)+ P(mach_learn is pred_not ∣ truth is fashion)\begin{aligned} &P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion}} \ |\ \text{\texttt{truth} is \texttt{fashion}}) \\ &\qquad +\ P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}not}} \ |\ \text{\texttt{truth} is \texttt{fashion}}) \end{aligned} (c) Provide an intuitive argument to explain why the sum in (b) is 1.3

Smallpox in Boston, 1721

The smallpox data set provides a sample of 6,224 individuals from the year 1721 who were exposed to smallpox in Boston. Doctors at the time believed that inoculation, which involves exposing a person to the disease in a controlled form, could reduce the likelihood of death.

Each case represents one person with two variables: inoculated and result. The variable inoculated takes two levels: yes or no, indicating whether the person was inoculated or not. The variable result has outcomes lived or died. These data are summarized in Tables 3.15 and 3.16.

inoculated
yes no Total
lived 238 5136 5374
result died 6 844 850
Total 244 5980 6224

Figure 3.15. Contingency table for the smallpox data set.
inoculated
yes no Total
lived 0.0382 0.8252 0.8634
result died 0.0010 0.1356 0.1366
Total 0.0392 0.9608 1.0000

Figure 3.16. Table proportions for the smallpox data, computed by dividing each count by the table total, 6224.

Guided Practice 3.31

Write out, in formal notation, the probability a randomly selected person who was not inoculated died from smallpox, and find this probability.4

Guided Practice 3.32

Determine the probability that an inoculated person died from smallpox. How does this result compare with the result of Guided Practice 3.31?5

Guided Practice 3.33

The people of Boston self-selected whether or not to be inoculated. (a) Is this study observational or was this an experiment? (b) Can we infer any causal connection using these data? (c) What are some potential confounding variables that might influence whether someone lived or died and also affect whether that person was inoculated?6

General multiplication rule

Section 3.1.7 introduced the Multiplication Rule for independent processes. Here we provide the General Multiplication Rule for events that might not be independent.

General Multiplication Rule

If AA and BB represent two outcomes or events, then P(A and B)=P(A∣B)×P(B)\begin{aligned} P(A\text{ and }B) = P(A | B)\times P(B) \end{aligned}

It is useful to think of AA as the outcome of interest and BB as the condition.

General Multiplication Rule is simply a rearrangement of the conditional probability equation.

Example 3.34

Consider the smallpox data set. Suppose we are given only two pieces of information: 96.08% of residents were not inoculated, and 85.88% of the residents who were not inoculated ended up surviving. How could we compute the probability that a resident was not inoculated and lived?


We will compute our answer using the General Multiplication Rule and then verify it using Figure 3.16. We want to determine P(result = lived and inoculated = no)\begin{aligned} P(\text{\texttt{result} = \texttt{lived} and \texttt{inoculated} = \texttt{no}}) \end{aligned} and we are given that P(result = lived ∣ inoculated = no)=0.8588P(inoculated = no)=0.9608\begin{aligned} P(\text{\texttt{result} = \texttt{lived} }|\text{ \texttt{inoculated} = \texttt{no}}) &= 0.8588 &&P(\text{\texttt{inoculated} = \texttt{no}}) = 0.9608 \end{aligned} Among the 96.08% of people who were not inoculated, 85.88% survived: P(result = lived and inoculated = no)=0.8588×0.9608=0.8251\begin{aligned} P(\text{\texttt{result} = \texttt{lived} and \texttt{inoculated} = \texttt{no}}) = 0.8588 \times 0.9608 = 0.8251 \end{aligned} This is equivalent to the General Multiplication Rule. We can confirm this probability in Figure 3.16 at the intersection of no and lived (with a small rounding error).

Guided Practice 3.35

Use P(P(inoculated = yes)=0.0392) = 0.0392 and P(P(result = lived ∣| inoculated = yes)=0.9754) = 0.9754 to determine the probability that a person was both inoculated and lived.7

Guided Practice 3.36

If 97.54% of the inoculated people lived, what proportion of inoculated people must have died?8

Sum of conditional probabilities

Let A1A_1, ..., AkA_k represent all the disjoint outcomes for a variable or process. Then if BB is an event, possibly for another variable or process, we have: P(A1∣B)+⋯+P(Ak∣B)=1\begin{aligned} P(A_1|B) + \cdots + P(A_k|B) = 1 \end{aligned}

The rule for complements also holds when an event and its complement are conditioned on the same information: P(A∣B)=1−P(Ac∣B)\begin{aligned} P(A | B) = 1 - P(A^c | B) \end{aligned}

Guided Practice 3.37

Based on the probabilities computed above, does it appear that inoculation is effective at reducing the risk of death from smallpox?9

Independence considerations in conditional probability

If two events are independent, then knowing the outcome of one should provide no information about the other. We can show this is mathematically true using conditional probabilities.

Guided Practice 3.38

Let XX and YY represent the outcomes of rolling two dice.10

  1. What is the probability that the first die, XX, is 1?

  2. What is the probability that both XX and YY are 1?

  3. Use the formula for conditional probability to compute P(Y=P(Y = 1 ∣ X=\ |\ X = 1)).

  4. What is P(Y=1)P(Y=1)? Is this different from the answer from part (c)? Explain.

We can show in Guided Practice 3.38(c) that the conditioning information has no influence by using the Multiplication Rule for independence processes: P(Y=1 ∣ X=1)=P(Y=1 and X=1)P(X=1)=P(Y=1)×P(X=1)P(X=1)=P(Y=1)\begin{aligned} P(Y=\text{\texttt{1}}\ |\ X=\text{\texttt{1}}) &= \frac{P(Y=\text{\texttt{1} and }X=\text{\texttt{1}})} {P(X=\text{\texttt{1}})} \\ &= \frac{P(Y=\text{\texttt{1}}) \times P(X=\text{\texttt{1}})} {P(X=\text{\texttt{1}})} \\ &= P(Y=\text{\texttt{1}}) \\ \end{aligned}

Guided Practice 3.39

Ron is watching a roulette table in a casino and notices that the last five outcomes were black. He figures that the chances of getting black six times in a row is very small (about 1/641/64) and puts his paycheck on red. What is wrong with his reasoning?11

Tree diagrams

Tree diagrams are a tool to organize outcomes and probabilities around the structure of the data. They are most useful when two or more processes occur in a sequence and each process is conditioned on its predecessors.

The smallpox data fit this description. We see the population as split by inoculation: yes and no. Following this split, survival rates were observed for each group. This structure is reflected in the tree diagram shown in Figure 3.17. The first branch for inoculation is said to be the primary branch while the other branches are secondary.

A tree diagram with a primary branch "Inoculated" and a secondary branch "Result". The Inoculated primary branching leads to two options: "Yes" with a probability of 0.0392 and "No" with a probability of 0.9608. Each of these branches has secondary branches with conditional probabilities for the "Result" conditional on "Inoculated". The Inoculated Yes branch breaks into branches for "Lived" (0.9754) and "Died" (0.0246). These branches also provide the multiplied probabilities along the branches as well. For example, the Yes-and-Lived branching multiplies 0.0392 times 0.9754 to get 0.03824. The Yes-and-Died branching has a multiplied probability of 0.00096. Next, turning our attention to the "No" primary branch, it also has secondary branches of Lived and Died with conditional probabilities 0.8589 and 0.1411, respectively. It also shows the probabilities multiplied along each set of branches, with No-and-Lived as 0.82523 and No-and-Died as 0.13557.

Figure 3.17. A tree diagram of the smallpox data set.

Tree diagrams are annotated with marginal and conditional probabilities, as shown in Figure 3.17. This tree diagram splits the smallpox data by inoculation into the yes and no groups with respective marginal probabilities 0.0392 and 0.9608. The secondary branches are conditioned on the first, so we assign conditional probabilities to these branches. For example, the top branch in Figure 3.17 is the probability that result = lived conditioned on the information that inoculated = yes. We may (and usually do) construct joint probabilities at the end of each branch in our tree by multiplying the numbers we come across as we move from left to right. These joint probabilities are computed using the General Multiplication Rule: P(inoculated = yes and result = lived)=P(inoculated = yes)×P(result = lived∣inoculated = yes)=0.0392×0.9754=0.0382\begin{aligned} & P(\text{\texttt{inoculated} = \texttt{yes} and \texttt{result} = \texttt{lived}}) \\ &\quad = P(\text{\texttt{inoculated} = \texttt{yes}})\times P(\text{\texttt{result} = \texttt{lived}}| \text{\texttt{inoculated} = \texttt{yes}}) \\ &\quad = 0.0392\times 0.9754=0.0382 \end{aligned}

Example 3.40

Consider the midterm and final for a statistics class. Suppose 13% of students earned an A on the midterm. Of those students who earned an A on the midterm, 47% received an A on the final, and 11% of the students who earned lower than an A on the midterm received an A on the final. You randomly pick up a final exam and notice the student received an A. What is the probability that this student earned an A on the midterm?


The end-goal is to find P(midterm = A∣final = A)P(\text{\texttt{midterm} = \texttt{A}} | \text{\texttt{final} = \texttt{A}}). To calculate this conditional probability, we need the following probabilities: P(midterm = A and final = A)andP(final = A)\begin{aligned} P(\text{\texttt{midterm} = \texttt{A} and \texttt{final} = \texttt{A}}) \qquad\text{and}\qquad P(\text{\texttt{final} = \texttt{A}}) \end{aligned} However, this information is not provided, and it is not obvious how to calculate these probabilities. Since we aren’t sure how to proceed, it is useful to organize the information into a tree diagram:

A tree diagram with a primary branch "Midterm" and a secondary branch "Final". The Midterm primary branching leads to two options: "A" with a probability of 0.13 and "Other" with a probability of 0.87. Each of these branches has secondary branches with conditional probabilities for the "Final" conditional on "Midterm". The Midterm-A branch breaks into branches for "A", with a conditional probability of 0.47 with an A-and-A final probability of 0.0611, and an "other" secondary branch, with a conditional probability of 0.53 with an other-and-other final probability of 0.0689. Next, turning our attention to the Midterm-Other primary branch, it also has secondary branches of Final-A with a conditional probability of 0.11 and final probability of 0.0957, and an "Final-other" branch with a conditional probability of 0.89 and final probability of 0.7743.

When constructing a tree diagram, variables provided with marginal probabilities are often used to create the tree’s primary branches; in this case, the marginal probabilities are provided for midterm grades. The final grades, which correspond to the conditional probabilities provided, will be shown on the secondary branches.

With the tree diagram constructed, we may compute the required probabilities: P(midterm = A and final = A)=0.0611P(final = A)=P(midterm = other and final = A)+P(midterm = A and final = A)=0.0957+0.0611=0.1568\begin{aligned} &P(\text{\texttt{midterm} = \texttt{A} and \texttt{final} = \texttt{A}}) = 0.0611 \\ &P(\text{\texttt{final} = \texttt{A}}) \\ & \quad= P(\text{\texttt{midterm} = \texttt{other} and \texttt{final} = \texttt{A}}) + P(\text{\texttt{midterm} = \texttt{A} and \texttt{final} = \texttt{A}}) \\ & \quad= 0.0957 + 0.0611 = 0.1568 \end{aligned} The marginal probability, P(P(final = A)), was calculated by adding up all the joint probabilities on the right side of the tree that correspond to final = A. We may now finally take the ratio of the two probabilities: P(midterm = A∣final = A)=P(midterm = A and final = A)P(final = A)=0.06110.1568=0.3897\begin{aligned} P(\text{\texttt{midterm} = \texttt{A}} | \text{\texttt{final} = \texttt{A}}) &= \frac{P(\text{\texttt{midterm} = \texttt{A} and \texttt{final} = \texttt{A}})} {P(\text{\texttt{final} = \texttt{A}})} \\ &= \frac{0.0611}{0.1568} = 0.3897 \end{aligned} The probability the student also earned an A on the midterm is about 0.39.

Guided Practice 3.41

After an introductory statistics course, 78% of students can successfully construct tree diagrams. Of those who can construct tree diagrams, 97% passed, while only 57% of those students who could not construct tree diagrams passed. (a) Organize this information into a tree diagram. (b) What is the probability that a randomly selected student passed? (c) Compute the probability a student is able to construct a tree diagram if it is known that she passed.12

Bayes’ Theorem

In many instances, we are given a conditional probability of the form P(statement about variable 1 ∣ statement about variable 2)\begin{aligned} P(\text{statement about variable 1 } | \text{ statement about variable 2}) \end{aligned} but we would really like to know the inverted conditional probability: P(statement about variable 2 ∣ statement about variable 1)\begin{aligned} P(\text{statement about variable 2 } | \text{ statement about variable 1}) \end{aligned} Tree diagrams can be used to find the second conditional probability when given the first. However, sometimes it is not possible to draw the scenario in a tree diagram. In these cases, we can apply a very useful and general formula: Bayes’ Theorem.

We first take a critical look at an example of inverting conditional probabilities where we still apply a tree diagram.

Example 3.42

In Canada, about 0.35% of women over 40 will develop breast cancer in any given year. A common screening test for cancer is the mammogram, but this test is not perfect. In about 11% of patients with breast cancer, the test gives a false negative: it indicates a woman does not have breast cancer when she does have breast cancer. Similarly, the test gives a false positive in 7% of patients who do not have breast cancer: it indicates these patients have breast cancer when they actually do not. If we tested a random woman over 40 for breast cancer using a mammogram and the test came back positive – that is, the test suggested the patient has cancer – what is the probability that the patient actually has breast cancer?


Notice that we are given sufficient information to quickly compute the probability of testing positive if a woman has breast cancer (1.00−0.11=0.891.00-0.11=0.89). However, we seek the inverted probability of cancer given a positive test result. (Watch out for the non-intuitive medical language: a positive test result suggests the possible presence of cancer in a mammogram screening.) This inverted probability may be broken into two pieces: P(has BC ∣ mammogram+)=P(has BC and mammogram+)P(mammogram+)\begin{aligned} P(\text{has BC } | \text{ mammogram}^+\text{}) = \frac{P(\text{has BC and mammogram}^+\text{})}{P(\text{mammogram}^+\text{})} \end{aligned} where “has BC” is an abbreviation for the patient having breast cancer and “mammogram+^+” means the mammogram screening was positive. We can construct a tree diagram for these probabilities:

A tree diagram with a primary branch "Truth" and a secondary branch "Mammogram". The Truth primary branching leads to two options: "Cancer" with a probability of 0.0035 and "No Cancer" with a probability of 0.9965. Each of these branches has secondary branches with conditional probabilities for "Positive" and "Negative" mammogram outcomes conditional on whether the truth is having cancer or not. The Cancer primary branch breaks into branches for "Positive", with a conditional probability of 0.89 with a Cancer-and-Positive final probability of 0.00312, and a "Negative" secondary branch, with a conditional probability of 0.11 with a Cancer-and-Negative final probability of 0.00038. Next, turning our attention to the No-Cancer primary branch, it also has secondary branches of Positive with a conditional probability of 0.07 and final probability of 0.06976, and a Negative branch with a conditional probability of 0.93 and final probability of 0.92675.

The probability the patient has breast cancer and the mammogram is positive is P(has BC and mammogram+)=P(mammogram+ ∣ has BC)P(has BC)=0.89×0.0035=0.00312\begin{aligned} P(\text{has BC and mammogram}^+\text{}) &= P(\text{mammogram}^+\text{ } | \text{ has BC})P(\text{has BC}) \\ &= 0.89\times 0.0035 = 0.00312 \end{aligned} The probability of a positive test result is the sum of the two corresponding scenarios: P(mammogram+)=P(mammogram+ and has BC)+P(mammogram+ and no BC)=P(has BC)P(mammogram+ ∣ has BC)+P(no BC)P(mammogram+ ∣ no BC)=0.0035×0.89+0.9965×0.07=0.07288\begin{aligned} P(\text{mammogram}^+\text{}) &= P(\text{mammogram}^+\text{ and has BC}) \\ &\qquad\qquad + P(\text{mammogram}^+\text{ and no BC})\\ &= P(\text{has BC})P(\text{mammogram}^+\text{ } | \text{ has BC}) \\ &\qquad\qquad + P(\text{no BC})P(\text{mammogram}^+\text{ } | \text{ no BC}) \\ &= 0.0035\times 0.89 + 0.9965\times 0.07 = 0.07288 \end{aligned} Then if the mammogram screening is positive for a patient, the probability the patient has breast cancer is P(has BC ∣ mammogram+)=P(has BC and mammogram+)P(mammogram+)=0.003120.07288≈0.0428\begin{aligned} P(\text{has BC } | \text{ mammogram}^+\text{}) &= \frac{P(\text{has BC and mammogram}^+\text{})}{P(\text{mammogram}^+\text{})}\\ &= \frac{0.00312}{0.07288} \approx 0.0428 \end{aligned} That is, even if a patient has a positive mammogram screening, there is still only a 4% chance that she has breast cancer.

Example 3.42 highlights why doctors often run more tests regardless of a first positive test result. When a medical condition is rare, a single positive test isn’t generally definitive.

Consider again the last equation of Example 3.42. Using the tree diagram, we can see that the numerator (the top of the fraction) is equal to the following product: P(has BC and mammogram+)=P(mammogram+ ∣ has BC)P(has BC)\begin{aligned} P(\text{has BC and mammogram}^+\text{}) = P(\text{mammogram}^+\text{ } | \text{ has BC})P(\text{has BC}) \end{aligned} The denominator – the probability the screening was positive – is equal to the sum of probabilities for each positive screening scenario: P(mammogram+)=P(mammogram+ and no BC)+P(mammogram+ and has BC)\begin{aligned} P(\text{mammogram}^+\text{}) &= P(\text{mammogram}^+\text{ and no BC}) + P(\text{mammogram}^+\text{ and has BC}) \end{aligned} In the example, each of the probabilities on the right side was broken down into a product of a conditional probability and marginal probability using the tree diagram. P(mammogram+)=P(mammogram+ and no BC)+P(mammogram+ and has BC)=P(mammogram+ ∣ no BC)P(no BC)+P(mammogram+ ∣ has BC)P(has BC)\begin{aligned} P(\text{mammogram}^+\text{}) &= P(\text{mammogram}^+\text{ and no BC}) + P(\text{mammogram}^+\text{ and has BC}) \\ &= P(\text{mammogram}^+\text{ } | \text{ no BC})P(\text{no BC}) \\ &\qquad\qquad + P(\text{mammogram}^+\text{ } | \text{ has BC})P(\text{has BC}) \end{aligned} We can see an application of Bayes’ Theorem by substituting the resulting probability expressions into the numerator and denominator of the original conditional probability. P(has BC ∣ mammogram+)=P(mammogram+ ∣ has BC)P(has BC)P(mammogram+ ∣ no BC)P(no BC)+P(mammogram+ ∣ has BC)P(has BC)\begin{aligned} & P(\text{has BC } | \text{ mammogram}^+\text{}) \\ & \qquad= \frac{P(\text{mammogram}^+\text{ } | \text{ has BC})P(\text{has BC})} {P(\text{mammogram}^+\text{ } | \text{ no BC})P(\text{no BC}) + P(\text{mammogram}^+\text{ } | \text{ has BC})P(\text{has BC})} \end{aligned}

Bayes’ Theorem: inverting probabilities

Consider the following conditional probability for variable 1 and variable 2: P(outcome A1 of variable 1 ∣ outcome B of variable 2)\begin{aligned} P(\text{outcome }A_1\text{ of variable 1 } | \text{ outcome }B\text{ of variable 2}) \end{aligned} Bayes’ Theorem states that this conditional probability can be identified as the following fraction: P(B∣A1)P(A1)P(B∣A1)P(A1)+P(B∣A2)P(A2)+⋯+P(B∣Ak)P(Ak)\begin{aligned} \frac{P(B | A_1) P(A_1)} {P(B | A_1) P(A_1) + P(B | A_2) P(A_2) + \cdots + P(B | A_k) P(A_k)} \end{aligned} where A2A_2, A3A_3, ..., and AkA_k represent all other possible outcomes of the first variable.

Bayes’ Theorem is a generalization of what we have done using tree diagrams. The numerator identifies the probability of getting both A1A_1 and BB. The denominator is the marginal probability of getting BB. This bottom component of the fraction appears long and complicated since we have to add up probabilities from all of the different ways to get BB. We always completed this step when using tree diagrams. However, we usually did it in a separate step so it didn’t seem as complex.

apply Bayes’ Theorem correctly, there are two preparatory steps:

  1. First identify the marginal probabilities of each possible outcome of the first variable: P(A1)P(A_1), P(A2)P(A_2), ..., P(Ak)P(A_k).

  2. Then identify the probability of the outcome BB, conditioned on each possible scenario for the first variable: P(B∣A1)P(B | A_1), P(B∣A2)P(B | A_2), ..., P(B∣Ak)P(B | A_k).

Once each of these probabilities are identified, they can be applied directly within the formula. Bayes’ Theorem tends to be a good option when there are so many scenarios that drawing a tree diagram would be complex.

Guided Practice 3.43

Jose visits campus every Thursday evening. However, some days the parking garage is full, often due to college events. There are academic events on 35% of evenings, sporting events on 20% of evenings, and no events on 45% of evenings. When there is an academic event, the garage fills up about 25% of the time, and it fills up 70% of evenings with sporting events. On evenings when there are no events, it only fills up about 5% of the time. If Jose comes to campus and finds the garage full, what is the probability that there is a sporting event? Use a tree diagram to solve this problem.13

Example 3.44

Here we solve the same problem presented in Guided Practice 3.43, except this time we use Bayes’ Theorem.


The outcome of interest is whether there is a sporting event (call this A1A_1), and the condition is that the lot is full (BB). Let A2A_2 represent an academic event and A3A_3 represent there being no event on campus. Then the given probabilities can be written as P(A1)=0.2P(A2)=0.35P(A3)=0.45P(B∣A1)=0.7P(B∣A2)=0.25P(B∣A3)=0.05\begin{aligned} &P(A_1) = 0.2 &&P(A_2) = 0.35 &&P(A_3) = 0.45 \\ &P(B | A_1) = 0.7 &&P(B | A_2) = 0.25 &&P(B | A_3) = 0.05 \end{aligned} Bayes’ Theorem can be used to compute the probability of a sporting event (A1A_1) under the condition that the parking lot is full (BB): P(A1∣B)=P(B∣A1)P(A1)P(B∣A1)P(A1)+P(B∣A2)P(A2)+P(B∣A3)P(A3)=(0.7)(0.2)(0.7)(0.2)+(0.25)(0.35)+(0.05)(0.45)=0.56\begin{aligned} P(A_1 | B) &= \frac{P(B | A_1) P(A_1)}{P(B | A_1) P(A_1) + P(B | A_2) P(A_2) + P(B | A_3) P(A_3)} \\ &= \frac{(0.7)(0.2)}{(0.7)(0.2) + (0.25)(0.35) + (0.05)(0.45)} \\ &= 0.56 \end{aligned} Based on the information that the garage is full, there is a 56% probability that a sporting event is being held on campus that evening.

Guided Practice 3.45

Use the information in the previous exercise and example to verify the probability that there is an academic event conditioned on the parking lot being full is 0.35.14

Guided Practice 3.46

In Guided Practice 3.43 and 3.45, you found that if the parking lot is full, the probability there is a sporting event is 0.56 and the probability there is an academic event is 0.35. Using this information, compute P(P(no event ∣| the lot is full)).15

The last several exercises offered a way to update our belief about whether there is a sporting event, academic event, or no event going on at the school based on the information that the parking lot was full. This strategy of updating beliefs using Bayes’ Theorem is actually the foundation of an entire section of statistics called Bayesian statistics. While Bayesian statistics is very important and useful, we will not have time to cover much more of it in this book.

Exercises

Exercise 3.13

Joint and conditional probabilities. P(A) = 0.3, P(B) = 0.7

  1. Can you compute P(A and B) if you only know P(A) and P(B)?

  2. Assuming that events A and B arise from independent random processes,

    1. what is P(A and B)?

    2. what is P(A or B)?

    3. what is P(A∣|B)?

  3. If we are given that P(A and B) = 0.1, are the random variables giving rise to events A and B independent?

  4. If we are given that P(A and B) = 0.1, what is P(A∣|B)?

Exercise 3.14

PB & J. Suppose 80% of people like peanut butter, 89% like jelly, and 78% like both. Given that a randomly sampled person likes peanut butter, what’s the probability that he also likes jelly?

Exercise 3.15

Global warming. A Pew Research poll asked 1,306 Americans “From what you’ve read and heard, is there solid evidence that the average temperature on earth has been getting warmer over the past few decades, or not?". The table below shows the distribution of responses by party and ideology, where the counts have been replaced with relative frequencies. 16

Response
Earth is Not Don’t Know
warming warming Refuse Total
Conservative Republican 0.11 0.20 0.02 0.33
Party and Mod/Lib Republican 0.06 0.06 0.01 0.13
Ideology Mod/Cons Democrat 0.25 0.07 0.02 0.34
Liberal Democrat 0.18 0.01 0.01 0.20
Total 0.60 0.34 0.06 1.00
  1. Are believing that the earth is warming and being a liberal Democrat mutually exclusive?

  2. What is the probability that a randomly chosen respondent believes the earth is warming or is a liberal Democrat?

  3. What is the probability that a randomly chosen respondent believes the earth is warming given that he is a liberal Democrat?

  4. What is the probability that a randomly chosen respondent believes the earth is warming given that he is a conservative Republican?

  5. Does it appear that whether or not a respondent believes the earth is warming is independent of their party and ideology? Explain your reasoning.

  6. What is the probability that a randomly chosen respondent is a moderate/liberal Republican given that he does not believe that the earth is warming?

Exercise 3.16

Health coverage, relative frequencies. The Behavioral Risk Factor Surveillance System (BRFSS) is an annual telephone survey designed to identify risk factors in the adult population and report emerging health trends. The following table displays the distribution of health status of respondents to this survey (excellent, very good, good, fair, poor) and whether or not they have health insurance.

Health Status
Excellent Very good Good Fair Poor Total
Health No 0.0230 0.0364 0.0427 0.0192 0.0050 0.1262
Coverage Yes 0.2099 0.3123 0.2410 0.0817 0.0289 0.8738
Total 0.2329 0.3486 0.2838 0.1009 0.0338 1.0000
  1. Are being in excellent health and having health coverage mutually exclusive?

  2. What is the probability that a randomly chosen individual has excellent health?

  3. What is the probability that a randomly chosen individual has excellent health given that he has health coverage?

  4. What is the probability that a randomly chosen individual has excellent health given that he doesn’t have health coverage?

  5. Do having excellent health and having health coverage appear to be independent?

Exercise 3.17

Burger preferences. A 2010 SurveyUSA poll asked 500 Los Angeles residents, “What is the best hamburger place in Southern California? Five Guys Burgers? In-N-Out Burger? Fat Burger? Tommy’s Hamburgers? Umami Burger? Or somewhere else?” The distribution of responses by gender is shown below. 17

Gender
Male Female Total
Five Guys Burgers 5 6 11
In-N-Out Burger 162 181 343
Best Fat Burger 10 12 22
hamburger Tommy’s Hamburgers 27 27 54
place Umami Burger 5 1 6
Other 26 20 46
Not Sure 13 5 18
Total 248 252 500
  1. Are being female and liking Five Guys Burgers mutually exclusive?

  2. What is the probability that a randomly chosen male likes In-N-Out the best?

  3. What is the probability that a randomly chosen female likes In-N-Out the best?

  4. What is the probability that a man and a woman who are dating both like In-N-Out the best? Note any assumption you make and evaluate whether you think that assumption is reasonable.

  5. What is the probability that a randomly chosen person likes Umami best or that person is female?

Exercise 3.18

Assortative mating. Assortative mating is a nonrandom mating pattern where individuals with similar genotypes and/or phenotypes mate with one another more frequently than what would be expected under a random mating pattern. Researchers studying this topic collected data on eye colors of 204 Scandinavian men and their female partners. The table below summarizes the results.18

Partner (female)
Blue Brown Green Total
Blue 78 23 13 114
Self (male) Brown 19 23 12 54
Green 11 9 16 36
Total 108 55 41 204
  1. What is the probability that a randomly chosen male respondent or his partner has blue eyes?

  2. What is the probability that a randomly chosen male respondent with blue eyes has a partner with blue eyes?

  3. What is the probability that a randomly chosen male respondent with brown eyes has a partner with blue eyes? What about the probability of a randomly chosen male respondent with green eyes having a partner with blue eyes?

  4. Does it appear that the eye colors of male respondents and their partners are independent? Explain your reasoning.

Exercise 3.19

Drawing box plots. After an introductory statistics course, 80% of students can successfully construct box plots. Of those who can construct box plots, 86% passed, while only 65% of those students who could not construct box plots passed.

  1. Construct a tree diagram of this scenario.

  2. Calculate the probability that a student is able to construct a box plot if it is known that he passed.

Exercise 3.20

Predisposition for thrombosis. A genetic test is used to determine if people have a predisposition for thrombosis, which is the formation of a blood clot inside a blood vessel that obstructs the flow of blood through the circulatory system. It is believed that 3% of people actually have this predisposition. The genetic test is 99% accurate if a person actually has the predisposition, meaning that the probability of a positive test result when a person actually has the predisposition is 0.99. The test is 98% accurate if a person does not have the predisposition. What is the probability that a randomly selected person who tests positive for the predisposition by the test actually has the predisposition?

Exercise 3.21

It’s never lupus. Lupus is a medical phenomenon where antibodies that are supposed to attack foreign cells to prevent infections instead see plasma proteins as foreign bodies, leading to a high risk of blood clotting. It is believed that 2% of the population suffer from this disease. The test is 98% accurate if a person actually has the disease. The test is 74% accurate if a person does not have the disease. There is a line from the Fox television show House that is often used after a patient tests positive for lupus: “It’s never lupus." Do you think there is truth to this statement? Use appropriate probabilities to support your answer.

Exercise 3.22

Exit poll. Edison Research gathered exit poll results from several sources for the Wisconsin recall election of Scott Walker. They found that 53% of the respondents voted in favor of Scott Walker. Additionally, they estimated that of those who did vote in favor for Scott Walker, 37% had a college degree, while 44% of those who voted against Scott Walker had a college degree. Suppose we randomly sampled a person who participated in the exit poll and found that he had a college degree. What is the probability that he voted in favor of Scott Walker? 19

Notes

  1. Each of the four outcome combination are disjoint, all probabilities are indeed non-negative, and the sum of the probabilities is 0.1081+0.0121+0.0615+0.8183=1.000.1081 + 0.0121 + 0.0615 + 0.8183 = 1.00. ↩

  2. (a) If the photo is about fashion and the ML algorithm prediction was correct, then the ML algorithm my have a value of pred_fashion: P(mach_learn is pred_fashion ∣ truth is fashion)\begin{aligned} P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion}}\ | \ \text{\texttt{truth} is \texttt{fashion}}) \end{aligned} (b) The equation for conditional probability indicates we should first find
    P(mach_learn is pred_fashion and truth is fashion)=0.1081P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}fashion} and \texttt{truth} is \texttt{fashion}}) = 0.1081 and P(truth is fashion)=0.1696P(\text{\texttt{truth} is \texttt{fashion}}) = 0.1696.
    Then the ratio represents the conditional probability: 0.1081/0.1696=0.63740.1081 / 0.1696 = 0.6374. ↩

  3. (a) This probability is P(mach_learn is pred_not, truth is fashion)P(truth is fashion)=0.06150.1696=0.3626\frac{P(\text{\texttt{mach\_{}learn} is \texttt{pred\_{}not}, \texttt{truth} is \texttt{fashion}})} {P(\text{\texttt{truth} is \texttt{fashion}})} = \frac{0.0615}{0.1696} = 0.3626. (b) The total equals 1. (c) Under the condition the photo is about fashion, the ML algorithm must have either predicted it was about fashion or predicted it was not about fashion. The complement still works for conditional probabilities, provided the probabilities are conditioned on the same information. ↩

  4. P(P(result = died ∣| inoculated = no)=P(result = died and inoculated = no)P(inoculated = no)=0.13560.9608=0.1411) = \frac{P(\text{\texttt{result} = \texttt{died} and \texttt{inoculated} = \texttt{no}})}{P(\text{\texttt{inoculated} = \texttt{no}})} = \frac{0.1356}{0.9608} = 0.1411. ↩

  5. P(P(result = died ∣| inoculated = yes)=P(result = died and inoculated = yes)P(inoculated = yes)=0.00100.0392=0.0255) = \frac{P(\text{\texttt{result} = \texttt{died} and \texttt{inoculated} = \texttt{yes}})}{P(\text{\texttt{inoculated} = \texttt{yes}})} = \frac{0.0010}{0.0392} = 0.0255 (if we avoided rounding errors, we’d get 6/244=0.02466 / 244 = 0.0246). The death rate for individuals who were inoculated is only about 1 in 40 while the death rate is about 1 in 7 for those who were not inoculated. ↩

  6. Brief answers: (a) Observational. (b) No, we cannot infer causation from this observational study. (c) Accessibility to the latest and best medical care. There are other valid answers for part (c). ↩

  7. The answer is 0.0382, which can be verified using Figure 3.16. ↩

  8. There were only two possible outcomes: lived or died. This means that 100% - 97.54% = 2.46% of the people who were inoculated died. ↩

  9. The samples are large relative to the difference in death rates for the “inoculated” and “not inoculated” groups, so it seems there is an association between inoculated and outcome. However, as noted in the solution to Guided Practice 3.33, this is an observational study and we cannot be sure if there is a causal connection. (Further research has shown that inoculation is effective at reducing death rates.) ↩

  10. Brief solutions: (a) 1/61/6. (b) 1/361/36. (c) P(Y= 1 and X= 1)P(X= 1)=1/361/6=1/6\frac{P(Y = \text{ \texttt{1} and }X=\text{ \texttt{1}})}{P(X=\text{ \texttt{1}})} = \frac{1/36}{1/6} = 1/6. (d) The probability is the same as in part (c): P(Y=1)=1/6P(Y=1)=1/6. The probability that Y=1Y=1 was unchanged by knowledge about XX, which makes sense as XX and YY are independent. ↩

  11. He has forgotten that the next roulette spin is independent of the previous spins. Casinos do employ this practice, posting the last several outcomes of many betting games to trick unsuspecting gamblers into believing the odds are in their favor. This is called the gambler’s fallacy. ↩

  12. (a) The tree diagram is shown to the right.
    (b) Identify which two joint probabilities represent students who passed, and add them: P(P(passed)=0.7566+0.1254=0.8820) = 0.7566+0.1254= 0.8820.
    (c) P(P(construct tree diagram ∣| passed)=0.75660.8820=0.8578) = \frac{0.7566}{0.8820} = 0.8578.
    ↩

  13. The tree diagram, with three primary branches, is shown to the right. Next, we identify two probabilities from the tree diagram. (1) The probability that there is a sporting event and the garage is full: 0.14. (2) The probability the garage is full: 0.0875+0.14+0.0225=0.250.0875 + 0.14 + 0.0225 = 0.25. Then the solution is the ratio of these probabilities: 0.140.25=0.56\frac{0.14}{0.25} = 0.56. If the garage is full, there is a 56% probability that there is a sporting event.
     

    ↩

  14. Short answer: P(A2∣B)=P(B∣A2)P(A2)P(B∣A1)P(A1)+P(B∣A2)P(A2)+P(B∣A3)P(A3)=(0.25)(0.35)(0.7)(0.2)+(0.25)(0.35)+(0.05)(0.45)=0.35\begin{aligned} P(A_2 | B) &= \frac{P(B | A_2) P(A_2)}{P(B | A_1) P(A_1) + P(B | A_2) P(A_2) + P(B | A_3) P(A_3)} \\ &= \frac{(0.25)(0.35)}{(0.7)(0.2) + (0.25)(0.35) + (0.05)(0.45)} \\ &= 0.35 \end{aligned} ↩

  15. Each probability is conditioned on the same information that the garage is full, so the complement may be used: 1.00−0.56−0.35=0.091.00 - 0.56 - 0.35 = 0.09. ↩

  16. Pew Research Center, Majority of Republicans No Longer See Evidence of Global Warming, data collected on October 27, 2010. ↩

  17. SurveyUSA, Results of SurveyUSA News Poll #17718, data collected on December 2, 2010. ↩

  18. Laeng, B. et al. Why do blue-eyed men prefer women with the same eye color?. Behavioral Ecology and Sociobiology. 2007. ↩

  19. New York Times, Wisconsin recall exit polls. ↩

Credit and licence

“3.2 Conditional probability” is from OpenIntro Statistics, Fourth Edition, by David M Diez, Mine Çetinkaya-Rundel and Christopher D Barr, shared under a CC BY-SA 3.0 license. WorldClass Statistics is a derivative of OpenIntro Statistics, shared under the same license; the original book may be found at openintro.org/book/os.

Source: https://www.openintro.org/book/os/

Licence: CC BY-SA 3.0 (creativecommons.org/licenses/by-sa/3.0/). You may share and adapt it under the same licence, with this credit. WorldClass adapted the formatting only: the text is the authors', with interactive parts and links to other sites left out.

Build status · Flash Infinity AI™ is a trademark of AI-Flash Inc.. WorldClass is not affiliated with, approved or accredited by any exam board, curriculum provider or university unless a page says so.