Skip to content

Instantly share code, notes, and snippets.

@jirilukavsky
Created February 15, 2018 09:58
Show Gist options
  • Save jirilukavsky/504085ae9781e1a356cecaeb82626ec5 to your computer and use it in GitHub Desktop.
Save jirilukavsky/504085ae9781e1a356cecaeb82626ec5 to your computer and use it in GitHub Desktop.
How to report effect size in Wilcoxon signed-rank test
# How to report effect size in Wilcoxon signed-rank test
# links
# [1] https://en.wikipedia.org/wiki/Wilcoxon_signed-rank_test
# [2] https://stats.stackexchange.com/questions/229760/wilcoxon-signed-rank-test-in-r/229761
# [3] https://stats.stackexchange.com/questions/41620/output-of-one-tailed-wilcoxon-sign-rank-test-in-r
# [4] https://stats.stackexchange.com/questions/133077/effect-size-to-wilcoxon-signed-rank-test
# [5] Acion, L., Peterson, J. J., Temple, S., & Arndt, S. (2006). Probabilistic index: an intuitive non-parametric approach to measuring the size of treatment effects. Statistics in Medicine, 25(4), 591–602. https://doi.org/10.1002/sim.2256
# How Wilcoxon signed-rank test works + what it reports
# example from Wikipedia [1, 2]
after = c(125, 115, 130, 140, 140, 115, 140, 125, 140, 135)
before = c(110, 122, 125, 120, 140, 124, 123, 137, 135, 145)
sgn = sign(after - before)
abs_dif = abs(after - before)
d = data.frame(after, before, sgn, abs_dif)
d$rank = rank(replace(abs_dif, abs_dif == 0, NA), na="keep")
d$multi = d$sgn * d$rank
d
(W=abs(sum(d$multi, na.rm = T)))
# W = 9
wilcox.test(d$before, d$after, paired = T, alternative = "two.sided", correct = F)
# V = 18
# [2] R reports the V-statistic, which is the sum of the positive ranks.
# it can be replicated with:
sum(d$rank[d$sgn < 0], na.rm = T)
# observation (!):
# wilcox.test(A, B, paired = T) will give a different result from wilcox.test(B, A, paired = T)
# Conclusion:
# For non-parametric tests, it has been recommended [5] to use P(X>Y) meaning
# "probability that the response of a patient given the new treatment (X) is better than
# the one for a randomly chosen patient given the old or no treatment (Y)".
# There are several ways how to calculate P(X>Y) from two-sample non-parametric tests (see [5]).
# For one-sample test (Wilcoxon signed-rank test) the best equivalent (to our knowledge, see [4]) is to
# report percentages of improved/unchanged/worse - as this method retains the clarity of P(X>Y) reporting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment