-
Notifications
You must be signed in to change notification settings - Fork 31k
Expand file tree
/
Copy pathindex.Rmd
More file actions
executable file
·276 lines (203 loc) · 7.64 KB
/
index.Rmd
File metadata and controls
executable file
·276 lines (203 loc) · 7.64 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
---
title : Probability
subtitle : Statistical Inference
author : Brian Caffo, Jeff Leek, Roger Peng
job : Johns Hopkins Bloomberg School of Public Health
logo : bloomberg_shield.png
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
url:
lib: ../../librariesNew
assets: ../../assets
widgets : [mathjax] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
---
## Notation
- The **sample space**, $\Omega$, is the collection of possible outcomes of an experiment
- Example: die roll $\Omega = \{1,2,3,4,5,6\}$
- An **event**, say $E$, is a subset of $\Omega$
- Example: die roll is even $E = \{2,4,6\}$
- An **elementary** or **simple** event is a particular result
of an experiment
- Example: die roll is a four, $\omega = 4$
- $\emptyset$ is called the **null event** or the **empty set**
---
## Interpretation of set operations
Normal set operations have particular interpretations in this setting
1. $\omega \in E$ implies that $E$ occurs when $\omega$ occurs
2. $\omega \not\in E$ implies that $E$ does not occur when $\omega$ occurs
3. $E \subset F$ implies that the occurrence of $E$ implies the occurrence of $F$
4. $E \cap F$ implies the event that both $E$ and $F$ occur
5. $E \cup F$ implies the event that at least one of $E$ or $F$ occur
6. $E \cap F=\emptyset$ means that $E$ and $F$ are **mutually exclusive**, or cannot both occur
7. $E^c$ or $\bar E$ is the event that $E$ does not occur
---
## Probability
A **probability measure**, $P$, is a function from the collection of possible events so that the following hold
1. For an event $E\subset \Omega$, $0 \leq P(E) \leq 1$
2. $P(\Omega) = 1$
3. If $E_1$ and $E_2$ are mutually exclusive events
$P(E_1 \cup E_2) = P(E_1) + P(E_2)$.
Part 3 of the definition implies **finite additivity**
$$
P(\cup_{i=1}^n A_i) = \sum_{i=1}^n P(A_i)
$$
where the $\{A_i\}$ are mutually exclusive. (Note a more general version of
additivity is used in advanced classes.)
---
## Example consequences
- $P(\emptyset) = 0$
- $P(E) = 1 - P(E^c)$
- $P(A \cup B) = P(A) + P(B) - P(A \cap B)$
- if $A \subset B$ then $P(A) \leq P(B)$
- $P\left(A \cup B\right) = 1 - P(A^c \cap B^c)$
- $P(A \cap B^c) = P(A) - P(A \cap B)$
- $P(\cup_{i=1}^n E_i) \leq \sum_{i=1}^n P(E_i)$
- $P(\cup_{i=1}^n E_i) \geq \max_i P(E_i)$
---
## Example
The National Sleep Foundation ([www.sleepfoundation.org](http://www.sleepfoundation.org/)) reports that around 3% of the American population has sleep apnea. They also report that around 10% of the North American and European population has restless leg syndrome. Does this imply that 13% of people will have at least one sleep problems of these sorts?
---
## Example continued
Answer: No, the events are not mutually exclusive. To elaborate let:
$$
\begin{eqnarray*}
A_1 & = & \{\mbox{Person has sleep apnea}\} \\
A_2 & = & \{\mbox{Person has RLS}\}
\end{eqnarray*}
$$
Then
$$
\begin{eqnarray*}
P(A_1 \cup A_2 ) & = & P(A_1) + P(A_2) - P(A_1 \cap A_2) \\
& = & 0.13 - \mbox{Probability of having both}
\end{eqnarray*}
$$
Likely, some fraction of the population has both.
---
## Random variables
- A **random variable** is a numerical outcome of an experiment.
- The random variables that we study will come in two varieties,
**discrete** or **continuous**.
- Discrete random variable are random variables that take on only a
countable number of possibilities.
* $P(X = k)$
- Continuous random variable can take any value on the real line or some subset of the real line.
* $P(X \in A)$
---
## Examples of variables that can be thought of as random variables
- The $(0-1)$ outcome of the flip of a coin
- The outcome from the roll of a die
- The BMI of a subject four years after a baseline measurement
- The hypertension status of a subject randomly drawn from a population
---
## PMF
A probability mass function evaluated at a value corresponds to the
probability that a random variable takes that value. To be a valid
pmf a function, $p$, must satisfy
1. $p(x) \geq 0$ for all $x$
2. $\sum_{x} p(x) = 1$
The sum is taken over all of the possible values for $x$.
---
## Example
Let $X$ be the result of a coin flip where $X=0$ represents
tails and $X = 1$ represents heads.
$$
p(x) = (1/2)^{x} (1/2)^{1-x} ~~\mbox{ for }~~x = 0,1
$$
Suppose that we do not know whether or not the coin is fair; Let
$\theta$ be the probability of a head expressed as a proportion
(between 0 and 1).
$$
p(x) = \theta^{x} (1 - \theta)^{1-x} ~~\mbox{ for }~~x = 0,1
$$
---
## PDF
A probability density function (pdf), is a function associated with
a continuous random variable
*Areas under pdfs correspond to probabilities for that random variable*
To be a valid pdf, a function $f$ must satisfy
1. $f(x) \geq 0$ for all $x$
2. The area under $f(x)$ is one.
---
## Example
Suppose that the proportion of help calls that get addressed in
a random day by a help line is given by
$$
f(x) = \left\{\begin{array}{ll}
2 x & \mbox{ for } 1 > x > 0 \\
0 & \mbox{ otherwise}
\end{array} \right.
$$
Is this a mathematically valid density?
---
```{r, fig.height = 5, fig.width = 5, echo = TRUE, fig.align='center'}
x <- c(-0.5, 0, 1, 1, 1.5); y <- c( 0, 0, 2, 0, 0)
plot(x, y, lwd = 3, frame = FALSE, type = "l")
```
---
## Example continued
What is the probability that 75% or fewer of calls get addressed?
```{r, fig.height = 5, fig.width = 5, echo = FALSE, fig.align='center'}
plot(x, y, lwd = 3, frame = FALSE, type = "l")
polygon(c(0, .75, .75, 0), c(0, 0, 1.5, 0), lwd = 3, col = "lightblue")
```
---
```{r}
1.5 * .75 / 2
pbeta(.75, 2, 1)
```
---
## CDF and survival function
- The **cumulative distribution function** (CDF) of a random variable $X$ is defined as the function
$$
F(x) = P(X \leq x)
$$
- This definition applies regardless of whether $X$ is discrete or continuous.
- The **survival function** of a random variable $X$ is defined as
$$
S(x) = P(X > x)
$$
- Notice that $S(x) = 1 - F(x)$
- For continuous random variables, the PDF is the derivative of the CDF
---
## Example
What are the survival function and CDF from the density considered before?
For $1 \geq x \geq 0$
$$
F(x) = P(X \leq x) = \frac{1}{2} Base \times Height = \frac{1}{2} (x) \times (2 x) = x^2
$$
$$
S(x) = 1 - x^2
$$
```{r}
pbeta(c(0.4, 0.5, 0.6), 2, 1)
```
---
## Quantiles
- The $\alpha^{th}$ **quantile** of a distribution with distribution function $F$ is the point $x_\alpha$ so that
$$
F(x_\alpha) = \alpha
$$
- A **percentile** is simply a quantile with $\alpha$ expressed as a percent
- The **median** is the $50^{th}$ percentile
---
## Example
- We want to solve $0.5 = F(x) = x^2$
- Resulting in the solution
```{r, echo = TRUE}
sqrt(0.5)
```
- Therefore, about `r sqrt(0.5)` of calls being answered on a random day is the median.
- R can approximate quantiles for you for common distributions
```{r}
qbeta(0.5, 2, 1)
```
---
## Summary
- You might be wondering at this point "I've heard of a median before, it didn't require integration. Where's the data?"
- We're referring to are **population quantities**. Therefore, the median being
discussed is the **population median**.
- A probability model connects the data to the population using assumptions.
- Therefore the median we're discussing is the **estimand**, the sample median will be the **estimator**