Compute the effect size for Kruskal-Wallis test as the eta
squared based on the H-statistic: eta2[H] = (H - k + 1)/(n - k);
where H is the value obtained in the Kruskal-Wallis test; k is
the number of groups; n is the total number of observations.
The eta-squared estimate assumes values from 0 to 1 and multiplied by 100
indicates the percentage of variance in the dependent variable explained by
the independent variable. The interpretation values commonly in published
litterature are: 0.01- < 0.06 (small effect), 0.06 - < 0.14
(moderate effect) and >= 0.14 (large effect).
Note that eta2[H] is a bias-corrected estimator, so the raw formula can
return a small negative value for a near-null effect (very small H). In
that case the estimate is floored to 0, keeping the reported effect size within
its valid [0, 1] range.
Confidence intervals are calculated by bootstap.
See the Datanovia tutorial Kruskal-Wallis Test in R for a worked walkthrough.
Arguments
- data
a data.frame containing the variables in the formula.
- formula
a formula of the form
x ~ groupwherexis a numeric variable giving the data values andgroupis a factor with one or multiple levels giving the corresponding groups. For example,formula = TP53 ~ cancer_group.- ci
If TRUE, returns confidence intervals by bootstrap. May be slow.
- conf.level
The level for the confidence interval.
- ci.type
The type of confidence interval to use. Can be any of "norm", "basic", "perc", or "bca". Passed to
boot::boot.ci.- nboot
The number of replications to use for bootstrap.
- boot.parallel
The type of parallel operation to be used when computing the bootstrap confidence interval. Allowed values are
"no"(default),"multicore"and"snow". Passed toboot(). Defaults togetOption("boot.parallel", "no"), so it can also be set globally withoptions(boot.parallel = "multicore"). Only used whenci = TRUE.- boot.ncpus
Integer. The number of processes to be used in the parallel bootstrap. Defaults to
getOption("boot.ncpus", 1L). Note thatboot.parallelhas no effect unlessboot.ncpus > 1. Only used whenci = TRUE.- method
the effect-size metric. Either
"eta2"(default) for the bias-corrected eta-squaredeta2[H] = (H - k + 1)/(N - k), or"epsilon2"for the rank epsilon-squaredH/(N - 1)(Tomczak & Tomczak, 2014), which equalseffectsize::rank_epsilon_squared()and is not bias-corrected (so a little larger thaneta2[H]).
Value
return a data frame with some of the following columns:
.y.: the y variable used in the test.n: Sample counts.effsize: estimate of the effect size.magnitude: magnitude of effect size.conf.low,conf.high: lower and upper bound of the effect size confidence interval.
References
Maciej Tomczak and Ewa Tomczak. The need to report effect size estimates revisited. An overview of some recommended measures of effect size. Trends in Sport Sciences. 2014; 1(21):19-25.
http://imaging.mrc-cbu.cam.ac.uk/statswiki/FAQ/effectSize
http://www.psy.gla.ac.uk/~steve/best/effect.html
See also
The Datanovia tutorial: Kruskal-Wallis Test in R.
Examples
# Load data
#:::::::::::::::::::::::::::::::::::::::
data("ToothGrowth")
df <- ToothGrowth
# Kruskal-wallis rank sum test
#:::::::::::::::::::::::::::::::::::::::::
df %>% kruskal_effsize(len ~ dose)
#> # A tibble: 1 × 5
#> .y. n effsize method magnitude
#> * <chr> <int> <dbl> <chr> <ord>
#> 1 len 60 0.678 eta2[H] large
# Grouped data
df %>%
group_by(supp) %>%
kruskal_effsize(len ~ dose)
#> # A tibble: 2 × 6
#> supp .y. n effsize method magnitude
#> * <fct> <chr> <int> <dbl> <chr> <ord>
#> 1 OJ len 30 0.611 eta2[H] large
#> 2 VC len 30 0.855 eta2[H] large
