class: center, middle, inverse, title-slide # POL90: Statistics ##
t
-tests Continued ### Prof Wasow
Assistant Professor, Politics
Pomona College ### 2021-02-15 --- # Announcements .large[ * Assignments + PS03 due <mark>Friday, 2/11</mark> + Report 1 ] --- # Schedule <table> <thead> <tr> <th style="text-align:right;"> Week </th> <th style="text-align:left;"> Date </th> <th style="text-align:left;"> Day </th> <th style="text-align:left;"> Title </th> <th style="text-align:right;"> Chapter </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> 2 </td> <td style="text-align:left;"> Jan 24 </td> <td style="text-align:left;"> Mon </td> <td style="text-align:left;"> Drawing Statistical Conclusions </td> <td style="text-align:right;"> 1 </td> </tr> <tr> <td style="text-align:right;"> 2 </td> <td style="text-align:left;"> Jan 26 </td> <td style="text-align:left;"> Wed </td> <td style="text-align:left;"> Drawing Statistical Conclusions </td> <td style="text-align:right;"> 1 </td> </tr> <tr> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Jan 31 </td> <td style="text-align:left;"> Mon </td> <td style="text-align:left;"> Inference Using t-Distributions </td> <td style="text-align:right;"> 2 </td> </tr> <tr> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Feb 2 </td> <td style="text-align:left;"> Wed </td> <td style="text-align:left;"> Inference Using t-Distributions </td> <td style="text-align:right;"> 2 </td> </tr> <tr> <td style="text-align:right;color: black !important;background-color: yellow !important;"> 4 </td> <td style="text-align:left;color: black !important;background-color: yellow !important;"> Feb 7 </td> <td style="text-align:left;color: black !important;background-color: yellow !important;"> Mon </td> <td style="text-align:left;color: black !important;background-color: yellow !important;"> A Closer Look at Assumptions </td> <td style="text-align:right;color: black !important;background-color: yellow !important;"> 3 </td> </tr> <tr> <td style="text-align:right;color: black !important;background-color: yellow !important;"> 4 </td> <td style="text-align:left;color: black !important;background-color: yellow !important;"> Feb 9 </td> <td style="text-align:left;color: black !important;background-color: yellow !important;"> Wed </td> <td style="text-align:left;color: black !important;background-color: yellow !important;"> A Closer Look at Assumptions </td> <td style="text-align:right;color: black !important;background-color: yellow !important;"> 3 </td> </tr> <tr> <td style="text-align:right;"> 5 </td> <td style="text-align:left;"> Feb 14 </td> <td style="text-align:left;"> Mon </td> <td style="text-align:left;"> Alternatives to the t-Tools </td> <td style="text-align:right;"> 4 </td> </tr> <tr> <td style="text-align:right;"> 5 </td> <td style="text-align:left;"> Feb 16 </td> <td style="text-align:left;"> Wed </td> <td style="text-align:left;"> Alternatives to the t-Tools </td> <td style="text-align:right;"> 4 </td> </tr> <tr> <td style="text-align:right;"> 6 </td> <td style="text-align:left;"> Feb 21 </td> <td style="text-align:left;"> Mon </td> <td style="text-align:left;"> Comparison Among Several Samples </td> <td style="text-align:right;"> 5 </td> </tr> <tr> <td style="text-align:right;"> 6 </td> <td style="text-align:left;"> Feb 23 </td> <td style="text-align:left;"> Wed </td> <td style="text-align:left;"> Comparison Among Several Samples </td> <td style="text-align:right;"> 5 </td> </tr> </tbody> </table> --- ## Assignment schedule <table> <thead> <tr> <th style="text-align:right;"> Week </th> <th style="text-align:left;"> Date </th> <th style="text-align:left;"> Day </th> <th style="text-align:left;"> Assignment </th> <th style="text-align:right;"> Percent </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Feb 4 </td> <td style="text-align:left;"> Fri </td> <td style="text-align:left;"> PS02 </td> <td style="text-align:right;"> 3 </td> </tr> <tr> <td style="text-align:right;color: black !important;background-color: yellow !important;"> 4 </td> <td style="text-align:left;color: black !important;background-color: yellow !important;"> Feb 11 </td> <td style="text-align:left;color: black !important;background-color: yellow !important;"> Fri </td> <td style="text-align:left;color: black !important;background-color: yellow !important;"> PS03 </td> <td style="text-align:right;color: black !important;background-color: yellow !important;"> 3 </td> </tr> <tr> <td style="text-align:right;"> 5 </td> <td style="text-align:left;"> Feb 18 </td> <td style="text-align:left;"> Fri </td> <td style="text-align:left;"> PS04 </td> <td style="text-align:right;"> 3 </td> </tr> <tr> <td style="text-align:right;"> 6 </td> <td style="text-align:left;"> Feb 25 </td> <td style="text-align:left;"> Fri </td> <td style="text-align:left;"> PS05 </td> <td style="text-align:right;"> 3 </td> </tr> <tr> <td style="text-align:right;"> 7 </td> <td style="text-align:left;"> Mar 4 </td> <td style="text-align:left;"> Fri </td> <td style="text-align:left;"> Report1 </td> <td style="text-align:right;"> 6 </td> </tr> <tr> <td style="text-align:right;"> 8 </td> <td style="text-align:left;"> Mar 11 </td> <td style="text-align:left;"> Fri </td> <td style="text-align:left;"> PS06 </td> <td style="text-align:right;"> 3 </td> </tr> <tr> <td style="text-align:right;"> 9 </td> <td style="text-align:left;"> Mar 18 </td> <td style="text-align:left;"> Fri </td> <td style="text-align:left;"> Spring break </td> <td style="text-align:right;"> NA </td> </tr> <tr> <td style="text-align:right;"> 10 </td> <td style="text-align:left;"> Mar 25 </td> <td style="text-align:left;"> Fri </td> <td style="text-align:left;"> PS07 </td> <td style="text-align:right;"> 3 </td> </tr> <tr> <td style="text-align:right;"> 11 </td> <td style="text-align:left;"> Apr 1 </td> <td style="text-align:left;"> Fri </td> <td style="text-align:left;"> PS08 </td> <td style="text-align:right;"> 3 </td> </tr> <tr> <td style="text-align:right;"> 12 </td> <td style="text-align:left;"> Apr 8 </td> <td style="text-align:left;"> Fri </td> <td style="text-align:left;"> Report2 </td> <td style="text-align:right;"> 8 </td> </tr> </tbody> </table> --- ## Coding tips .large[ - Based on ED & other questions - Only `install.packages()` about once per year - `install.packages()` is like installing an app, done rarely - `library()` is like opening an app, done every time used - In addition to knitting Rmd, run chunks interactively, confirm each step works ] <!-- - For now, knitting to HTML or Word okay but won't work later in semester --> --- class: center, middle, inverse # Report 1 --- class: center ## Report 1: Test a theory, elites vs masses .pull-left[<img src="images/Zaller_James_big_square.jpg" alt="drawing" style="width:200px;"/><img src="images/lenz_gabriel2.jpg" alt="drawing" style="width:200px;"/>] .pull-right[<img src="images/lee_taeku_big.jpg" alt="drawing" style="width:200px;"/><img src="images/erica-chenoweth-maria-stephan-nsc-briefing.jpg" alt="drawing" style="width:200px;"/><img src="images/Daniel-Gillion3.jpg" alt="drawing" style="width:200px;"/>] --- class: center ## Report 1: Engage with texts, not people .pull-left[<img src="images/zaller_book_cover.jpg" alt="drawing" style="width:150px;"/> <img src="images/lenz_book_cover.jpg" alt="drawing" style="width:150px;"/>] .pull-rigth[<img src="images/lee_book_cover.jpg" alt="drawing" style="width:100px;"/> <img src="images/stephan_chenoweth_book_cover.jpg" alt="drawing" style="width:100px;"/> <img src="images/gillion_book_cover.jpg" alt="drawing" style="width:100px;"/>] --- ## Pew: US opinion on same-sex marriage, 2001-2017 <img src="images/pew_same_sex_marriage.png" width="75%" style="display: block; margin: auto;" /> .footnote[Source: http://www.pewforum.org/fact-sheet/changing-attitudes-on-gay-marriage/] --- ## Report 1: Goals .large[ * Use data to test theories - A contest or horserace of theories - "Three cornered fight" or a court proceeding ] -- .large[ * Use data as rhetoric - Report a statistical test - Summarize data in a table - Convey trends and relationships with visualization ] -- .large[ * Produce replicable research - See how "literate programming" like R + R Markdown + Latex + knitr contributes to replication - Practice good programming and statistical style ] --- ## Report Questions & Suggestions .large[ - Plan to use iPoll - Register on iPoll it makes downloading many polls much easier - You will need to do some data cleaning, that's part of the assignment - See Data Scrubbing handout: http://appliedstats.org/data_scrub_handout.html - Collaboration may be easier with RStudio.cloud. See link on Canvas & handout: http://appliedstats.org/rstudio_cloud_guide.html ] --- class: center, middle, inverse # Simulation vs Analytic methods --- ## Downey: Simplifying hypothesis testing .vertical-center[ .large[ 1. A test statistic, 2. A model of a null hypothesis, and usually, 3. A method that computes or approximates the *p*-value. ] ] --- ## Calculate Test Statistic - First calculate a test statistic <br><br> <img src="images/allen_downey_one_hypothesis_test_mod1.png" width="100%" style="display: block; margin: auto;" /> .footnote[Source: http://allendowney.blogspot.com/2016/06/there-is-still-only-one-test.html] --- ## Simulation methods - With randomization, compare test statistic to simulated null distribution <br><br> <img src="images/allen_downey_one_hypothesis_test.png" width="100%" style="display: block; margin: auto;" /> .footnote[Source: http://allendowney.blogspot.com/2016/06/there-is-still-only-one-test.html] --- ## Analytical methods, example *t*-test - With analytical methods, we transform the test statistic (such as by dividing by the standard error), and then compare to a theoretical distribution <img src="images/allen_downey_one_hypothesis_test_modified_t-stat.png" width="100%" style="display: block; margin: auto;" /> .footnote[Source: http://allendowney.blogspot.com/2016/06/there-is-still-only-one-test.html] --- ## With Randomization, No Transformations of Estimate ```r library(infer) creativity_null_distribution <- creativity %>% infer::specify(score ~ treatment) %>% infer::hypothesize(null = "independence") %>% infer::generate(reps = 1000, type = "permute") %>% infer::calculate(stat = "diff in means", order = c("Intrinsic", "Extrinsic")) head(creativity_null_distribution) ``` ``` Response: score (numeric) Explanatory: treatment (factor) Null Hypothesis: independence # A tibble: 6 × 2 replicate stat <int> <dbl> 1 1 2.67 2 2 -0.973 3 3 0.892 4 4 0.364 5 5 -0.471 6 6 1.02 ``` --- ## Estimate on Same Scale as Null Distribution ```r library(ggplot2) infer::visualize(creativity_null_distribution) + geom_vline(xintercept = c(-4.14, 4.14), col = "red") ``` <img src="week04_01_files/figure-html/unnamed-chunk-12-1.png" width="504" style="display: block; margin: auto;" /> --- ## With `\(t\)`-test, Estimate Must be Transformed .vertical-center[ $$ t\text{-ratio} = \dfrac{\text{Estimate}-\text{Parameter}}{\text{SE(Estimate)}} $$ $$ t-\text{ratio}(\text{if } \mu \text{ is zero}) = \dfrac{0.199-0}{0.0615} = 3.236 $$ ] --- ## Visualizing *t*-Ratio on *t*-distribution ```r visualize::visualize.t(stat = c(-3.23, 3.23), df = 14, section = "tails") ``` <img src="week04_01_files/figure-html/unnamed-chunk-14-1.png" width="50%" style="display: block; margin: auto;" /> --- class: center, middle ## Data as Storytelling --- <br/><br/><br/> <img src="images/data_science_storytellers.png" width="612" style="display: block; margin: auto;" /> .footnote[ Source: https://twitter.com/benhamner/status/434860448010080256 ] --- .center[![](images/hans_rosling.jpg)] .footnote[Source: https://www.ted.com/talks/hans_rosling_shows_the_best_stats_you_ve_ever_seen] --- class: middle, center background-color: #000000 <iframe width="1120" height="630" src="https://www.youtube.com/embed/jbkSRLYSojo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> --- class: center, middle # Questions?