Compute Wilcoxon effect size (r) for:
one-sample test (Wilcoxon one-sample signed-rank test);
paired two-samples test (Wilcoxon two-sample paired signed-rank test) and
independent two-samples test ( Mann-Whitney, two-sample rank-sum test).
It can also returns confidence intervals by bootstap.
The effect size r is calculated as Z statistic divided by
square root of the sample size (N) (\(Z/\sqrt{N}\)). The Z value is
extracted from either coin::wilcoxsign_test() (case of one- or
paired-samples test) or coin::wilcox_test() (case of independent
two-samples test).
Here, N is the number of independent observations contributing to the
test: the total sample size for the independent two-samples test, and the
number of pairs (equivalently, the number of difference scores) for
the one-sample and paired tests. This is because the paired test reduces to a
one-sample signed-rank test on the pairwise differences, so each pair counts
once. This convention matches the default of
rcompanion::wilcoxonPairedR() (its cases = TRUE setting).
Some references instead define N as the total number of observations,
i.e. twice the number of pairs (Field, 2012; Tomczak & Tomczak, 2014), which
yields a smaller r. If you need that convention for a paired test,
divide the reported r (or the Z) by \(\sqrt 2\); it is also
available via rcompanion::wilcoxonPairedR(..., cases = FALSE).
The r value varies from 0 to close to 1. The interpretation values
for r commonly in published litterature and on the internet are: 0.10
- < 0.3 (small effect), 0.30 - < 0.5 (moderate effect) and >=
0.5 (large effect).
See the Datanovia tutorial Wilcoxon Test in R for a worked walkthrough.
wilcox_effsize(
data,
formula,
comparisons = NULL,
ref.group = NULL,
paired = FALSE,
alternative = "two.sided",
mu = 0,
ci = FALSE,
conf.level = 0.95,
ci.type = "perc",
nboot = 1000,
detailed = FALSE,
...,
boot.parallel = getOption("boot.parallel", "no"),
boot.ncpus = getOption("boot.ncpus", 1L),
method = c("r", "rank_biserial")
)return a data frame with some of the following columns:
.y.: the y variable used in the test.
group1,group2: the compared groups in the pairwise tests.
n,n1,n2: Sample counts.
effsize: estimate of the effect
size (r value).
magnitude: magnitude of effect size.
conf.low,conf.high: lower and upper bound of the effect size
confidence interval.
statistic: the Z statistic and
p: the p-value (only when detailed = TRUE).
a data.frame containing the variables in the 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.
A list of length-2 vectors specifying the groups of
interest to be compared. For example to compare groups "A" vs "B" and "B" vs
"C", the argument is as follow: comparisons = list(c("A", "B"), c("B",
"C"))
a character string specifying the reference group. If specified, for a given grouping variable, each of the group levels will be compared to the reference group (i.e. control group).
If ref.group = "all", pairwise two sample tests are performed for
comparing each grouping variable levels against all (i.e. basemean).
a logical indicating whether you want a paired test.
a character string specifying the alternative
hypothesis, must be one of "two.sided" (default),
"greater" or "less". You can specify just the initial
letter.
a number specifying an optional parameter used to form the null hypothesis.
If TRUE, returns confidence intervals by bootstrap. May be slow.
The level for the confidence interval.
The type of confidence interval to use. Can be any of "norm",
"basic", "perc", or "bca". Passed to boot::boot.ci.
The number of replications to use for bootstrap.
logical value. Default is FALSE. If TRUE, and
method = "r", the output additionally includes the Z
statistic (extracted from the coin package and used to compute
r = Z/sqrt(N)), the p-value (p) and the test
method/alternative, so the effect size and the underlying Z are
reported together in one data frame. The rank-biserial metric
(method = "rank_biserial") has no underlying Z, so those extra
columns are not meaningful for it.
Additional arguments passed to the functions
coin::wilcoxsign_test() (case of one- or paired-samples test) or
coin::wilcox_test() (case of independent two-samples test).
The type of parallel operation to be used when computing
the bootstrap confidence interval. Allowed values are "no" (default),
"multicore" and "snow". Passed to boot().
Defaults to getOption("boot.parallel", "no"), so it can also be set
globally with options(boot.parallel = "multicore"). Only used when
ci = TRUE.
Integer. The number of processes to be used in the parallel
bootstrap. Defaults to getOption("boot.ncpus", 1L). Note that
boot.parallel has no effect unless boot.ncpus > 1. Only used
when ci = TRUE.
the effect-size metric. Either "r" (default) for the
rank correlation r = Z / sqrt(N), or "rank_biserial" for the
rank-biserial correlation --- Cliff's delta for an independent-samples test
(equal to cliff_delta()) or the matched-pairs rank-biserial for
a paired test, both equal to effectsize::rank_biserial(). The
independent-samples case is labelled with the Romano et al. magnitude
thresholds (those thresholds define Cliff's delta); the paired case carries
no magnitude (NA), because no threshold set is calibrated for
the matched-pairs rank-biserial. The confidence interval (ci = TRUE)
is a percentile bootstrap.
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.
The Datanovia tutorial: Wilcoxon Test in R.
if(require("coin")){
# One-sample Wilcoxon test effect size
ToothGrowth %>% wilcox_effsize(len ~ 1, mu = 0)
# Independent two-samples wilcoxon effect size
ToothGrowth %>% wilcox_effsize(len ~ supp)
# Paired-samples wilcoxon effect size
ToothGrowth %>% wilcox_effsize(len ~ supp, paired = TRUE)
# Pairwise comparisons
ToothGrowth %>% wilcox_effsize(len ~ dose)
# Grouped data
ToothGrowth %>%
group_by(supp) %>%
wilcox_effsize(len ~ dose)
}
Run the code above in your browser using DataLab