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 #> <ord> <chr> <chr> <dbl> <dbl> <dbl> #> 1 SI2 carat ~ color Welch Two Sample t-test -18.0 -0.503 -0.558 #> 2 SI1 carat ~ color Welch Two Sample t-test -22.1 -0.462 -0.503 #> 3 VS1 carat ~ color Welch Two Sample t-test -16.8 -0.444 -0.496 #> 4 VVS2 carat ~ color Welch Two Sample t-test -12.0 -0.553 -0.644 #> 5 VS2 carat ~ color Welch Two Sample t-test -24.6 -0.542 -0.586 #> 6 I1 carat ~ color Welch Two Sample t-test -4.48 -0.644 -0.932 #> 7 VVS1 carat ~ color Welch Two Sample t-test -6.53 -0.417 -0.545 #> 8 IF carat ~ color Welch Two Sample t-test -2.38 -0.198 -0.364 #> 9 SI2 price ~ color Welch Two Sample t-test -10.6 -2347. -2782. #> 10 SI1 price ~ color Welch Two Sample t-test -12.6 -2024. -2339. #> conf.high parameter p.value significance #> <dbl> <dbl> <dbl> <chr> #> 1 -0.448 634. 9.24e- 59 *** #> 2 -0.420 948. 2.47e- 87 *** #> 3 -0.392 663. 2.91e- 53 *** #> 4 -0.461 140. 3.81e- 23 *** #> 5 -0.499 856. 1.51e-101 *** #> 6 -0.357 60.6 3.34e- 5 *** #> 7 -0.290 76.1 6.68e- 9 *** #> 8 -0.0318 60.1 2.03e- 2 * #> 9 -1913. 676. 2.02e- 24 *** #> 10 -1709. 1031. 5.75e- 34 *** #> # ... with 14 more rows