class: center, middle, inverse, title-slide # How to t test ### Peter Higgins --- ### We will start with the tidy version from the {infer} package: t_test() #### Notice that you have to state the order of the two levels of your grouping variable --- count: false Tidy version from the {infer} package .panel1-ttest1-auto[ ```r *prostate ``` ] .panel2-ttest1-auto[ ``` # A tibble: 316 x 20 RBC.Age.Group Median.RBC.Age Age AA FamHx PVol TVol T.Stage bGS <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 3 25 72.1 0 0 54 3 1 3 2 3 25 73.6 0 0 43.2 3 2 2 3 3 25 67.5 0 0 103. 1 1 3 4 2 15 65.8 0 0 46 1 1 1 5 2 15 63.2 0 0 60 2 1 2 6 3 25 65.4 0 0 45.9 2 1 1 7 3 25 65.5 1 0 42.6 2 1 1 8 1 10 67.1 0 0 40.7 3 1 1 9 1 10 63.9 0 0 45 2 1 1 10 2 15 63 1 0 67.6 2 1 2 # … with 306 more rows, and 11 more variables: `BN+` <dbl>, # OrganConfined <dbl>, PreopPSA <dbl>, PreopTherapy <dbl>, Units <dbl>, # sGS <dbl>, AnyAdjTherapy <dbl>, AdjRadTherapy <dbl>, Recurrence <dbl>, # Censor <dbl>, TimeToRecurrence <dbl> ``` ] --- count: false Tidy version from the {infer} package .panel1-ttest1-auto[ ```r prostate %>% * t_test(TVol ~ AA, * order = c("0", "1")) ``` ] .panel2-ttest1-auto[ ``` # A tibble: 1 x 6 statistic t_df p_value alternative lower_ci upper_ci <dbl> <dbl> <dbl> <chr> <dbl> <dbl> 1 -0.683 79.2 0.496 two.sided -0.271 0.132 ``` ] --- count: false Tidy version from the {infer} package .panel1-ttest1-auto[ ```r prostate %>% t_test(TVol ~ AA, order = c("0", "1")) # Interpreting the results # The t statistic is first # followed by degrees of freedom # then the p value # the default alternative: two.sided # then the confidence bounds # output is a tibble so that it is # easy to use these results ``` ] .panel2-ttest1-auto[ ``` # A tibble: 1 x 6 statistic t_df p_value alternative lower_ci upper_ci <dbl> <dbl> <dbl> <chr> <dbl> <dbl> 1 -0.683 79.2 0.496 two.sided -0.271 0.132 ``` ] <style> .panel1-ttest1-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-ttest1-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-ttest1-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ### Now we will use the baseR version: t.test() #### Notice that you have to use `data = .` #### It is not quite as pipe-friendly #### But you do not have to specify the order of the two levels. --- count: false Base R Version .panel1-ttest2-auto[ ```r *prostate ``` ] .panel2-ttest2-auto[ ``` # A tibble: 316 x 20 RBC.Age.Group Median.RBC.Age Age AA FamHx PVol TVol T.Stage bGS <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 3 25 72.1 0 0 54 3 1 3 2 3 25 73.6 0 0 43.2 3 2 2 3 3 25 67.5 0 0 103. 1 1 3 4 2 15 65.8 0 0 46 1 1 1 5 2 15 63.2 0 0 60 2 1 2 6 3 25 65.4 0 0 45.9 2 1 1 7 3 25 65.5 1 0 42.6 2 1 1 8 1 10 67.1 0 0 40.7 3 1 1 9 1 10 63.9 0 0 45 2 1 1 10 2 15 63 1 0 67.6 2 1 2 # … with 306 more rows, and 11 more variables: `BN+` <dbl>, # OrganConfined <dbl>, PreopPSA <dbl>, PreopTherapy <dbl>, Units <dbl>, # sGS <dbl>, AnyAdjTherapy <dbl>, AdjRadTherapy <dbl>, Recurrence <dbl>, # Censor <dbl>, TimeToRecurrence <dbl> ``` ] --- count: false Base R Version .panel1-ttest2-auto[ ```r prostate %>% * t.test(TVol ~ AA, data = .) ``` ] .panel2-ttest2-auto[ ``` Welch Two Sample t-test data: TVol by AA t = -0.6833, df = 79.184, p-value = 0.4964 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -0.2708947 0.1324320 sample estimates: mean in group 0 mean in group 1 2.081712 2.150943 ``` ] --- count: false Base R Version .panel1-ttest2-auto[ ```r prostate %>% t.test(TVol ~ AA, data = .) # Interpreting the results # The t statistic is first # followed by degrees of freedom # then the p value # then the alternative hypothesis # then the confidence bounds # then the mean mpg for each group ``` ] .panel2-ttest2-auto[ ``` Welch Two Sample t-test data: TVol by AA t = -0.6833, df = 79.184, p-value = 0.4964 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -0.2708947 0.1324320 sample estimates: mean in group 0 mean in group 1 2.081712 2.150943 ``` ] <style> .panel1-ttest2-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-ttest2-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-ttest2-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- <style type="text/css"> .remark-code{line-height: 1.5; font-size: 80%} </style> ### Which version of the t test do you like better? Discuss.