Define independence of 2-3 events and decide whether two or more events are independent
Define key facts for conditional probabilities and calculate conditional probabilities.
Calculate the probability of an event using Bayes’ Theorem, Higher Order Multiplication Rule, and the Law of Total Probabilities
Where are we?
General Process for Probability Word Problems
Clearly define your events of interest and mathematically define the goal probability
Translate question to probability using defined events OR Venn Diagram
Ask yourself:
Are we sampling with or without replacement?
Does order matter? (Are the objects distinguishable?)
Use axioms, properties, partitions, facts, etc. to define the end probability calculation into smaller parts
If probabilities are given to you, Venn Diagrams may help you parse out the events and probability calculations
If you need to find probabilities with counting, pictures or diagrams might help here
Write out a concluding statement that gives the probability context
(For own check) Make sure the calculated probability follows the axioms. Is it between 0 and 1?
Learning objectives
Define independence of 2-3 events and decide whether two or more events are independent
Define key facts for conditional probabilities and calculate conditional probabilities.
Calculate the probability of an event using Bayes’ Theorem, Higher Order Multiplication Rule, and the Law of Total Probabilities
Independent Events
Definition: Independence
Events \(A\) and \(B\) are independent if \[\mathbb{P}(A \cap B) = \mathbb{P}(A) \cdot \mathbb{P}(B).\]
Notation: For shorthand, we sometimes write \(A \mathrel{\unicode{x2AEB}} B,\) to denote that \(A\) and \(B\) are independent events.
Also note: \[\begin{aligned} \mathbb{P}(A \cap B) = \mathbb{P}(A) \cdot \mathbb{P}(B) & \implies A \mathrel{\unicode{x2AEB}} B \\
A \mathrel{\unicode{x2AEB}} B & \implies \mathbb{P}(A \cap B) = \mathbb{P}(A) \cdot \mathbb{P}(B) \end{aligned}\]
Example of two dice
Example 1
Two dice (green and blue) are rolled. Let \(A =\) event a total of 7 appears, and \(B =\) event green die is a six. Are events \(A\) and \(B\) independent?
Example of two dice: simulating in R (1/2)
Example 1
Two dice (green and blue) are rolled. Let \(A =\) event a total of 7 appears, and \(B =\) event green die is a six. Are events \(A\) and \(B\) independent?
First, a small simulation with 10 rolls of the two dice
set.seed(1002)reps <-10dice <-expand_grid(sim =1:reps) |>mutate(green =sample(1:6, n(), replace =TRUE),blue =sample(1:6, n(), replace =TRUE))dice_events <- dice |>mutate(A = green + blue ==7,B = green ==6)
1
Set the seed once, so we get the same “random” rolls every time the slides are made.
2
Save the number of simulations as reps, so it is easy to change later.
3
One row for every simulation. Each simulation is one roll of the pair of dice.
4
Each die is a box with tickets 1 to 6. sample() draws one ticket for every row (n() is the number of rows). replace = TRUE means any number can show up on both dice.
5
Start with the table of dice and save the result as dice_events.
6
A is TRUE when the total of the two dice is 7. The == asks “is it equal to?”
7
B is TRUE when the green die is a six.
dice_events
1
Typing a name prints the table. Each row is one simulation.
Two dice (green and blue) are rolled. Let \(A =\) event a total of 7 appears, and \(B =\) event green die is a six. Are events \(A\) and \(B\) independent?
Same code, now with 10,000 simulations
reps <-10000dice <-expand_grid(sim =1:reps) |>mutate(green =sample(1:6, n(), replace =TRUE),blue =sample(1:6, n(), replace =TRUE))dice_events <- dice |>mutate(A = green + blue ==7,B = green ==6)
1
The only change: 10,000 simulations instead of 10.
2
Same as before: roll the two dice and check events A and B in each simulation.
Then we compare \(\mathbb{P}(A) \cdot \mathbb{P}(B)\) with \(\mathbb{P}(A \cap B)\)
If everyone has the same chance \(p\) of smoking, this is \(1 - (1 - p)^n\)
Probability at least one smoker: simulating in R (extra reference on own)
Suppose every person has the same chance of smoking, \(p = 0.2\), and we sample \(n = 5\) people. The formula gives \(1 - (1 - 0.2)^5 = 0.672\). Does the simulation agree?
Save the number of simulations, the number of people, and the chance of smoking as named values, so they are easy to change.
3
One row for every combination of simulation (a sample of 5 people) and person.
4
Like the unfair coin in Lesson 1: prob gives each outcome its own chance, here 20% smoker and 80% non-smoker. Each person is drawn separately, which is what makes them independent.
5
Handle each simulation (each sample of people) separately.
6
any() is TRUE if at least one person in the sample is a smoker.
7
The proportion of samples with at least one smoker.
# A tibble: 1 × 1
prob_at_least_one
<dbl>
1 0.682
Learning objectives
Define independence of 2-3 events and decide whether two or more events are independent
Define key facts for conditional probabilities and calculate conditional probabilities.
Calculate the probability of an event using Bayes’ Theorem, Higher Order Multiplication Rule, and the Law of Total Probabilities
Conditional Probability facts (1/2)
Fact 1: General Multiplication Rule
\[\mathbb{P}(A\cap B)=\mathbb{P}(A)\cdot\mathbb{P}(B|A) \\ \text{ and } \\ \mathbb{P}(A\cap B)=\mathbb{P}(B)\cdot\mathbb{P}(A|B)\]
Fact 1 in words: the probability that \(A\)and\(B\) both happen is the probability that \(A\) happens times the probability that \(B\) happens given\(A\) happened (or the same with \(A\) and \(B\) switched)
Fact 2: Conditional Probability Definition
\[\mathbb{P}(A|B)=\frac{\mathbb{P}(A\cap B)}{\mathbb{P}(B)} \text{ and } \mathbb{P}(B|A)=\frac{\mathbb{P}(A\cap B)}{\mathbb{P}(A)}\]
Fact 2 in words: the conditional probability of \(A\)given\(B\) is the probability that \(A\) happens when we already know \(B\) happened
Conditional Probability facts (2/2)
Fact 3
If \(A\) and \(B\) are independent events (\(A \unicode{x2AEB}B\)), then \[\mathbb{P}(A|B) = \mathbb{P}(A) \text{ and } \mathbb{P}(B|A) = \mathbb{P}(B)\]
Fact 3 in words: if \(A\) and \(B\) are independent, knowing that \(B\) happened does not change the probability that \(A\) happens
Fact 4
\(\mathbb{P}(A|B)\) is a probability, meaning that it satisfies the probability axioms. In particular, \[\mathbb{P}(A|B) + \mathbb{P}(A^C|B) = 1 \\ \text{ and } \\ \mathbb{P}(B|A) + \mathbb{P}(B^C|A) = 1\]
Fact 4 in words: given that \(B\) happened, the probability that \(A\) happens and the probability that \(A\) does not happen add up to 1
Conditional probability with two dice
Example 3
Two dice (green and blue) are rolled. If the dice do not show the same face, what is the probability that one of the dice is a 1?
Conditional probability with two dice: simulations (1/2)
Example 3
Two dice (green and blue) are rolled. If the dice do not show the same face, what is the probability that one of the dice is a 1?
Reuse the 10,000 rolls, but with new events: \(A\) = one die is a 1, and \(B\) = the dice do not match
cond_sims <- dice |>mutate(A = green ==1| blue ==1,B = green != blue)
1
Start with the same dice table from Example 1 and save the result as cond_sims.
2
| is “or”, so A is TRUE when the green die is a 1 or the blue die is a 1 (or both).
3
!= is “is not equal to”, so B is TRUE when the two dice show different numbers.
Three doors: a car is behind one, goats behind the other two. You pick a door, the host opens a different door with a goat, and you choose whether to stay or switch
Switching wins about \(\frac{2}{3}\) of the time. Why? Switching wins exactly when our first pick was wrong, and that has probability \(\frac{2}{3}\)
Learning objectives
Define independence of 2-3 events and decide whether two or more events are independent
Define key facts for conditional probabilities and calculate conditional probabilities.
Calculate the probability of an event using Bayes’ Theorem, Higher Order Multiplication Rule, and the Law of Total Probabilities
Bayes’ Rule for two events
We can use the conditional probability (\(\mathbb{P}(A|B)\)) to get information on the flipped conditional probability (\(\mathbb{P}(B|A)\))
Theorem: Bayes’ Rule (for two events)
For any two events \(A\) and \(B\) with nonzero probabilities,
\[\mathbb{P}(A| B) =
\frac{\mathbb{P}(A) \cdot \mathbb{P}(B|A)}
{\mathbb{P}(B)}\]
Calculating probability with Higher Order Multiplication Rule
Example 4
Suppose we draw 5 cards from a standard shuffled deck of 52 cards. What is the probability of a flush, that is all the cards are of the same suit (including straight flushes)?
Calculating probability with Law of Total Probability
Example 5
Suppose 1% of people assigned female at birth (AFAB) and 5% of people assigned male at birth (AMAB) are color-blind. Assume person born is equally likely AFAB or AMAB (not including intersex). What is the probability that a person chosen at random is color-blind?
Save the number of simulations as reps. We use 100,000 because breast cancer with a positive test is fairly rare.
3
Save the three probabilities from the problem as named values, so they are easy to change.
4
One row per simulated AFAB person aged 40-50 years.
5
Does this person have breast cancer? Like the unfair coin in Lesson 1, prob gives TRUE (cancer) a 1% chance and FALSE a 99% chance.
6
What the mammogram would show if this person has cancer: positive with probability 0.9.
7
What the mammogram would show if this person does not have cancer: a false positive with probability 0.1.
8
New function: if_else(condition, value_if_TRUE, value_if_FALSE) picks a value for each row. If the person has cancer, we keep pos_if_cancer. Otherwise we keep pos_if_no_cancer. This is how the test result depends on cancer status.
9
“Given a positive test” means we only keep the people with a positive test. filter(positive) keeps the rows where positive is TRUE.
10
Among the positive tests, the proportion that have cancer. This should be close to our answer of 0.0833.
# A tibble: 1 × 1
prob_cancer_given_pos
<dbl>
1 0.0879
Bayes’ Rule expanded to \(n\) partitions
Theorem: Bayes’ Rule
If \(\{A_i\}_{i=1}^{n}\) form a partition of the sample space \(S\), with \(\mathbb{P}(A_i)>0\) for \(i=1\ldots n\) and \(\mathbb{P}(B)>0\), then