-
Notifications
You must be signed in to change notification settings - Fork 9
/
06-class.Rmd
719 lines (440 loc) · 15.4 KB
/
06-class.Rmd
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
---
title: "Class 6: Validity + confidence intervals"
author: "Andrew Heiss"
date: "`r Sys.Date()`"
output:
xaringan::moon_reader:
lib_dir: "libs"
chakra: "libs/remark-latest.min.js"
css: ["default", "css/ath-slides.css", "css/ath-inferno-fonts.css", "css/animate.css"]
seal: false
anchor_sections: false
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
ratio: "16:9"
navigation:
scroll: false
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE,
fig.retina = 3, fig.align = "center")
```
```{r packages-data, include=FALSE}
library(tidyverse)
library(ggdag)
library(palmerpenguins)
library(modelsummary)
```
```{r xaringanExtra, echo=FALSE}
xaringanExtra::use_xaringan_extra(c("tile_view"))
```
class: center middle main-title section-title-3
# In-person<br>session 6
.class-info[
**February 16, 2023**
.light[PMAP 8521: Program evaluation<br>
Andrew Young School of Policy Studies
]
]
---
name: outline
class: title title-inv-8
# Plan for today
--
.box-1.medium.sp-after-half[Exam 1]
--
.box-3.medium.sp-after-half[FAQs]
--
.box-5.medium.sp-after-half[Confidence intervals, credible intervals,<br>and a crash course on Bayesian statistics]
---
layout: false
name: exam-1
class: center middle section-title section-title-1 animated fadeIn
# Exam 1
---
layout: true
class: middle
---
.box-1.large[Tell us about Exam 1!]
---
layout: false
name: faqs
class: center middle section-title section-title-3 animated fadeIn
# FAQs
---
layout: true
class: middle
---
.box-3.large[What's the difference<br>between `+` and `%>%`?]
???
- <https://github.com/tonsky/FiraCode>
---
.box-3.large[Are *p*-values really misinterpreted<br>in published research?]
---
.box-3.large[Power calculations and sample size]
.box-3.medium[Won't we always be able to find<br>a significant effect if the<br>sample size is big enough?]
.box-inv-3.small[Yes!]
---
.box-3.huge[Math with computers]
.box-inv-3[andhs.co/live]
---
.box-3.large[Are the results from<br>p-hacking actually a<br>threat to validity?]
???
<https://projects.fivethirtyeight.com/p-hacking/>
---
.box-3.large[Do people actually post<br>their preregistrations?]
---
.box-3.large.sp-after[Yes!]
.box-3.medium[[OSF](https://osf.io/prereg/)]
.box-inv-3.sp-after[See [this](https://stats.andrewheiss.com/ngo-crackdowns-philanthropy/preregistration.html) and [this](https://stats.andrewheiss.com/why-donors-donate/preregistration.html) for examples]
.box-3.medium[[As Predicted](https://aspredicted.org/)]
.box-inv-3[See [this](https://aspredicted.org/blind.php?x=jr2hr3)]
---
.box-3.medium[Do you have any tips for identifying the<br>threats to validity in articles since<br>they're often not super clear?]
.box-3[Especially things like spillovers,<br>Hawthorne effects, and John Henry effects?]
---
.box-3.medium[Using a control group of some kind<br>seems to be the common fix<br>for all of these issues.]
.box-3.medium[What happens if you can't do that?<br>Is the study just a lost cause?]
???
That's the point of DAGs and quasi experiments; simulate having treatment and control groups
---
layout: false
name: bayes
class: center middle section-title section-title-5 animated fadeIn
# Confidence intervals,<br>credible intervals,<br>and a crash course on Bayesian statistics
---
class: middle
.box-5.large[In the absence of p-values,<br>I'm confused about how<br>we report… significance?]
---
class: middle
.box-5.huge[Math with computers]
.box-inv-5[andhs.co/live]
---
layout: true
class: title title-5
---
# Imbens and p-values
.box-inv-5[Nobody really cares about p-values]
--
.box-inv-5[Decision makers want to know<br>a number or a range of numbers—<br>some sort of effect and uncertainty]
--
.box-inv-5[Nobody cares how likely a number would be<br>in an imaginary null world!]
---
# Imbens's solution
.box-inv-5[Report point estimates and some sort of range]
> "It would be preferable if reporting standards emphasized confidence intervals or standard errors, and, even better, Bayesian posterior intervals."
--
.pull-left[
.box-inv-5[Point estimate]
.box-5.small[The single number you calculate<br>(mean, coefficient, etc.)]
]
.pull-right[
.box-inv-5[Uncertainty]
.box-5.small[A range of possible values]
]
---
# Greek, Latin, and extra markings
.box-inv-5[Statistics: use a sample to make inferences about a population]
--
.pull-left[
.box-5[Greek]
Letters like $\beta_1$ are the ***truth***
Letters with extra markings like $\hat{\beta_1}$ are our ***estimate*** of the truth based on our sample
]
--
.pull-right[
.box-5[Latin]
Letters like $X$ are ***actual data*** from our sample
Letters with extra markings like $\bar{X}$ are ***calculations*** from our sample
]
---
# Estimating truth
.box-inv-5.sp-after[Data → Calculation → Estimate → Truth]
--
.pull-left[
<table>
<tr>
<td class="cell-left">Data</td>
<td class="cell-center">\(X\)</td>
</tr>
<tr>
<td class="cell-left">Calculation </td>
<td class="cell-center">\(\bar{X} = \frac{\sum{X}}{N}\)</td>
</tr>
<tr>
<td class="cell-left">Estimate</td>
<td class="cell-center">\(\hat{\mu}\)</td>
</tr>
<tr>
<td class="cell-left">Truth</td>
<td class="cell-center">\(\mu\)</td>
</tr>
</table>
]
--
.pull-right[
$$
\bar{X} = \hat{\mu}
$$
$$
X \rightarrow \bar{X} \rightarrow \hat{\mu} \xrightarrow{\text{🤞 hopefully 🤞}} \mu
$$
]
---
# Population parameter
.box-inv-5.large[Truth = Greek letter]
.box-5[An single unknown number that is true for the entire population]
--
.box-inv-5.small[Proportion of left-handed students at GSU]
.box-inv-5.small[Median rent of apartments in NYC]
.box-inv-5.small[Proportion of red M&Ms produced in a factory]
.box-inv-5.small[ATE of your program]
---
# Samples and estimates
.box-inv-5.medium[We take a sample and make a guess]
--
.box-5[This single value is a *point estimate*]
.box-5.small[(This is the Greek letter with a hat)]
---
# Variability
.box-inv-5.medium[You have an estimate,<br>but how different might that<br>estimate be if you take another sample?]
---
# Left-handedness
.box-inv-5.medium[You take a random sample of<br>50 GSU students and 5 are left-handed.]
--
.box-5.less-medium[If you take a different random sample of<br>50 GSU students, how many would you<br>expect to be left-handed?]
--
.box-inv-5[3 are left-handed. Is that surprising?]
--
.box-inv-5[40 are left-handed. Is that surprising?]
---
# Nets and confidence intervals
.box-inv-5.medium[How confident are we that the sample<br>picked up the population parameter?]
--
.box-inv-5.medium[Confidence interval is a net]
--
.box-5[We can be X% confident that our net is<br>picking up that population parameter]
.box-inv-5.small[If we took 100 samples, at least 95 of them would have the<br>true population parameter in their 95% confidence intervals]
---
layout: false
> A city manager wants to know the true average property value of single-value homes in her city. She takes a random sample of 200 houses and builds a 95% confidence interval. The interval is ($180,000, $300,000).
--
.box-5[We're 95% confident that the<br>interval ($180,000, $300,000)<br>captured the true mean value]
---
layout: true
class: title title-5
---
# WARNING
--
.box-inv-5.medium[It is way too tempting to say <br>“We’re 95% sure that the<br>population parameter is X”]
--
.box-5[People do this all the time! People with PhDs!]
--
.box-5[YOU will try to do this too]
???
OpenIntro Stats p. 186
First, notice that the statements are always about the population parameter, which considers all American adults for the energy polls or all New York adults for the quarantine poll.
We also avoided another common mistake: incorrect language might try to describe the confidence interval as capturing the population parameter with a certain probability. Making a probability interpretation is a common error: while it might be useful to think of it as a probability, the confidence level only quantifies how plausible it is that the parameter is in the given interval.
Another important consideration of confidence intervals is that they are only about the population parameter. A confidence interval says nothing about individual observations or point estimates. Confidence intervals only provide a plausible range for population parameters.
---
# Nets
.box-inv-5.medium[If you took lots of samples,<br>95% of their confidence intervals<br>would have the single true value in them]
---
layout: false
.center[
<figure>
<img src="img/06-class/reliable-se-1.png" alt="Lots of confidence intervals" title="Lots of confidence intervals" width="80%">
</figure>
]
---
layout: true
class: title title-5
---
# Frequentism
.box-inv-5.medium[This kind of statistics is called "frequentism"]
--
.box-5[The population parameter θ is fixed and singular<br>while the data can vary]
$$
P(\text{Data} \mid \theta)
$$
--
.box-5[You can do an experiment over and over again;<br>take more and more samples and polls]
---
# Frequentist confidence intervals
.box-inv-5.medium.sp-before["We are 95% confident that this net<br>captures the true population parameter"]
--
.box-5.medium.sp-before[~~"There's a 95% chance that the<br>true value falls in this range"~~]
---
layout: false
class: middle
.box-5.huge[Weekends and<br>restaurant scores]
---
layout: true
class: title title-5
---
# Bayesian statistics
.pull-left[
.center[
<figure>
<img src="img/06-class/bayes.jpg" alt="Thomas Bayes" title="Thomas Bayes" width="80%">
<figcaption>Rev. Thomas Bayes</figcaption>
</figure>
]
]
.pull-right.small[
$$P(\theta \mid \text{Data})$$
$$\color{orange}{P(\text{H} \mid \text{E})} = \frac{\color{red}{P(\text{H})} \times\color{blue}{P(\text{E} \mid \text{H})}}{\color{black}{P(\text{E})}}$$
]
---
# Bayesianism in WWII
.pull-left[
.center[
<figure>
<img src="img/06-class/turing.jpg" alt="Alan Turing" title="Alan Turing" width="65%">
<figcaption>Alan Turing</figcaption>
</figure>
]
]
.pull-right[
.center[
<figure>
<img src="img/06-class/enigma.jpg" alt="Enigma machine" title="Enigma machine" width="85%">
<figcaption>An enigma machine</figcaption>
</figure>
]
]
---
layout: true
class: middle
---
$$\color{orange}{P(\text{H} \mid \text{E})} = \frac{\color{red}{P(\text{H})} \times\color{blue}{P(\text{E} \mid \text{H})}}{\color{black}{P(\text{E})}}$$
$$
\color{orange}{P(\text{Hypothesis} \mid \text{Evidence})} =
$$
$$
\frac{
\color{red}{P(\text{Hypothesis})} \times
\color{blue}{P(\text{Evidence} \mid \text{Hypothesis})}
}{
\color{black}{P(\text{Evidence})}
}
$$
---
.center[
<figure>
<img src="img/06-class/step1.png" alt="Bayesian formulas" title="Bayesian formulas" width="100%">
</figure>
]
---
.center[
<figure>
<img src="img/06-class/step2.png" alt="Bayesian formulas" title="Bayesian formulas" width="100%">
</figure>
]
---
.box-5.huge[Bayesian statistics and<br>more complex questions]
---
.center[
<figure>
<img src="img/06-class/step3.png" alt="Bayesian formulas" title="Bayesian formulas" width="100%">
</figure>
]
---
.box-5.huge[But the math is too hard!]
.box-inv-5[So we simulate!]
.box-inv-5.small[(Monte Carlo Markov Chains, or MCMC)]
---
.box-5.huge[Weekends and<br>restaurant scores again]
---
layout: true
class: title title-5
---
# Bayesianism and parameters
.center[
.pull-left-wide[
.box-inv-5[In the world of frequentism,<br>there's a fixed population parameter<br>and the data can hypothetically vary]
]
.pull-right-narrow[
$$
P(\text{Data} \mid \theta)
$$
]
]
--
.center[
.pull-left-wide[
.box-inv-5[In the world of Bayesianism,<br>the data is fixed .small[(you collected it just once!)]<br>and the population parameter can vary]
]
.pull-right-narrow[
$$
P(\theta \mid \text{Data})
$$
]
]
???
In frequentism land, the parameter is fixed and singular and the data can vary - you can do an experiment over and over again, take more and more samples and polls
In Bayes land, the data is fixed (you collected it, that's it), and the parameter can vary
---
# Bayesian credible intervals
.box-5.small[(AKA posterior intervals)]
.box-inv-5.medium.sp-before["Given the data, there is a 95% probability<br>that the true population parameter<br>falls in the credible interval"]
???
> a Bayesian statistician would say “given our observed data, there is a 95% probability that the true value of θ falls within the credible region” while a Frequentist statistician would say “there is a 95% probability that when I compute a confidence interval from data of this sort, the true value of θ will fall within it”.
(https://freakonometrics.hypotheses.org/18117)
> Note how this drastically improve the interpretability of the Bayesian interval compared to the frequentist one. Indeed, the Bayesian framework allows us to say “given the observed data, the effect has 95% probability of falling within this range”, compared to the less straightforward, frequentist alternative (the 95% Confidence* Interval) would be “there is a 95% probability that when computing a confidence interval from data of this sort, the effect falls within this range”.
(https://easystats.github.io/bayestestR/articles/credible_interval.html)
---
# Intervals
.pull-left[
.box-inv-5.medium[Frequentism]
.box-5[There's a 95% probability<br>that the range contains the true value]
.box-5[Probability of the range]
.box-inv-5[Few people naturally<br>think like this]
]
.pull-right[
.box-inv-5.medium[Bayesianism]
.box-5[There's a 95% probability<br>that the true value falls in this range]
.box-5[Probability of the actual value]
.box-inv-5[People *do* naturally<br>think like this!]
]
???
There's a 95% probability that the range contains the true value (freq) - We are 95% confident that this net captures the true population parameter
vs.
There's a 95% probability that the the true value falls in this range (bayes)
This is a minor linguistic difference but it actually matters a lot! With frequentism, you have a range of possible values - you don't really know the true parameter, but it's in that range somewhere. Could be at the very edge, could be in the middle. With Bayesianism, you focus on the parameter itself, which has a distribution around it. It could be on the edge, but is most likely in the middle
Probability of range boundaries vs probability of parameter values
Bayesian p-value = probability that it's greater than 0 - you can say that there's a 100% chance that the coefficient is not zero, no more null worlds!
---
# Thinking Bayesianly
.box-inv-5.less-medium[We all think Bayesianly,<br>even if you've never heard of Bayesian stats]
.box-5[Every time you look at a confidence interval, you inherently think that the parameter is around that value, but that's wrong!]
--
.box-inv-5.less-medium.sp-before[BUT Imbens cites research that<br>that's actually generally okay]
.box-5[Often credible intervals are super similar to confidence intervals]
---
# Bayesian inference
.box-inv-5.medium[What do you do without p-values then?]
--
.pull-left[
.box-5.small[Probability<br>of direction]
<figure>
<img src="img/06-class/plot-pd-1.png" alt="Probability of direction" title="Probability of direction" width="100%">
</figure>
]
--
.pull-right[
.box-5.small[Region of practical<br>equivalence (ROPE)]
<figure>
<img src="img/06-class/plot-rope-1.png" alt="ROPE" title="ROPE" width="100%">
</figure>
]
---
layout: false
class: middle
.box-5.huge[Weekends and<br>restaurant scores<br>once more]