-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-measuring-uncertainty.qmd
141 lines (88 loc) · 5.74 KB
/
02-measuring-uncertainty.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Measuring Uncertainty
```{r}
```
## What is Probability?
Probability is a measurement of how strongly we believe things about the world. We can consider probability an extension of logic. Probability allows us to extend logic not only to work with absolute beliefs (true and false) but also to work with uncertain values (values between true and false).
An important part of logic is *negation.* When we say “not true” we mean false. Likewise, saying “not false” means true. We want probability to work the same way, so we make sure that the probability of X and the negation of the probability of X sum to 1 (in other words, values are either X, or not X).
$$P(X) + \neg{P(X)} = 1$$ {#eq-negation}
## Calculating Probabilities by Counting Outcomes of Events
The most common way to calculate probability is to count outcomes of events. We have two sets of outcomes that are important:
1. All possible outcomes of an event. For a coin toss, this would be “heads” or “tails.”
2. The count of the outcomes you’re interested in. If you’ve decided that heads means you win, the outcomes you care about are those involving heads.
In probability theory, we use $\Omega$ (the capital Greek letter omega) to indicate the set of all events:
$$\Omega = \{heads, tails\}$${#eq-omega}
::: {#exm-1head-2-coins}
What is the probability of getting at least one heads when we toss two coins?
1. Count the list of all possible events:
$$\Omega = \{(heads, heads), (heads, tails), (tails, heads), (tails, tails) \}$$ {#eq-possible-events}
2. How many events match our condition?
$$\{(heads, heads), (heads, tails), (tails, heads) \}$$ {#eq-matching-events}
3. Divide number of matches by number of all possible events:
$$\frac{3}{4}$$
Solving harder probability problems of this nature often involves a field of mathematics called `r glossary("combinatorics")`.
:::
## Calculating Probabilities as Ratios of Beliefs
Counting events is only useful for physical objects. How to reason about more abstract problems? -- Making bets is a practical way that we can express how strongly we hold our beliefs.
### Using Odds to Determine Probability
`r glossary("Odds")` are a common way to represent beliefs as a ratio of how much you would be willing to pay if you were wrong about the outcome of an event to how much you’d want to receive for being correct. For example, say the odds of a horse winning a race are 12 to 1.
Odds have a simple relation with `r glossary("probabilities")`: the odds of an outcome are the ratio of the probability that the outcome occurs to the probability that the outcome does not occur. In mathematical terms, where p is the probability of the outcome and 1- p is the probability that the outcome does not occur:
$$odds = \frac{p}{1-p}$$ {#eq-odds-p}
### Solving for the Probabilities
Using algebra we can convert @eq-odds-p to find the probability of a hypotheses:
$$p = \frac{odds}{1 + odds}$$ {#eq-p-odds}
### Measuring Beliefs in a Coin Toss
Rather than thinking about a coin toss as an event, we can rephrase the question as “How strongly do I believe the next coin toss will be heads?” Now we’re not talking about $P(heads)$ but rather a hypothesis or belief about the coin toss, $P(H_{heads})$. Just like before, we need an alternate hypothesis to compare our belief with.
## Wrapping Up
- We explored two different types of probabilities: those of events and those of beliefs.
- We defined probability as the ratio of the outcome(s) we care about to the number of all possible outcomes.
While this is the most common definition of probability, it is difficult to apply to beliefs because most practical, everyday probability problems do not have clear-cut outcomes and so aren’t intuitively assigned discrete numbers. To calculate the probability of beliefs, then, we need to establish *how many times more we believe in one hypothesis over another*. One good test of this is how much you would be willing to bet on your belief
## Exercises
Try answering the following questions to make sure you understand how we can assign real values between 0 and 1 to our beliefs.
::: {#exm-02-1}
What is the probability of rolling two six-sided dice and getting a value greater than 7?
Following @exm-1head-2-coins:
1. @eq-possible-events: $36$
$$
\begin{align*}
\Omega = \{(1,1), (1,2), (1,3), (1,4), (1,5), (1,6) \\
(2,1), (2,2), (2,3), (2,4), (2,5), (2,6) \\
(3,1), (3,2), (3,3), (3,4), (3,5), (3,6) \\
(4,1), (4,2), (4,3), (4,4), (4,5), (4,6) \\
(5,1), (5,2), (5,3), (5,4), (5,5), (5,6) \\
(6,1), (6,2), (6,3), (6,4), (6,5), (6,6) \}
\end{align*}
$$
2. @eq-matching-events: $15$
**Solution**:
$$\frac{15}{36} = \frac{5}{12}$$
:::
***
::: {#exm-02-2}
What is the probability of rolling three six-sided dice and getting a value greater than 7?
**Solution**:
```{r}
possible_events = dice_sum = success = 0
for (i in 1:6) {
for (j in 1:6) {
for (k in 1:6) {
possible_events <- possible_events + 1
dice_sum <- i + j + k
if (dice_sum > 7) {
success <- success + 1
}
}
}
}
glue::glue('Possible events = {possible_events}, \n',
'Dice value > 7 = {success}, \n',
'Probability = {success} / {possible_events} = {success / possible_events}')
```
:::
::: {exm-02-3}
The Yankees are playing the Red Sox. You’re a diehard Sox fan and bet your friend they’ll win the game. You’ll pay your friend \$30 if the Sox lose and your friend will have to pay you only \$5 if the Sox win. What is the probability you have intuitively assigned to the belief that the Red Sox will win?
**Solution**:
$$odds = \frac{30}{5} = 6$$
Probability is calculated with @eq-p-odds:
$$p = \frac{odds}{1 + odds} = $$
<center>$p = \frac{6}{1 + 6} = \frac{6}{7}$ = `r round(6/7, 2)`</center>
:::