class: center, middle, inverse, title-slide .title[ # PSY 503: Foundations of Statistical Methods in Psychological Science ] .subtitle[ ## More LM: Categorical Predictors ] .author[ ### Jason Geller, Ph.D. (he/him/his) ] .institute[ ### Princeton University ] .date[ ### Updated:2022-11-02 ] --- <div style = "position:fixed; visibility: hidden"> `$$\require{color}\definecolor{red}{rgb}{1, 0, 0}$$` `$$\require{color}\definecolor{green}{rgb}{0, 1, 0}$$` `$$\require{color}\definecolor{blue}{rgb}{0, 0, 1}$$` </div> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ TeX: { Macros: { red: ["{\\color{red}{#1}}", 1], green: ["{\\color{green}{#1}}", 1], blue: ["{\\color{blue}{#1}}", 1] }, loader: {load: ['[tex]/color']}, tex: {packages: {'[+]': ['color']}} } }); </script> <style> .red {color: #FF0000;} .green {color: #00FF00;} .blue {color: #0000FF;} </style> # Outline - Check-in questions - Effect size and power in MR - Categorical predictors - How linear modeling is related to t-tests/ANOVAs - Contrast coding for categorical predictors with two means - Contrast coding for categorical predictors with three means or more --- # Check-in Questions - What the heck is heteroskedasticity? --- # Heteroskedasticity - Non-constant error (residual) variance - Residuals and predictors are correlated <img src="hetero.webp" width="60%" style="display: block; margin: auto;" /> --- # Heteroskedasticity - Consequences: - Causes standard errors (SE) to be unreliable - Increased Type 1 and Type 2 Error - Solution: - Easiest would be to use robust methods for the SE --- .pull-left[ ```r library(performance) model_parameters(model2) %>% flextable() %>% autofit() ``` <template id="09cd7a52-28c3-497b-9d6d-f4f736478fa7"><style> .tabwid table{ border-spacing:0px !important; border-collapse:collapse; line-height:1; margin-left:auto; margin-right:auto; border-width: 0; display: table; margin-top: 1.275em; margin-bottom: 1.275em; border-color: transparent; } .tabwid_left table{ margin-left:0; } .tabwid_right table{ margin-right:0; } .tabwid td { padding: 0; } .tabwid a { text-decoration: none; } .tabwid thead { background-color: transparent; } .tabwid tfoot { background-color: transparent; } .tabwid table tr { background-color: transparent; } .katex-display { margin: 0 0 !important; } </style><div class="tabwid"><style>.cl-fcdda176{}.cl-fcd77bc0{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-fcd78cf0{margin:0;text-align:left;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-fcd78cfa{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-fcd7be28{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be32{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be33{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be34{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be3c{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be46{width:82.3pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be47{width:274.4pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be50{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be5a{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be5b{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be5c{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be64{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be65{width:82.3pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be6e{width:274.4pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be6f{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be78{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be79{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be82{width:82.3pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be8c{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be8d{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be8e{width:274.4pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be96{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7be97{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7bea0{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7bea1{width:274.4pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7beaa{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7beab{width:82.3pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7beac{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7beb4{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7beb5{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7bebe{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7bebf{width:274.4pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7bec0{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7bec8{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcd7bec9{width:82.3pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table class='cl-fcdda176'><thead><tr style="overflow-wrap:break-word;"><td class="cl-fcd7bec8"><p class="cl-fcd78cf0"><span class="cl-fcd77bc0">Parameter</span></p></td><td class="cl-fcd7beb5"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">Coefficient</span></p></td><td class="cl-fcd7beb4"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">SE</span></p></td><td class="cl-fcd7bebe"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">CI</span></p></td><td class="cl-fcd7beb4"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">CI_low</span></p></td><td class="cl-fcd7beb5"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">CI_high</span></p></td><td class="cl-fcd7bec9"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">t</span></p></td><td class="cl-fcd7bec0"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">df_error</span></p></td><td class="cl-fcd7bebf"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">p</span></p></td></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td class="cl-fcd7be34"><p class="cl-fcd78cf0"><span class="cl-fcd77bc0">(Intercept)</span></p></td><td class="cl-fcd7be28"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">55.16373592</span></p></td><td class="cl-fcd7be33"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">3.88904610</span></p></td><td class="cl-fcd7be3c"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.95</span></p></td><td class="cl-fcd7be33"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">47.5059719</span></p></td><td class="cl-fcd7be28"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">62.82149992</span></p></td><td class="cl-fcd7be46"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">14.1843873</span></p></td><td class="cl-fcd7be32"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">262</span></p></td><td class="cl-fcd7be47"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.0000000000000000000000000000000002841237</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fcd7be64"><p class="cl-fcd78cf0"><span class="cl-fcd77bc0">PIL_total</span></p></td><td class="cl-fcd7be5c"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">-0.38157775</span></p></td><td class="cl-fcd7be5a"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.03384062</span></p></td><td class="cl-fcd7be5b"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.95</span></p></td><td class="cl-fcd7be5a"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">-0.4482119</span></p></td><td class="cl-fcd7be5c"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">-0.31494356</span></p></td><td class="cl-fcd7be65"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">-11.2757330</span></p></td><td class="cl-fcd7be50"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">262</span></p></td><td class="cl-fcd7be6e"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.0000000000000000000000026622090508643975</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fcd7be78"><p class="cl-fcd78cf0"><span class="cl-fcd77bc0">AUDIT_TOTAL_NEW</span></p></td><td class="cl-fcd7be79"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">-0.09210892</span></p></td><td class="cl-fcd7be8d"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.09391092</span></p></td><td class="cl-fcd7be6f"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.95</span></p></td><td class="cl-fcd7be8d"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">-0.2770251</span></p></td><td class="cl-fcd7be79"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.09280729</span></p></td><td class="cl-fcd7be82"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">-0.9808116</span></p></td><td class="cl-fcd7be8c"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">262</span></p></td><td class="cl-fcd7be8e"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.3275904695939578781249679195752833038568</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fcd7beac"><p class="cl-fcd78cf0"><span class="cl-fcd77bc0">DAST_TOTAL_NEW</span></p></td><td class="cl-fcd7be97"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">1.03415391</span></p></td><td class="cl-fcd7beaa"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.39871264</span></p></td><td class="cl-fcd7be96"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.95</span></p></td><td class="cl-fcd7beaa"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.2490649</span></p></td><td class="cl-fcd7be97"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">1.81924291</span></p></td><td class="cl-fcd7beab"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">2.5937324</span></p></td><td class="cl-fcd7bea0"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">262</span></p></td><td class="cl-fcd7bea1"><p class="cl-fcd78cfa"><span class="cl-fcd77bc0">0.0100281479598650895973532826133123307955</span></p></td></tr></tbody></table></div></template> <div class="flextable-shadow-host" id="b9372206-23b8-4bed-9207-15cf782e2b45"></div> <script> var dest = document.getElementById("b9372206-23b8-4bed-9207-15cf782e2b45"); var template = document.getElementById("09cd7a52-28c3-497b-9d6d-f4f736478fa7"); var caption = template.content.querySelector("caption"); if(caption) { caption.style.cssText = "display:block;text-align:center;"; var newcapt = document.createElement("p"); newcapt.appendChild(caption) dest.parentNode.insertBefore(newcapt, dest.previousSibling); } var fantome = dest.attachShadow({mode: 'open'}); var templateContent = template.content; fantome.appendChild(templateContent); </script> ] .pull-right[ ```r model_parameters(model2, vcov = "HC3") %>% #get corrected SE# robust params flextable() %>% autofit()# robust params ``` <template id="84e0aab9-daef-4821-a8c3-b7b19a95f499"><style> .tabwid table{ border-spacing:0px !important; border-collapse:collapse; line-height:1; margin-left:auto; margin-right:auto; border-width: 0; display: table; margin-top: 1.275em; margin-bottom: 1.275em; border-color: transparent; } .tabwid_left table{ margin-left:0; } .tabwid_right table{ margin-right:0; } .tabwid td { padding: 0; } .tabwid a { text-decoration: none; } .tabwid thead { background-color: transparent; } .tabwid tfoot { background-color: transparent; } .tabwid table tr { background-color: transparent; } .katex-display { margin: 0 0 !important; } </style><div class="tabwid"><style>.cl-fcf78212{}.cl-fcf3412a{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-fcf34dd2{margin:0;text-align:left;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-fcf34ddc{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-fcf379a6{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379c4{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379ce{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379cf{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379d8{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379d9{width:76.2pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379e2{width:249.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379e3{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379ec{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379ed{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379f6{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf379f7{width:76.2pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a00{width:249.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a01{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a02{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a0a{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a0b{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a0c{width:76.2pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a14{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a15{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a16{width:249.9pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a1e{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a1f{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a28{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a29{width:249.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a32{width:76.2pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a33{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a3c{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a3d{width:84.8pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a3e{width:41.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a46{width:78.6pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a47{width:249.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a50{width:59pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a51{width:126.9pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fcf37a5a{width:76.2pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table class='cl-fcf78212'><thead><tr style="overflow-wrap:break-word;"><td class="cl-fcf37a51"><p class="cl-fcf34dd2"><span class="cl-fcf3412a">Parameter</span></p></td><td class="cl-fcf37a3d"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">Coefficient</span></p></td><td class="cl-fcf37a46"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">SE</span></p></td><td class="cl-fcf37a3e"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">CI</span></p></td><td class="cl-fcf37a3d"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">CI_low</span></p></td><td class="cl-fcf37a3d"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">CI_high</span></p></td><td class="cl-fcf37a5a"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">t</span></p></td><td class="cl-fcf37a50"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">df_error</span></p></td><td class="cl-fcf37a47"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">p</span></p></td></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td class="cl-fcf379cf"><p class="cl-fcf34dd2"><span class="cl-fcf3412a">(Intercept)</span></p></td><td class="cl-fcf379a6"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">55.16373592</span></p></td><td class="cl-fcf379ce"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">4.20877887</span></p></td><td class="cl-fcf379d8"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.95</span></p></td><td class="cl-fcf379a6"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">46.87639900</span></p></td><td class="cl-fcf379a6"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">63.45107283</span></p></td><td class="cl-fcf379d9"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">13.106827</span></p></td><td class="cl-fcf379c4"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">262</span></p></td><td class="cl-fcf379e2"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.000000000000000000000000000001603377</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fcf379f6"><p class="cl-fcf34dd2"><span class="cl-fcf3412a">PIL_total</span></p></td><td class="cl-fcf379ec"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">-0.38157775</span></p></td><td class="cl-fcf37a01"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.03597990</span></p></td><td class="cl-fcf379ed"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.95</span></p></td><td class="cl-fcf379ec"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">-0.45242431</span></p></td><td class="cl-fcf379ec"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">-0.31073119</span></p></td><td class="cl-fcf379f7"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">-10.605305</span></p></td><td class="cl-fcf379e3"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">262</span></p></td><td class="cl-fcf37a00"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.000000000000000000000425863763393213</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fcf37a0a"><p class="cl-fcf34dd2"><span class="cl-fcf3412a">AUDIT_TOTAL_NEW</span></p></td><td class="cl-fcf37a0b"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">-0.09210892</span></p></td><td class="cl-fcf37a15"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.08647293</span></p></td><td class="cl-fcf37a02"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.95</span></p></td><td class="cl-fcf37a0b"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">-0.26237929</span></p></td><td class="cl-fcf37a0b"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.07816145</span></p></td><td class="cl-fcf37a0c"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">-1.065176</span></p></td><td class="cl-fcf37a14"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">262</span></p></td><td class="cl-fcf37a16"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.287776789141752753486969140794826671</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fcf37a33"><p class="cl-fcf34dd2"><span class="cl-fcf3412a">DAST_TOTAL_NEW</span></p></td><td class="cl-fcf37a1f"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">1.03415391</span></p></td><td class="cl-fcf37a3c"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.48095976</span></p></td><td class="cl-fcf37a1e"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.95</span></p></td><td class="cl-fcf37a1f"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.08711542</span></p></td><td class="cl-fcf37a1f"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">1.98119239</span></p></td><td class="cl-fcf37a32"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">2.150188</span></p></td><td class="cl-fcf37a28"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">262</span></p></td><td class="cl-fcf37a29"><p class="cl-fcf34ddc"><span class="cl-fcf3412a">0.032455663970932233097776986596727511</span></p></td></tr></tbody></table></div></template> <div class="flextable-shadow-host" id="2728b0f3-9c5a-4494-8d22-6798addb3489"></div> <script> var dest = document.getElementById("2728b0f3-9c5a-4494-8d22-6798addb3489"); var template = document.getElementById("84e0aab9-daef-4821-a8c3-b7b19a95f499"); var caption = template.content.querySelector("caption"); if(caption) { caption.style.cssText = "display:block;text-align:center;"; var newcapt = document.createElement("p"); newcapt.appendChild(caption) dest.parentNode.insertBefore(newcapt, dest.previousSibling); } var fantome = dest.attachShadow({mode: 'open'}); var templateContent = template.content; fantome.appendChild(templateContent); </script> ] --- # Check-in Questions - What the heck is heteroskedasticity? - Assumptions of simple linear model --- # Simple Linear Modeling Assumptions - Normality of residuals - Missingness - Outliers --- # Burning Questions - What the heck is heteroskedasticity? - Assumptions of simple linear model - Difference between `\(\epsilon\)` and residual --- # Errors - Error is basically an unobservable quantity in our model - We use residuals as a proxy --- # Outliers <img src="out.png" width="70%" style="display: block; margin: auto;" /> --- # Outliers: Discrepancy > A data point that is unusual in the context of the least squares model `$$e_i^* = \dfrac{e_i}{S_{E(-i)}\sqrt{1-h_i}}$$` <img src="hdl.png" width="100%" style="display: block; margin: auto;" /> --- # Outliers: Leverage > Leverage measures how far a data point is from the mean `$$h_i = \dfrac{1}{n} + \dfrac{\left(x_i -\overline{x}\right)^2}{\sum_{j=1}^{n}{\left(x_j -\overline{x}\right)^2}} \qquad \text{and}\qquad \overline{h} = \dfrac{k}{n} \qquad \text{and}\qquad \dfrac{1}{n} \leq h_i \leq 1.0$$` <img src="hdl.png" width="100%" style="display: block; margin: auto;" /> --- # Cook's Distance - A measure of how much of an effect a single data point has on the whole model - Often described as leverage + discrepancy (residuals) `$$D_i = \dfrac{e_i^2}{k \times \frac{1}{n}\sum{e_i^2}} \times \dfrac{h_i}{1-h_i}$$` `$$e_i^* = \dfrac{e_i}{S_{E(-i)}\sqrt{1-h_i}}$$` - How do we calculate how much change is bad? <p align="center"> - `\(\frac{4}{N-K-1}\)` --- # Calculate in R ```r augment(model) # in broom package ``` --- # The Impact of Individual Predictors on the Model: Effect Size .pull-left[ - R is the multiple correlation - `\(R^2\)` is the multiple correlation squared - All overlap in Y, used for overall model - `\(A+B+C/(A+B+C+D)\)` ] .pull-right[ <img src="https://raw.githubusercontent.com/doomlab/learnSTATS/master/vignettes/pictures/regression/19.PNG" width="100%" style="display: block; margin: auto;" /> ] --- # Effect Size .pull-left[ - sr is the semi-partial correlations - Unique contribution of IV to `\(R^2\)` for those IVs - Increase in proportion of explained Y variance when X is added to the equation - `\(A/(A+B+C+D)\)` ] .pull-right[ <img src="https://raw.githubusercontent.com/doomlab/learnSTATS/master/vignettes/pictures/regression/19.PNG" width="100%" style="display: block; margin: auto;" /> ] --- # Effect Size .pull-left[ - pr is the partial correlation - Partial correlation asks how much of the Y variance, which is not estimated by the other IVs, is estimated by this variable. - `\(A/(A+D)\)` - Removes the shared variance of the control variable (Say X2) from both Y and X1 - Pr > sr ] .pull-right[ <img src="https://raw.githubusercontent.com/doomlab/learnSTATS/master/vignettes/pictures/regression/19.PNG" width="100%" style="display: block; margin: auto;" /> ] --- # Partial Correlations - We would add these to our other reports: - Meaning: `\(b = -0.38\)`, 95\% CI `\([-0.45, -0.31]\)`, `\(t(262) = -11.28\)`, `\(p < .001\)`, `\(pr^2 = .30\)`` - Alcohol: `\(b = -0.09\)`, 95\% CI `\([-0.28, 0.09]\)`, `\(t(262) = -0.98\)`, `\(p = .328\)`, `\(pr^2 < .01\)`` - Drugs: `\(b = 1.03\)`, 95\% CI `\([0.25, 1.82]\)`, `\(t(262) = 2.59\)`, `\(p = .010\)`, `\(pr^2 < .01\)`` ```r library(ppcor) partials <- pcor(master) partials$estimate^2 #spcor.test (semi-partial) ``` --- # Multiple Regression: Power - We can use the `pwr` library to calculate the required sample size for any particular effect size - First, we need to convert the `\(R^2\)` value to `\(f^2\)`, which is a different effect size, not the ANOVA *F* ```r library(pwr) r2=glance(model2) R2= r2$r.squared f2 <- R2 / (1-R2) R2 ``` ``` ## [1] 0.3586693 ``` ```r f2 ``` ``` ## [1] 0.559258 ``` --- # Multiple Regression: Power - `u` is degrees of freedom for the model, first value in the F-statistic - `v` is degrees of freedom for error, but we are trying to figure out sample size for each condition, so we leave this one blank. - `f2` is the converted effect size. - `sig.level` is our `\(\alpha\)` value - `power` is our power level - The final sample size is *v + k + 1 where k is the predictors* ```r #f2 is cohen f squared pwr.f2.test(u = model2$df[1], v = NULL, f2 = f2, sig.level = .05, power = .80) ``` --- class: middle # Categorical Predictors --- # Modeling Categorical Variables - Today's Dataset - Winter(2016) - Are smell words (e.g., *rancid*) rated as more negative/unpleaseant than taste words (e.g., *sweet*)? - 1 to 9 rating scale ```r library(tidyverse) senses<- read_csv("data/winter_2016_senses_valence.csv") senses_filt <- senses %>% filter(Modality=="Taste" | Modality=="Smell") ``` --- # Linear Model <br> <br> `$$\red{Y_i} = \beta_0 + \beta_1 \blue{X_i} + \green{\varepsilon_i}$$` -- - So far .blue[predictor variable] has been continuous -- - We can also use linear modeling for categorical variables --- # Categorical Variables - Terminology - *Factor*: a variable with a fix set of categories - *Levels*: The individual categories within a factor -- - In our dataset, what is the factor and what are its levels? --- # Linear Modeling and t-tests/ANOVAs What do we do in linear modeling? - Fit a line (least squares method) <img src="More_LM_categorical_files/figure-html/unnamed-chunk-19-1.png" width="100%" style="display: block; margin: auto;" /> --- # Linear Modeling and *t*-tests/ANOVAs Within a t-test/ANOVA framework we want to know if means differ between groups ```r t.test() # test mean differences ``` <img src="More_LM_categorical_files/figure-html/unnamed-chunk-21-1.png" width="60%" style="display: block; margin: auto;" /> --- # Linear Modeling and t-tests/ANOVAs - First, calculate `\(SS_{total}\)` <br> <br> .pull-left[ <img src="More_LM_categorical_files/figure-html/unnamed-chunk-22-1.png" width="100%" style="display: block; margin: auto;" /> ] .pull-left[ <img src="More_LM_categorical_files/figure-html/unnamed-chunk-23-1.png" width="100%" style="display: block; margin: auto;" /> ] --- # Fit a line - Find line using least squares method - Mean is best line fit <img src="More_LM_categorical_files/figure-html/unnamed-chunk-24-1.png" width="100%" style="display: block; margin: auto;" /> --- # Fit a line <img src="More_LM_categorical_files/figure-html/unnamed-chunk-25-1.png" width="100%" style="display: block; margin: auto;" /> --- # Single Line - We have two equations - `\(y = b_0\)` = intercept(mean of smell) - `\(y = b_0\)` = intercept(mean of touch) - How do we get one linear equation? --- class:middle # Dummy Coding/Treatment Coding --- # Dummy Coding/Treatment Coding - R's default system - 0’s and 1’s, with reference level at intercept - R does this automatically (0 = whatever comes first alphabetically) - Smell = 0 - Taste = 1 `$$\operatorname{Val} = \alpha + \beta_{1}(X_i) + \epsilon$$` <p align="center"> `\(X_i\)` = Indicator of group (0 or 1) --- # Dummy Coding/Treatment Coding - Prediction for Smell `\(X_i =0\)` `$$\operatorname{Val} = \alpha + \beta_{1}(\operatorname{Modality}_{\operatorname{Taste}}0) + \epsilon$$` $$ \operatorname{\bar{Y}} = \alpha(Smell_{mean}) $$ - Prediction for Taste `\(X_i =1\)` `$$\operatorname{Val} = \alpha + \beta_{1}(\operatorname{Modality}_{\operatorname{Taste}}1) + \epsilon$$` `$$\operatorname{\bar{Y}{taste}} = \alpha + \beta_{1}(\operatorname{Modality}_{\operatorname{Taste}}1) + \epsilon$$` --- # Dummy Coding By Hand <br> <br> <br> .pull-left[ ```r senses_dum <- senses_filt %>% mutate(mod=ifelse(Modality=="Smell", 0, 1)) ``` ] .pull-right[ <img src="More_LM_categorical_files/figure-html/unnamed-chunk-27-1.png" width="100%" style="display: block; margin: auto;" /> ] --- # Categorical Contrast Coding `$$slope=\frac{\mu_{diff}}{run}$$` .pull-left[ <br> <br> <img src="More_LM_categorical_files/figure-html/unnamed-chunk-28-1.png" width="80%" style="display: block; margin: auto;" /> ] .pull-right[ <img src="twomean.JPG" width="100%" style="display: block; margin: auto;" /> ] --- # Dummy Coded Regression ```r lm(Val ~ Modality, data=senses_filt) ``` -- - Intercept: `\(\bar{Y} = b_0\)`(Smell) = 5.47 - Slope ($b_1$): Valance of taste words are .337 higher - One unit increase (going from 0 to 1; from Smell to Taste) associated with .337 increase in valance scores (mean difference) - Adding intercept and slope together will give us mean valence of taste words --- # Change Reference Level .pull-left[ ```r senses_dum <- senses_filt %>% mutate(mod=factor(Modality)) %>% mutate(mod1=relevel(mod, ref="Taste")) # relevel the var contrasts(senses_dum$mod1) ``` ``` ## Smell ## Taste 0 ## Smell 1 ``` ```r contrasts(senses_dum$mod) ``` ``` ## Taste ## Smell 0 ## Taste 1 ``` ] .pull-right[ ```r lm(Val ~ mod, data=senses_dum) ``` ] --- class:middle # Effects Coding/Sum Coding --- # Effects Coding/Sum Coding - So far the intercept at 0 has referred to a particular baseline or reference level -- - Centering (subtracting mean from each value) changes the intercept to correspond to the overall mean - While mostly done for continuous variables, you can apply centering to categorical variables --- # Effects Coding/Sum Coding (.5, -.5) - Mean of dummy coded variable is = .5 - Subtract .5 from (0, 1) and we get *+ 0.5* and *-0.5* - Y intercept is now the grand mean `$$\frac{\mu_1 + \mu_2}{2}$$` - Slope is still the difference ```r senses_filt_sum <- senses_filt %>% mutate(mod_sum=as.factor(Modality), mod_sum_r = as.factor(Modality)) # add a new var to sum code contrasts(senses_filt_sum$mod_sum) <- c(0.5, -0.5) # change 0 - 1 to +.5 and -.5 ``` --- # Effects Coding Results .pull-left[ ```r # reg regression lm(Val ~ Modality, data=senses_filt) ``` ] .pull-right[ ```r # regression with sum coding (.5 - .5) lm(Val ~ mod_sum, data=senses_filt_sum) ``` ] -- - Intercept is grand mean (mean of means): `\(\hat \beta_0=5.64\)` - Mean of Smell: `\(\hat\beta_0+\hat\beta_1\times .5=5.64-0.33(0.5)=5.47\)` - Mean of Taste: `\(\hat\beta_0+\hat\beta_1\times -.5=5.64 + (-0.33)*-0.5=5.80\)` --- # Default Sum Coding R behavior - +1 and -1 ```r senses_filt_sum <- senses_filt_sum %>% mutate(mod_sum55=ifelse(mod_sum=="Taste", .5, -.5), mod_sum11 = ifelse(mod_sum=="Taste", 1, -1)) # add a new var to sum code (1, -1) ``` --- # Sum Coding (-1 + 1) Interpretation .pull-left[ What does this do to our interpretation? - Intercept is now centered at 0 (grand mean) - Slope rise is still the same (difference between categories) but: - Stepping from one category to another (the run) results in overall change of 2 - Results are halved ] .pull-right[ <br> <br> <img src="More_LM_categorical_files/figure-html/unnamed-chunk-37-1.png" width="100%" style="display: block; margin: auto;" /> ] --- # Sum Coding (+1, -1) Model Results .pull-left[ ```r lm(Val ~ mod_sum55, data=senses_filt_sum) ``` ] .pull-right[ ```r lm(Val ~ mod_sum11, data=senses_filt_sum) ``` -- - Intercept is grand mean: `\(\hat\beta_0\)`=5.64 - Mean of Smell: - Mean of Taste: ] --- # Why -0.5 and +0.5? <img src="contrastcodes.bmp" width="100%" style="display: block; margin: auto;" /> --- # The General Linear F-Test - Can test overall influence for 2 or more levels of a factor - We can think about the hypotheses for the overall test being: - `\(H_0\)`: We cannot predict the dependent variable (over and above a restricted model (only an intercept)) - `\(H_1\)`: We can predict the dependent variable (over and above a model with only an intercept) --- # Restricted Model `$$Y_{ij} = \mu + \epsilon$$` .pull-left[ - Restricted model (Intercept-only): each score `\(Y_{ij}\)` is the result of a single population mean plus random error `$$SS_{error}(R)=\sum(y_i-\bar{y})^2=SS_{total}$$` where: `\(y_i\)` = observed value `\(\bar{y}\)` = mean value ] .pull-right[ <img src="More_LM_categorical_files/figure-html/unnamed-chunk-41-1.png" width="80%" style="display: block; margin: auto;" /> ] --- # Full Model `$$Y_{ij} = \mu_j + \epsilon$$` .pull-left[ - Full model (all predictors/levels): each score `\(Y_ij\)` is the result of a different group mean plus random error `$$SSE(F)=\sum(y_{ij}-\hat{y}_{ij})^2=SSE$$` where: `\(i\)` = Person `\(j\)` = Group `\(y_i\)` = Observed value `\(\hat{y}\)` = Value estimated by regression line ] .pull-right[ <img src="More_LM_categorical_files/figure-html/unnamed-chunk-42-1.png" width="80%" style="display: block; margin: auto;" /> ] --- # F-ratio - F-ratio is measure of signal to noise - Tells us if overall model is significant fit to the data - `\(H_0\)`: We cannot predict the dependent variable (over and above a model with only an intercept) - `\(H_1\)`: We can predict the dependent variable (over and above a model with only an intercept) `$$\begin{aligned} &&df_{R} = N - 1\\ &&df_{F} = N - a\\ &&SSE(R)=SS_{total}\\&&SSE(F)=SS_{error}\end{aligned}$$` --- # F-ratio `$$F = \frac{SS_{R}-SS_{F}/{df_{R}-df_{F}} (p-1)}{SS_{F}/df_F(N-p)} = \frac{MS_{model}}{MS_{error}}$$` - If Full = Restricted , then F=1 - If Full > Restricted, F > 1 - If Full < Restricted, F < 1 *Degrees of freedom: F(a-1, n - a)* --- # Plotting Categorical Effects - Boxplot <img src="More_LM_categorical_files/figure-html/unnamed-chunk-43-1.png" width="100%" style="display: block; margin: auto;" /> --- # Violin Plots .pull-left[ ```r mod=lm(Val ~ Modality, data=senses_filt) means=modelbased::estimate_means(mod) d=ggplot(senses_filt, aes(x = Modality, y = Val)) + # Add base data geom_violin(aes(fill = Modality), color = "white") + geom_jitter2(width = 0.05, alpha = 0.5) + # Add pointrange and line from means geom_line(data = means, aes(y = Mean, group = 1), size = 1) + geom_pointrange( data = means, aes(y = Mean, ymin = CI_low, ymax = CI_high), size = 1, color = "white" ) + # Improve colors scale_fill_material() + theme_modern() ``` ] <br> <br> .pull-right[ <img src="More_LM_categorical_files/figure-html/unnamed-chunk-45-1.png" width="100%" style="display: block; margin: auto;" /> ] --- # Activity Mental Health and Drug Use - CESD: Depressions scores - unemp: 1=employed 0=unemployed ```r d <- read_csv("https://raw.githubusercontent.com/ASKurz/Applied-Longitudinal-Data-Analysis-with-brms-and-the-tidyverse/master/data/unemployment_pp.csv") ``` --- # Activity 1. Change `unemp` variable to a factor with categorical labels 2. Dummy code the unemployment variable 3. Contrast code the unemployment variable 3. Run `lm` on the dummy coded variable 6. Interpret the output 7. Use output to extract the means for each group only using the output 8. Plot the results --- # Linear Models with Multiple Levels - So far we have only been looking at two levels - We easily can extend linear modeling approach to multiple levels - Let's go back to our sense data - Before filtering it down to 2 senses it had 5 senses! ```r senses<- read_csv("data/winter_2016_senses_valence.csv") glimpse(senses) ``` ``` ## Rows: 405 ## Columns: 3 ## $ Word <chr> "abrasive", "absorbent", "aching", "acidic", "acrid", "adhesi… ## $ Modality <chr> "Touch", "Sight", "Touch", "Taste", "Smell", "Touch", "Taste"… ## $ Val <dbl> 5.398113, 5.876667, 5.233370, 5.539592, 5.173947, 5.240000, 5… ``` --- Treatment/Dummy Coding: Multilevel Factors ```r lm(Val~Modality, data=senses) %>% tidy() ```
term
estimate
std.error
statistic
p.value
(Intercept)
5.58
0.0189
295
0
ModalitySmell
-0.109
0.0564
-1.93
0.0549
ModalitySound
-0.174
0.0376
-4.64
4.66e-06
ModalityTaste
0.228
0.0431
5.3
1.96e-07
ModalityTouch
-0.0452
0.0374
-1.21
0.227
- What is going on here? There are only 4 levels, but we actually have 5 levels. --- # Dummy Coding Extension .pull-left[ 1. Create one fewer dummy codes than levels (K (number of levels)-1) 2. Choose one of your levels as baseline and assign all zeros for this level across each dummy code 3. For first dummy code, assign 1 to first group and 0s for rest of levels 4. For the second dummy code, assign 1 to second group and 0s for rest of levels 5. For third dummy code, assign 1 to third group and 0s for rest of levels 6. For fourth dummy code, assign 1 to fourth group and 0s for rest of levels ] .pull-right[ <template id="0a0b2692-a1ee-4f17-ab7c-4fc96296dece"><style> .tabwid table{ border-spacing:0px !important; border-collapse:collapse; line-height:1; margin-left:auto; margin-right:auto; border-width: 0; display: table; margin-top: 1.275em; margin-bottom: 1.275em; border-color: transparent; } .tabwid_left table{ margin-left:0; } .tabwid_right table{ margin-right:0; } .tabwid td { padding: 0; } .tabwid a { text-decoration: none; } .tabwid thead { background-color: transparent; } .tabwid tfoot { background-color: transparent; } .tabwid table tr { background-color: transparent; } .katex-display { margin: 0 0 !important; } </style><div class="tabwid"><style>.cl-fe774e88{}.cl-fe73031e{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-fe730d0a{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-fe732ac4{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fe732ace{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fe732acf{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table class='cl-fe774e88'><thead><tr style="overflow-wrap:break-word;"><td class="cl-fe732acf"><p class="cl-fe730d0a"><span class="cl-fe73031e">2</span></p></td><td class="cl-fe732acf"><p class="cl-fe730d0a"><span class="cl-fe73031e">3</span></p></td><td class="cl-fe732acf"><p class="cl-fe730d0a"><span class="cl-fe73031e">4</span></p></td><td class="cl-fe732acf"><p class="cl-fe730d0a"><span class="cl-fe73031e">5</span></p></td></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">1</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">1</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">1</span></p></td><td class="cl-fe732ac4"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fe732ace"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ace"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ace"><p class="cl-fe730d0a"><span class="cl-fe73031e">0</span></p></td><td class="cl-fe732ace"><p class="cl-fe730d0a"><span class="cl-fe73031e">1</span></p></td></tr></tbody></table></div></template> <div class="flextable-shadow-host" id="79538354-5a60-4d0b-9ab4-be9b695a1fe5"></div> <script> var dest = document.getElementById("79538354-5a60-4d0b-9ab4-be9b695a1fe5"); var template = document.getElementById("0a0b2692-a1ee-4f17-ab7c-4fc96296dece"); var caption = template.content.querySelector("caption"); if(caption) { caption.style.cssText = "display:block;text-align:center;"; var newcapt = document.createElement("p"); newcapt.appendChild(caption) dest.parentNode.insertBefore(newcapt, dest.previousSibling); } var fantome = dest.attachShadow({mode: 'open'}); var templateContent = template.content; fantome.appendChild(templateContent); </script> ] --- # Linear Equation `$$\operatorname{Val} = \alpha + \beta_{1}(\operatorname{Modality}_{\operatorname{Smell}}) + \beta_{2}(\operatorname{Modality}_{\operatorname{Sound}}) + \beta_{3}(\operatorname{Modality}_{\operatorname{Taste}}) + \beta_{4}(\operatorname{Modality}_{\operatorname{Touch}}) + \epsilon$$` <img src="morethree.JPG" width="60%" style="display: block; margin: auto;" /> --- # Hello Again Sums of Squares <img src="ss_aov.bmp" width="40%" style="display: block; margin: auto;" /> --- # The General Linear F-Test - We can think about the hypotheses for the overall test being: `$$H_0: b_1 = 0$$` `$$H_0: \mu_1 = \mu_2 = \mu_3 = \mu_4 = \mu_5$$` `$$H_1: b_1 \neq b_2 \neq b_3 \neq b_4 \neq b_5$$` `$$H_1: \mu_1 \neq \mu_2 \neq \mu_3 \neq \mu_4 \neq \mu_5$$` - *Analysis of Variance (ANOVA)* --- # Restricted Model `$$Y_{ij} = \mu + \epsilon$$` .pull-left[ - Restricted model (Intercept-only): each score `\(Y_{ij}\)` is the result of a single population mean plus random error `$$SS_{error}(R)=\sum(y_i-\bar{y})^2=SS_{total}$$` where: `\(y_i\)` = observed value `\(\bar{y}\)` = mean value ] .pull-right[ <img src="More_LM_categorical_files/figure-html/unnamed-chunk-52-1.png" width="100%" style="display: block; margin: auto;" /> ] --- # Full Model `$$Y_{ij} = \mu_j + \epsilon$$` .pull-left[ - Full model (all predictors/levels): each score `\(Y_ij\)` is the result of a different group mean plus random error `$$SSE(F)=\sum(y_{ij}-\hat{y}_{ij})^2=SSE$$` where: `\(i\)` = Person `\(j\)` = Group `\(y_i\)` = Observed value `\(\hat{y}\)` = Value estimated by regression line ] .pull-right[ <img src="More_LM_categorical_files/figure-html/unnamed-chunk-53-1.png" width="100%" style="display: block; margin: auto;" /> ] --- # F-ratio - F-ratio is measure of signal to noise `$$\begin{aligned} &&df_{R} = N - 1\\ &&df_{F} = N - p\\ &&SSE(R)=SS_{total}\\&&SSE(F)=SS_{error}\end{aligned}$$` --- # F-ratio `$$F = \frac{SS_{R}-SS_{F}/{df_{R}-df_{F}} (p-1)}{SS_{F}/df_F(N-p)} = \frac{MS_{model}}{MS_{error}}$$` - If Full = Restricted , then F=1 - If Full > Restricted, F > 1 - If Full < Restricted, F < 1 *Degrees of freedom: F(p-1, n - p)* --- # ANOVA Table ```r lm(Val~Modality, data=senses) %>% parameters::model_parameters() ```
Parameter
Coefficient
SE
CI
CI_low
CI_high
t
df_error
p
(Intercept)
5.58
0.0189
0.95
5.54
5.62
295
400
0
ModalitySmell
-0.109
0.0564
0.95
-0.22
0.00229
-1.93
400
0.0549
ModalitySound
-0.174
0.0376
0.95
-0.248
-0.101
-4.64
400
4.66e-06
ModalityTaste
0.228
0.0431
0.95
0.144
0.313
5.3
400
1.96e-07
ModalityTouch
-0.0452
0.0374
0.95
-0.119
0.0282
-1.21
400
0.227
--- # ANOVA Table ```r aov1<-aov(Val~ 1, data=senses) aov2 <- aov(Val~Modality, data=senses) #anova(aov1, aov2) compare two models aov(Val~Modality, data=senses) %>% parameters::model_parameters() ```
Parameter
Sum_Squares
df
Mean_Square
F
p
Modality
4.81
4
1.2
17
6.62e-13
Residuals
28.3
400
0.0707
--- # Model Comparison Approach vs Traditional Approach to ANOVA - Traditional formulation of ANOVA asks the same question in a different way: - Is the variability between groups (variance due to differences between groups) greater than expected on the basis of the within-group variability (the variability within a group) observed, and random sampling of group members? - Both use sum of squares - Both use F-statistic - F = `\(\frac{MSR}{MSE}\)` (Same Mean Squared Error on ANOVA table outputs) --- # Post-Hoc Comparisons ```r aov_em=aov(Val~Modality, data=senses) # fit ANOVA aov_em %>% parameters::model_parameters(.) # print out ANOVA table ```
Parameter
Sum_Squares
df
Mean_Square
F
p
Modality
4.81
4
1.2
17
6.62e-13
Residuals
28.3
400
0.0707
- The Modality factor is significant. Now what? --- # Post-Hoc Comparisons - The best package ever created: `emmeans` - Allows one to extract marginal means for the model and also test comparisons of interest --- # Pairwise Tests - Get means and pairwise comparisons .pull-left[ ```r # get pairwise tests between all groups as.data.frame(emmeans::emmeans(aov_em, specs = "Modality")) %>% flextable() ``` <template id="ca771b03-59bd-47ef-a4a2-6e101ab84c56"><style> .tabwid table{ border-spacing:0px !important; border-collapse:collapse; line-height:1; margin-left:auto; margin-right:auto; border-width: 0; display: table; margin-top: 1.275em; margin-bottom: 1.275em; border-color: transparent; } .tabwid_left table{ margin-left:0; } .tabwid_right table{ margin-right:0; } .tabwid td { padding: 0; } .tabwid a { text-decoration: none; } .tabwid thead { background-color: transparent; } .tabwid tfoot { background-color: transparent; } .tabwid table tr { background-color: transparent; } .katex-display { margin: 0 0 !important; } </style><div class="tabwid"><style>.cl-feb827f0{}.cl-feb0c168{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-feb0cc76{margin:0;text-align:left;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-feb0cc80{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-feb0f48a{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-feb0f48b{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-feb0f494{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-feb0f49e{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-feb0f4a8{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-feb0f4a9{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table class='cl-feb827f0'><thead><tr style="overflow-wrap:break-word;"><td class="cl-feb0f4a9"><p class="cl-feb0cc76"><span class="cl-feb0c168">Modality</span></p></td><td class="cl-feb0f4a8"><p class="cl-feb0cc80"><span class="cl-feb0c168">emmean</span></p></td><td class="cl-feb0f4a8"><p class="cl-feb0cc80"><span class="cl-feb0c168">SE</span></p></td><td class="cl-feb0f4a8"><p class="cl-feb0cc80"><span class="cl-feb0c168">df</span></p></td><td class="cl-feb0f4a8"><p class="cl-feb0cc80"><span class="cl-feb0c168">lower.CL</span></p></td><td class="cl-feb0f4a8"><p class="cl-feb0cc80"><span class="cl-feb0c168">upper.CL</span></p></td></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td class="cl-feb0f48b"><p class="cl-feb0cc76"><span class="cl-feb0c168">Sight</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.579663</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">0.01889440</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">400</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.542518</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.616808</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-feb0f48b"><p class="cl-feb0cc76"><span class="cl-feb0c168">Smell</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.471012</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">0.05317357</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">400</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.366477</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.575546</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-feb0f48b"><p class="cl-feb0cc76"><span class="cl-feb0c168">Sound</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.405193</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">0.03248092</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">400</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.341338</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.469047</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-feb0f48b"><p class="cl-feb0cc76"><span class="cl-feb0c168">Taste</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.808124</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">0.03878081</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">400</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.731884</span></p></td><td class="cl-feb0f48a"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.884364</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-feb0f49e"><p class="cl-feb0cc76"><span class="cl-feb0c168">Touch</span></p></td><td class="cl-feb0f494"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.534435</span></p></td><td class="cl-feb0f494"><p class="cl-feb0cc80"><span class="cl-feb0c168">0.03224121</span></p></td><td class="cl-feb0f494"><p class="cl-feb0cc80"><span class="cl-feb0c168">400</span></p></td><td class="cl-feb0f494"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.471052</span></p></td><td class="cl-feb0f494"><p class="cl-feb0cc80"><span class="cl-feb0c168">5.597818</span></p></td></tr></tbody></table></div></template> <div class="flextable-shadow-host" id="ef04ff6b-41a6-4985-99fc-46092ad0f861"></div> <script> var dest = document.getElementById("ef04ff6b-41a6-4985-99fc-46092ad0f861"); var template = document.getElementById("ca771b03-59bd-47ef-a4a2-6e101ab84c56"); var caption = template.content.querySelector("caption"); if(caption) { caption.style.cssText = "display:block;text-align:center;"; var newcapt = document.createElement("p"); newcapt.appendChild(caption) dest.parentNode.insertBefore(newcapt, dest.previousSibling); } var fantome = dest.attachShadow({mode: 'open'}); var templateContent = template.content; fantome.appendChild(templateContent); </script> ] .pull-right[ <template id="0eb24d64-17ad-4a3e-bd4b-b35a1acac90c"><style> .tabwid table{ border-spacing:0px !important; border-collapse:collapse; line-height:1; margin-left:auto; margin-right:auto; border-width: 0; display: table; margin-top: 1.275em; margin-bottom: 1.275em; border-color: transparent; } .tabwid_left table{ margin-left:0; } .tabwid_right table{ margin-right:0; } .tabwid td { padding: 0; } .tabwid a { text-decoration: none; } .tabwid thead { background-color: transparent; } .tabwid tfoot { background-color: transparent; } .tabwid table tr { background-color: transparent; } .katex-display { margin: 0 0 !important; } </style><div class="tabwid"><style>.cl-feda41c8{}.cl-fed63416{font-family:'Helvetica';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-fed64550{margin:0;text-align:left;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-fed6455a{margin:0;text-align:right;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-fed68e70{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fed68e7a{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fed68e84{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fed68e85{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fed68e8e{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-fed68e98{width:54pt;background-color:transparent;vertical-align: middle;border-bottom: 2pt solid rgba(102, 102, 102, 1.00);border-top: 2pt solid rgba(102, 102, 102, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table class='cl-feda41c8'><thead><tr style="overflow-wrap:break-word;"><td class="cl-fed68e8e"><p class="cl-fed64550"><span class="cl-fed63416">contrast</span></p></td><td class="cl-fed68e98"><p class="cl-fed6455a"><span class="cl-fed63416">estimate</span></p></td><td class="cl-fed68e98"><p class="cl-fed6455a"><span class="cl-fed63416">SE</span></p></td><td class="cl-fed68e98"><p class="cl-fed6455a"><span class="cl-fed63416">df</span></p></td><td class="cl-fed68e98"><p class="cl-fed6455a"><span class="cl-fed63416">t.ratio</span></p></td><td class="cl-fed68e98"><p class="cl-fed6455a"><span class="cl-fed63416">p.value</span></p></td></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td class="cl-fed68e7a"><p class="cl-fed64550"><span class="cl-fed63416">Sight - Smell</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.10865148</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.05643072</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">1.925396</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.3055011645361</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fed68e7a"><p class="cl-fed64550"><span class="cl-fed63416">Sight - Sound</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.17447036</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.03757671</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">4.643046</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.0000456942086</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fed68e7a"><p class="cl-fed64550"><span class="cl-fed63416">Sight - Taste</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-0.22846083</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.04313872</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-5.295957</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.0000019440745</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fed68e7a"><p class="cl-fed64550"><span class="cl-fed63416">Sight - Touch</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.04522812</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.03736969</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">1.210289</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.7454337311622</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fed68e7a"><p class="cl-fed64550"><span class="cl-fed63416">Smell - Sound</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.06581888</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.06230922</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">1.056327</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.8286561493660</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fed68e7a"><p class="cl-fed64550"><span class="cl-fed63416">Smell - Taste</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-0.33711231</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.06581321</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-5.122259</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.0000046594174</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fed68e7a"><p class="cl-fed64550"><span class="cl-fed63416">Smell - Touch</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-0.06342336</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.06218459</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-1.019921</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.8461335445944</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fed68e7a"><p class="cl-fed64550"><span class="cl-fed63416">Sound - Taste</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-0.40293120</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.05058618</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-7.965243</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.0000000000000</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fed68e7a"><p class="cl-fed64550"><span class="cl-fed63416">Sound - Touch</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-0.12924225</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.04576577</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">-2.823993</span></p></td><td class="cl-fed68e70"><p class="cl-fed6455a"><span class="cl-fed63416">0.0397092275599</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-fed68e85"><p class="cl-fed64550"><span class="cl-fed63416">Taste - Touch</span></p></td><td class="cl-fed68e84"><p class="cl-fed6455a"><span class="cl-fed63416">0.27368895</span></p></td><td class="cl-fed68e84"><p class="cl-fed6455a"><span class="cl-fed63416">0.05043260</span></p></td><td class="cl-fed68e84"><p class="cl-fed6455a"><span class="cl-fed63416">400</span></p></td><td class="cl-fed68e84"><p class="cl-fed6455a"><span class="cl-fed63416">5.426827</span></p></td><td class="cl-fed68e84"><p class="cl-fed6455a"><span class="cl-fed63416">0.0000009903166</span></p></td></tr></tbody></table></div></template> <div class="flextable-shadow-host" id="111460cd-2c2e-4f37-b9d1-ed1f16d22b55"></div> <script> var dest = document.getElementById("111460cd-2c2e-4f37-b9d1-ed1f16d22b55"); var template = document.getElementById("0eb24d64-17ad-4a3e-bd4b-b35a1acac90c"); var caption = template.content.querySelector("caption"); if(caption) { caption.style.cssText = "display:block;text-align:center;"; var newcapt = document.createElement("p"); newcapt.appendChild(caption) dest.parentNode.insertBefore(newcapt, dest.previousSibling); } var fantome = dest.attachShadow({mode: 'open'}); var templateContent = template.content; fantome.appendChild(templateContent); </script> ] --- # `afex` ANOVA package ```r library(afex) one_fit <- aov_ez("Word", "Val", data = senses, between = c("Modality")) afex_plot(one_fit, x="Modality") ``` <img src="More_LM_categorical_files/figure-html/unnamed-chunk-59-1.png" width="100%" style="display: block; margin: auto;" /> --- # Assumptions - Within linear modeling framework, do normal assumptions checks ```r check_model() ``` <img src="More_LM_categorical_files/figure-html/unnamed-chunk-61-1.png" width="100%" height="50%" style="display: block; margin: auto;" /> --- # Effect Sizes: eta - `\(\eta^2\)` > Interpretation: % of variance explained `$$\eta^2 = \frac{SS_{model}}{SS_{total}}$$` - `\(\eta^2\)` cannot easily be compared between studies, because the total variability in a study ($SS_{total}$) depends on the design of a study, and increases when additional variables are manipulated - .01: Small - .06: Medium - .14: Large --- # Effect Sizes:eta - `\(\eta_p^2\)` > Interpretation: % of variance explained for one effect (partailing out others) `$$\eta_p^2 = \frac{SS_{model}}{SS_{model} + SS_{error}}$$` --- # Effect Sizes: eta - `\(\eta^2_g\)` - Generalized eta-sqaured `$$\frac{SS_{model}}{SS_{model} + SS_{subject} + SS_{error}}$$` --- # Less Biased Effect Size: Omega - `\(\omega^2\)` `$$\omega^2 = \frac{SS_{model} - df_{model}\cdot MS_{error}}{SS_{total} + MS_{error}}$$` - `\(\omega_p^2\)` `$$\frac{df_{model} \times (MS_{model} - MS_{error})}{SS_{model} + (N - df_{model}) \times MS_{error}}$$` - .01: Small - .06: Medium - .14: Large --- # Effect Size: Cohen's f `$$\text{Cohen's} f_p = \sqrt{\frac{\eta^2_p}{1-\eta^2_p}} = \sqrt{\frac{SS_{effect}}{SS_{error}}}$$` - .14: Small - .39: Medium - .59: Large https://imaging.mrc-cbu.cam.ac.uk/statswiki/FAQ/effectSize --- # Caculate ANOVA Effect Size in R ```r cohens_f(aov_em) ```
Parameter
Cohens_f
CI
CI_low
CI_high
Modality
0.413
0.95
0.316
Inf
```r eta_squared(aov_em) ```
Parameter
Eta2
CI
CI_low
CI_high
Modality
0.146
0.95
0.0909
1
```r omega_squared(aov_em) ```
Parameter
Omega2
CI
CI_low
CI_high
Modality
0.137
0.95
0.0832
1
--- # Power - We can also run power analyses for omnibus tests (e.g., number of participants needed to find a sufficiently powered main effect or interaction) - May not sufficiently power one for the smallest desired effect size of interest - Recommendation: Perform on smallest desired effect size (e.g., mean comparison while controlling for multiple corrections) - Often complex tests cannot be performed analytically and you must use numerical methods - Same approach we have already done! --- # Power Analysis: ANOVA - You are planning a reaction-time study involving three groups (k = 3) - Pilot research & data from literature suggest effect size is medium `\(f\)` = .39 - Suppose you want a power of 0.9 - How many subjects do you need in each sample group? --- # Power Analysis: ANOVA ```r library(pwr) pwr.anova.test(k=3,n=NULL,f=.39,sig.level=0.05,power=0.9) ``` ``` ## ## Balanced one-way analysis of variance power calculation ## ## k = 3 ## n = 28.75626 ## f = 0.39 ## sig.level = 0.05 ## power = 0.9 ## ## NOTE: n is number in each group ``` ```r #k = groups #n= sample size #es = cohen's f ``` --- # Superpower - Same RT study - Pilot research & data from literature suggest population means might be 400, 450 and 500 ms with a sample within-group standard deviation of 100 ms - Suppose you want a power of 0.9 - How many subjects do you need in each sample group? --- # Non-Parametric .pull-left[ - Kruskal Wallis Test - Can be used if assumptions are not met - Extension of Mann-Whitney test ```r kruskal.test(Val ~ Modality, data=senses) ``` ``` ## ## Kruskal-Wallis rank sum test ## ## data: Val by Modality ## Kruskal-Wallis chi-squared = 57.815, df = 4, p-value = 8.344e-12 ``` ] .pull-right[ - Welch's F test (W-test) ```r library(onewaytests) welch.test(Val ~ Modality, data = senses) ``` ``` ## ## Welch's Heteroscedastic F Test (alpha = 0.05) ## ------------------------------------------------------------- ## data : Val and Modality ## ## statistic : 13.01914 ## num df : 4 ## denom df : 101.1231 ## p.value : 1.374323e-08 ## ## Result : Difference is statistically significant. ## ------------------------------------------------------------- ``` ]