Function to run t-test on multiple variables across multiple grouping variables.

grouped_ttest(
  data,
  dep.vars,
  indep.vars,
  grouping.vars,
  paired = FALSE,
  var.equal = FALSE
)

Arguments

data

Dataframe from which variables are to be taken.

dep.vars

List dependent variables for a t-test (y in y ~ x).

indep.vars

List independent variables for a t-test (x in y ~ x).

grouping.vars

List of grouping variables.

paired

A logical indicating whether you want a paired t-test (Default: paired = FALSE; independent t-test, i.e.).

var.equal

A logical variable indicating whether to treat the two variances as being equal. If TRUE, then the pooled variance is used to estimate the variance otherwise the Welch (or Satterthwaite) approximation to the degrees of freedom is used (Default: var.equal = FALSE; Welch's t-test, i.e.).

Value

A tibble dataframe with tidy results from t-test analyses.

Examples

# for reproducibility set.seed(123) groupedstats::grouped_ttest( data = dplyr::filter(.data = ggplot2::diamonds, color == "E" | color == "J"), dep.vars = c(carat, price, depth), indep.vars = color, grouping.vars = clarity, paired = FALSE, var.equal = FALSE )
#> # A tibble: 24 x 10 #> clarity formula method t.test estimate conf.low conf.high parameter p.value #> <ord> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 SI2 carat … Welch… -18.0 -5.03e-1 -5.58e-1 -4.48e-1 634. 9.24e- 59 #> 2 SI1 carat … Welch… -22.1 -4.62e-1 -5.03e-1 -4.20e-1 948. 2.47e- 87 #> 3 VS1 carat … Welch… -16.8 -4.44e-1 -4.96e-1 -3.92e-1 663. 2.91e- 53 #> 4 VVS2 carat … Welch… -12.0 -5.53e-1 -6.44e-1 -4.61e-1 140. 3.81e- 23 #> 5 VS2 carat … Welch… -24.6 -5.42e-1 -5.86e-1 -4.99e-1 856. 1.51e-101 #> 6 I1 carat … Welch… -4.48 -6.44e-1 -9.32e-1 -3.57e-1 60.6 3.34e- 5 #> 7 VVS1 carat … Welch… -6.53 -4.17e-1 -5.45e-1 -2.90e-1 76.1 6.68e- 9 #> 8 IF carat … Welch… -2.38 -1.98e-1 -3.64e-1 -3.18e-2 60.1 2.03e- 2 #> 9 SI2 price … Welch… -10.6 -2.35e+3 -2.78e+3 -1.91e+3 676. 2.02e- 24 #> 10 SI1 price … Welch… -12.6 -2.02e+3 -2.34e+3 -1.71e+3 1031. 5.75e- 34 #> # … with 14 more rows, and 1 more variable: significance <chr>