---
title: "13 Conditional Probability and Independence"
author: "David Housman"
format: docx
editor: visual
fig-width: 6
fig-height: 4
---

```{r}
#| message: false
#| warning: false
#| echo: false
library(tidyverse)
```

## Conditional Probability

Suppose an experiment is run that has a sample space $S$ and associated events $A$ and $B$.

![](C13Venn.png)

The **probability** of event $A$ is

$$P(A) = \dfrac{\text{amount of stuff in }A}{\text{amount of stuff in }S}.$$

Suppose that it is known that event $B$ has occurred. The **conditional probability** of event $A$ given $B$ is

$$P(A|B) = \dfrac{\text{amount of stuff in }A\text{ that is also in }B}{\text{amount of stuff in }B} = \dfrac{P(A\cap B)}{P(B)}.$$

We can rewrite the above definition as

$$P(A \cap B) = P(B)P(A|B).$$

## Exercises

Trigger Warning: #4 refers to an actual case of suicide reported in the *New York Times*.

1.  One hundred students were asked their sex and hair color. The results are summarized in the table. Identify the population, sample, and variables. Suggest a statistic and a parameter.

|        | Blonde | Brown | Red |
|:------:|:------:|:-----:|:---:|
|  Male  |   27   |  32   |  1  |
| Female |   18   |  17   |  5  |

2.  Suppose a student is selected at random from the sample described in #1. Find the probabilities of the following events.

    a.  The student has red hair.

    b.  The student is male.

    c.  The student is male and has red hair.

    d.  The student is male or has red hair.

    e.  The student is male given that the students has red hair.

    f.  The student has red hair given that the student is male.

3.  Suppose two students are selected at random without replacement from the sample described in #1. Find the probabilities of the following events.

    a.  The first student has brown hair.

    b.  The second student has brown hair given that the first student had brown hair.

    c.  The second student has brown hair given that the first student did not have brown hair.

    d.  The secnd student has brown hair.

4.  At the time, the test for the AIDS virus was 96% accurate. Ten thousand people considered to be at risk were tested for the AIDS virus. John Jones (not his real name) tested positive and two hours later committed suicide. In his last note, he explained that he saw no sense in continuing to live since he had a 96% chance of having AIDS. Of course, the real reasons for suicide may not correspond to what is stated in a suicide note, but our question here is whether John Jones' reasoning in his suicide note was valid?

5.  What are the implications for random workplace drug testing, mammograms, and early pregnancy tests?

6.  Suppose from a standard deck of cards that you have been dealt 4H, 5S, 6D, 6H, 9H. Given only this information, calculate the following probabilities.

    a.  Obtain a heart flush by discarding 5S and 6D and drawing two new cards.

    b.  Obtain a straight by discarding 6H and 9H and drawing two new cards.

    c.  Obtain a three or four sixes by discarding 4H, 5S, and 9H and drawing three new cards.

    d.  Are calculations of the above sort sufficient to determine which cards to discard to obtain a better poker hand?

7.  From an standard deck of playing cards, cards are to be drawn successively at random and without replacement. Find the probability that the third spade appears on the sixth draw.

8.  A grade school boy has five blue and four white marbles in his left pocket and four blue and five white marbles in his right pocket. If he transfers one marble at random from his left to his right pocket, what is the probability of his then drawing a blue marble from his right pocket?

9.  A pair of four-sided dice are rolled repeatedly. Find the probability of rolling a sum of 3 before rolling a sum of 5.

## Event Independence

Event $A$ is said to be **independent** of event $B$ if $P(A | B) = P(A)$. Otherwise, $A$ is **dependent** on $B$.

## Exerises

1.  Roll a 4-sided die twice. Let $A$ be 2 appears on the first roll and $B$ be 4 appears on the second roll. Is $A$ independent of or dependent on $B$?

2.  Roll a 4-sided die twice. Let $A$ be 2 appears on the first roll and $B$ be the sum is 4. Is $A$ independent of or dependent on $B$?

3.  Roll a 4-sided die twice. Let $A$ be 2 appears on the first roll and $B$ be the sum is 5. Is $A$ independent of or dependent on $B$?

4.  Why can we say events $A$ and $B$ *are independent* rather than $A$ *is independent* of $B$?

5.  Show that if knowing that $B$ has occurred does not change the probability that $A$ occurs, then knowing that $B$ has not occurred does not change the probability that $A$ occurs.

6.  Suppose one student is selected at random from the sample described in the above table.

    a.  Are the events "has red hair" and "is male" independent?

    b.  Are the events "has blonde hair" and "female" independent?

## Random Variables and Independence

A **random variable** is a function from a sample space. Informally, a random variable is a question asked of the outcomes of a random experiment. The **probability distribution function (pdf)** for a random variable with only a finite number of possible values records the probability for each of the random variable's possible values. Two random variables $X$ and $Y$ on the same sample space are **independent** if the events $X = x$ and $Y = y$ are independent for all possible values $x$ and $y$.

## Exercises

1.  A four-sided die is rolled twice. Let $X$ be the number on the first roll and $Y$ be the number on the second roll.

    a.  What is $X$ formally?

    b.  What is the pdf of $X$?

    c.  Are $X$ and $Y$ independent?

2.  A four-sided die is rolled twice. Let $X$ be the number on the first roll and $Y$ be the sum of the two numbers.

    a.  What is the pdf of $Y$?

    b.  Are $X$ and $Y$ independent?

3.  Suppose one student is selected at random from the sample described in the above table.

    a.  What is the pdf of hair color?

    b.  Are gender and hair color independent?

    c.  Keepng the same numbers of males and females, Change the numbers in the above table so that the answer to the previous question changes.
