Probability#
Download#
Outline#
Frequency as probability
Rules of probability
Opposite rule: complements
Multiplication rule & conditional probability
Rule of total mass
Addition rule
Reading: Chapters 13 & 14 of Freedman, Pisani and Purves
Probability#
Frequency definition of chances#
If you flip a fair coin many times, the long-run proportion of heads will be 50%.
Rolling a fair 6-sided die, will result in a long-run proportion of 1’s of
coin_tosses = sample(c('H', 'T'), 10000, replace=TRUE)
mean(coin_tosses == 'H')
die_rolls = sample(1:6, 10000, replace=TRUE)
mean(die_rolls == 1)
Some rules of probability#
Range of values: Chances are between 0 % and 100 % (i.e. between 0 and 1).
Opposites: The chance of something equals 100 % minus the chance of the opposite thing.
Example#
The chance of not getting a 1 when rolling a die is
Drawing marbles from a box#
Box #1 (
large) :30 blue, 20 redBox #2 (
small): 3 blue, 2 redIf you have to draw a blue marble to win, which box would you choose?
large = c(rep('B', 30), rep('R', 20))
small = c(rep('B', 3), rep('R', 2))
They both have the same chance of winning when drawing 1 marble: 0.6
With or without replacement?#
When drawing one marble, the important number was
What if you draw 5 marbles with replacement?
Without replacement?
Chances of winning with replacement#
We will see that the chances of winning are
The fraction \((2/5)^5\) is the chance that we pick 5 red marbles in a row.
Sampling without replacement#
If drawing without replacement,
smallwill be easier to win.We’re even guaranteed to win with
small. Why?
Example#
Suppose our experiment consists of drawing a ticket out of a hat with 20 tickets numbered 1 to 20 in it. We are going to draw 3 tickets.
Describe the hat after each draw if we draw with replacement. What are the possible outcomes of the experiment?
Describe the hat after each draw if we draw without replacement. What are possible outcomes of the experiment?
Conditional probability#
Observing some information can change the chances of something.
We already saw this in the marble example. If drawing without replacement, suppose the first draw was red. What are the chances a blue marble is drawn on the second draw?
What if we draw with replacement?
In this examples, we are given that the first draw was red. These chances are conditioned on knowing the first draw was red.
Multiplication rule#
The chance that two things will both happen equals the chance that the first will happen, multiplied by the chance that the second will happen given the first has happened.
Chance of winning with when drawing twice#
Winning is the opposite of losing, so let’s compute the chance of losing when drawing twice, starting with
small.The chances of losing when drawing twice with
smallare
The chances of losing when drawing twice with
largeare
Mathematical notation#
“winning when drawing twice from
small” is called an event ;“first draw from
smallis red” and “second draw with replacement fromsmallis blue” are also events;We usually write \(P\) for “chances”. For an event \(E\)
Conditional probability of an event \(A\) given \(B\), i.e.
the chances \(A\) occurs given \(B\) occurs, is written as
Multiplication rule can be written as
Rule of total mass#
The chances of something occuring are 100%.
Example: when we drew marbles, the chances we draw a marble whose color is blue or red is 100 %.
In mathematical notation, we often use \(S\) for “something” or the sample space
What is the sample space in our marbles example for any particular draw?
Examples: sample space#
What is the sample space if the experiment is to draw 3 balls without replacement from the small box?
What if we draw them with replacement?
Example for the rule of total mass#
When drawing from
smallwithout replacement, we will draw a blue ball within the first three draws.
Let’s verify the rule of total mass
Summing the probablities $\(\frac{3}{5} + \frac{3}{10} + \frac{1}{10} = 1.\)$
Addition rule#
When can we add probabilities of different events?
We can add probabilities of events when the events are disjoint or mutually exclusive
Example#
When rolling a die, the events \(E_1= \text{roll is 4}\) , \(E_2=\text{roll is 3}\) are mutually exclusive because the result of the roll cannot be 4 and 3 simultaneously.
Therefore
Mutually exclusive events#
Non-mutually exclusive events#
Addition rule#
If the events \(E_1, E_2\) are mutually exclusive, then
This rule works for more than two: if \([E_1, \dots, E_n]\) are mutually exclusive, then
We often write “\(E_1\) or \(E_2\)” as \(E_1 \cup E_2\) and “\(E_1\) and \(E_2\)” as \(E_1 \cap E_2\).
The events \(E_1, E_2\) are mutually exclusive if \(E_1 \cap E_2\) is empty.
From a Venn diagram, we can deduce the general form of the addition rule
There are also rules that involve more than 2 events.
Three events#
A more complicated Venn diagram: four events#
A simple bound on probabilities#
Because chances (or probabilities) are non-negative we can see that
Works for many events as well:
Example#
Google says there is a 40% chance of rain on Friday, a 10% chance of rain on Saturday and a 0% chance of rain on Sunday.
Google may be wrong about these chances! BUT, if Google’s weather predictions follows the rules of probability we should expect it to say
Bound not always useful#
Google predicts 100% chance of precipitation on Tuesday, 10% on Wednesday and 80% on Thursday.
There is at most 190% chance of rain on one of Tuesday, Wednesday or Thursday.
BUT, we know there is at most a 100% chance of rain on one of Tuesday, Wednesday or Thursday.
Do probabilities have to be real?#
Our previous example used Google’s estimate of rain.
Their forecast team may or may not be good. They are likely somewhat incorrect.
BUT, their team probably has its own way it computes probabilities.
We used the rules of probability to say something about chances of rain on the weekend.
Moral: the rules of probability are math: they describe a (consistent) way of assigning “chances” to events.#
Different probabilities, same sample space#
In tossing a coin once, the sample space is \(\{\text{head, tail}\}\).
We will typically assume \(P(\text{head})=P(\text{tail})=50%\).
There are weighted coins out there, for which \(Q(\text{head})\) might be 55% (so \(Q(\text{tail})\) is 45%). We use the letter \(Q\) because it is a different way of computing chances than \(P\).
What if we didn’t know whether a coin is fair or weighted? How might we decide?
Multiplication rule & independence#
Intuitively, an event \(A\) is independent of \(B\) if given \(B\), the odds of \(A\) are unaffected.
In mathematical notation, this would be
If this is true, we say \(A\) and \(B\) are independent.
Otherwise, \(A\) and \(B\) are dependent.
The multiplication rule, combined with independence tells us
Example for independence#
Let’s go back to drawing marbles from a box.
When drawing marbles with replacement the events
are independent
We can even conclude that the draws are independent in this case.
When drawing without replacement the events \(A\) and \(B\) are dependent. Show this.
We know know that when drawing with replacement the probability of drawing 5 red balls in a row is
Counting and probability#
When performing an experiment (drawing a sample) where each outcome is equally likely, we can compute probabilities by counting.
Example: when rolling two dice, what is the probability of obtaining a sum of 9?
For such experiments $\(P(E) = \frac{\# E}{\# S}\)\( where \)S$ is the set of all possible outcomes (our sample space).
Counting example: rolling a pair of dice#
** What is the sample space?**
Die 1 \ Die 2 |
1 |
2 |
3 |
4 |
5 |
6 |
|---|---|---|---|---|---|---|
1 |
(1,1) |
(1,2) |
(1,3) |
(1,4) |
(1,5) |
(1,6) |
2 |
(2,1) |
(2,2) |
(2,3) |
(2,4) |
(2,5) |
(2,6) |
3 |
(3,1) |
(3,2) |
(3,3) |
(3,4) |
(3,5) |
(3,6) |
4 |
(4,1) |
(4,2) |
(4,3) |
(4,4) |
(4,5) |
(4,6) |
5 |
(5,1) |
(5,2) |
(5,3) |
(5,4) |
(5,5) |
(5,6) |
6 |
(6,1) |
(6,2) |
(6,3) |
(6,4) |
(6,5) |
(6,6) |
What are the chances the sum will be equal to 9?#
Die 1 \ Die 2 |
1 |
2 |
3 |
4 |
5 |
6 |
|---|---|---|---|---|---|---|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
There are 4 outcomes whose sum is 9. Therefore, the chances are \(\frac{4}{36}=\frac{1}{9}\).
What are the chances the sum will be greater than or equal to 7?#
Die 1 \ Die 2 |
1 |
2 |
3 |
4 |
5 |
6 |
|---|---|---|---|---|---|---|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
There are 21 outcomes whose sum is greater than or equal to 7. Therefore, the chances are \(\frac{21}{36}=\frac{7}{12}\).
What are the chances the sum will be less than 7?#
The chances that the sum is greater than or equal to 7 are \(\frac{7}{12}\). Therefore, by the “opposite” rule, the chances are chances are
Complement of an event#
Formally, the “opposite” rule is the rule of complements.
We write the complement of an event \(E\) as \(E^c\)
The rule of complements says
An event \(E\) and its complement \(E^c\)#
Properties of complements#
For any event \(E\), \(E\) and \(E^c\) are mutually exclusive.
For any event \(E\), \(S = E \cup E^c\).
For any two events \(A, B\)
where \(B \cap A\) and \(B \cap A^c\) are mutually exclusive (i.e. disjoint).
Therefore,
Using complements to decompose#
For the
smallbox, if we draw with replacement, what are the chances it will take less than 6 draws to draw 1st blue marble?If \(E\)={takes less than 6 draws to draw 1st blue marble}, then
By independence,
Therefore,
Using complements 2nd example#
For the
small boxsuppose we draw without replacement and want to compute
We know
Therefore
Bayes’ rule#
Credited to Reverend Thomas Bayes
Given two events \(A\) and \(B\)
The formula is a direct consequence of the multiplication rule.
Alternate version of Bayes’ rule#
By the properties of complements
Other versions of Bayes’ rule
Drawing marbles without replacement from small box using Bayes’ rule#
Let
Compute \(P(A \vert B)\).
What do we know?
We need $\(P(B) = P(B \vert A) \times P(A) + P(B \vert A^c) \times P(A^c).\)$
Note that \(A^c=\{\text{draw a blue marble on first draw}\}\).
We know
Therefore,
Using alternate form#
Earlier, we computed \(P(\text{2nd marble is blue}) = P(B)\) as
So,
Diagnostic testing#
Suppose a patient from some population is tested for a disease based on some diagnostic test.
The prevalence of the disease is 0.1% in the population.
If a patient has the disease, the test result is positive with probability 95 %. (True positive )
If a patient does not have the disease, the test result is positive with probability 1 %. (False positive ).
What is the probability a patient has the disease given a positive test result? What if the false positive rate were 0.1%?
Let
We are given
We want to compute \(P(D \vert T^+)\).
By Bayes’ theorem
Changing the false positive rate#
If the test makers improve their false positive rate to 0.001 then