This function produce two-sample t-test (two-tailed with confident interval at 0.95) results for multiple sub-groups and provides with a nice output in a table format. It can also add adjusted p values for multiple comparison issue.

t_test_two_sample(data, x, y, paired = FALSE, p_adjust = "bonferroni")

Arguments

data

A grouped data frame. It should be grouped by the intended sub-groups which you want to do the same t-test.

x

Column name of the variable which contains data values that you want to test (see t.test and details).

y

Column name of the variable which contains data values of group assignments for the test values (see t.test and details).

paired

a logical indicating whether you want a paired t-test.

p_adjust

character indicating which method should be used for adjusting multiple comparisons (see p.adjust and details). The default "bonferroni" corresponds to Bonferroni adjustment.

Value

A data.frame with the t-statistics table consisting of characters. The columns that are always present are: group variable(s), tvalue, df (degrees of freedom), p, and p_adjustmethod(s).

Examples

t_test_two_sample(color_index_two_sample, x = "color_effect", y = "group", paired = TRUE)
#> Warning: The `t_test_two_sample()` function expects a grouped data frame (i.e., from `dplyr::group_by()`). Returning statistics for the overall comparison
#> Warning: `...` must not be empty for ungrouped data frames. #> Did you want `data = everything()`?
#> # A tibble: 1 x 4 #> tvalue df p p_bonferroni #> <dbl> <dbl> <dbl> <dbl> #> 1 4.44 231 0.0000142 0.0000142
# use bonferroni and fdr method for adjusted p values. library(magrittr) color_index_two_sample %>% t_test_two_sample( x = "color_effect", y = "group", paired = TRUE, p_adjust = c("bonferroni","fdr") )
#> Warning: The `t_test_two_sample()` function expects a grouped data frame (i.e., from `dplyr::group_by()`). Returning statistics for the overall comparison
#> Warning: `...` must not be empty for ungrouped data frames. #> Did you want `data = everything()`?
#> # A tibble: 1 x 5 #> tvalue df p p_bonferroni p_fdr #> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 4.44 231 0.0000142 0.0000142 0.0000142