Provides a pipe-friendly framework to perform Kruskal-Wallis rank sum test. Wrapper around the function kruskal.test().

kruskal_test(data, formula, ...)

Arguments

data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, formula = TP53 ~ cancer_group.

...

other arguments to be passed to the function kruskal.test.

Value

return a data frame with the following columns:

  • .y.: the y variable used in the test.

  • n: sample count.

  • statistic: the kruskal-wallis rank sum statistic used to compute the p-value.

  • p: p-value.

  • method: the statistical test used to compare groups.

Examples

# Load data #::::::::::::::::::::::::::::::::::::::: data("ToothGrowth") df <- ToothGrowth # Kruskal-wallis rank sum test #::::::::::::::::::::::::::::::::::::::::: df %>% kruskal_test(len ~ dose)
#> Warning: `...` must not be empty for ungrouped data frames. #> Did you want `data = everything()`?
#> # A tibble: 1 x 6 #> .y. n statistic df p method #> * <chr> <int> <dbl> <int> <dbl> <chr> #> 1 len 60 40.7 2 0.00000000148 Kruskal-Wallis
# Grouped data df %>% group_by(supp) %>% kruskal_test(len ~ dose)
#> # A tibble: 2 x 7 #> supp .y. n statistic df p method #> * <fct> <chr> <int> <dbl> <int> <dbl> <chr> #> 1 OJ len 30 18.5 2 0.0000958 Kruskal-Wallis #> 2 VC len 30 25.1 2 0.00000359 Kruskal-Wallis