blog/wilcoxon-test-in-r-how-to-compare-2-groups-under-the-non-normality-assumption/ #65
Replies: 14 comments 4 replies
-
Comment written by Gerald I Cheves on June 08, 2020 01:09:13: What's the difference between the Shapiro-Wilk normality test and the Kolmogorov test for normality? |
Beta Was this translation helpful? Give feedback.
-
Comment written by Antoine Soetewey on June 08, 2020 04:09:03: Good question Gerald. This article discusses the different normality tests. Briefly said, Kolmogorov-Smirnov and Shapiro-Wilk tests both have the same hypotheses (H0: data comes from a normal distribution and H1: data does not come from a normal distribution), but Shapiro-Wilk test is less sensitive to extreme values and more powerful than Kolmogorov-Smirnov test. Hope this helps. Best, |
Beta Was this translation helpful? Give feedback.
-
Hi, ¿why you are not testing for variance and what would be the difference between testing for it or not testing? ¿does it change what is being tested with wilcoxon test? |
Beta Was this translation helpful? Give feedback.
-
Dear Xaira, This is a good question and it is often raised. Here are 3 good articles discussing the concept of equal variances in Wilcoxon test: 1, 2 & 3. See for instance in 1: "If the two distributions have a different shape, the Mann-Whitney U test is used to determine whether there are differences in the distributions of your two groups. However, if the two distributions are the same shape, the Mann-Whitney U test is used to determine whether there are differences in the medians of your two groups." To rephrase it, if you only want to compare the two groups you do not have to test the equality of variances. However, if your goal is to compare medians of the two groups then you will need to make sure that the two distributions have the same shape. So testing for equality of variances will change your interpretation. In this article I don't compare medians, I only compare the groups. This is the reason I don't test for equality of variances. I have added a note regarding this assumption in this section, so thanks for your question. For your information, this is equivalent when using Kruskal-Wallis test to compare 3 groups or more (see this footnote in my article about ANOVA): if you only want to compare the groups you do not need homoscedasticity, but if you want to compare the medians this assumption must be met. Hope this helps. Regards, |
Beta Was this translation helpful? Give feedback.
-
Since you want to compare the groups by determining whether there are differences in the distributions of the two groups, how to inteprete ' Alternative = "less" or "greater" '? |
Beta Was this translation helpful? Give feedback.
-
Hello, Thanks for your question. Indeed in the first place I would like to test whether there are differences in the distribution of the two groups, so I don't specify any alternative and test the following:
However, one may be interested to go further (based on preliminary research or on the research question for instance) by testing whether one group performs better or worse than the other. In this case, the alternative should be specified. If one wants to test whether:
Hope this makes sense; let me know if not. Regards, |
Beta Was this translation helpful? Give feedback.
-
The R document cites "if both x and y are given and paired is FALSE, a Wilcoxon rank sum test (equivalent to the Mann-Whitney test) is carried out. In this case, the null hypothesis is that the distributions of x and y differ by a location shift of mu and the alternative is that they differ by some other location shift (and the one-sided alternative "greater" is that x is shifted to the right of y)." |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reference.
if I understand correctly, it seems to me that x is larger than y, which means (in our case) that group 1 (x) performs better than group 2 (y). Unless you have another interpretation of the documentation? I'd be happy to discuss it. Regards, |
Beta Was this translation helpful? Give feedback.
-
Thanks for your quick reply. |
Beta Was this translation helpful? Give feedback.
-
As far as I understand, the Wilcoxon test is not comparing the means (mu). This is the reason that in this article I wrote:
The Student's t-test is comparing the means:
That being said, both tests allows to compare two groups (with a different process if I may say).
If you don't specify any alternative, it is indeed a two-sided test so you are testing:
But in any case (i.e., with or without specifying an alternative), with the Wilcoxon test you are not using the means, you are rather comparing the distributions of the two groups, so I would not call it a mean test. Hope this helps. I am not completely sure I understand your question so my apologies if I am not answering it. Regards, |
Beta Was this translation helpful? Give feedback.
-
Thanks for a great article. However, to use the Wilcoxon signed-rank test, must data be continuous? |
Beta Was this translation helpful? Give feedback.
-
The score is a sum of different questions. From each question a value from 0-3 can be giving.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the great answer!👏
|
Beta Was this translation helpful? Give feedback.
-
What a nicely written blog! It's very clean and guides the readers step by step, I like it! Notes first (about medians): I know you wrote that comparing medians was NOT the intention for this post, but by this occasion let me only briefly mention two alternatives for medians, just in case :)
Proposals next: And then, there is one brilliant option to compare them with preserved H0 (about means) while relaxing the requirement for normality: the permutation Welch-Satterthwaite t-test. The good-old Welch t-test, which accounts for the unequal variances, + permutation approach (actually, in reality it's just a smaller subset of huge number of permutations) which "makes" the theoretical distribution of the test statistics under true H0, so we can test safely. (PS: and we can also specify the "trim" parameter, which turns the Welch t-test into Yuen-Welch t-test, which accounts also for extreme observations, aka outliers). In R there are multiple packages for doing permutation t-test, but let me call my preferred one: MKinfer. This is my favoruite workhorse for both permutation and bootstrap testing. It does one fantastic thing: it prints both results based on permutations (or bootstrap, depending on choice) AND the ordinary Welch t-test, so we can compare them. Why is it useful? Because this way we can clearly assess how much the violation of normality affected the actual result. If it did not - so if both results are very close to each other, we can safely report the classic Welch t-test without "scaring people" :) with the "permutation" name. Because despite the fact the assumption was violated, it didn't affect the estimation process noticeably. The permutation (Welch, Yuen-Welch) t-test isn't a magic wand - it won't make the inference meaningful if summarizing our data with arithmetic means is just pointless. It will give a technically valid answer to a pointless question. But if only such question makes sense, this is just awesome way to answer it. One needs to remember to save the seed (set.seed()) to be able to replicate the results in future. If you do not mind, I would like also to provide some literature for curious readers, exactly about these topics: 👩🏫 Janssen, A. (2005). Resampling Student's t-type statistics. Annals of the Institute of Statistical Mathematics. 57. 507-529. 10.1007/BF02509237 , https://www.researchgate.net/publication/24052826_Resampling_Student%27s_t-type_statistics 👩🏫 Arnold Janssen, Thorsten Pauls "How do bootstrap and permutation tests work?," The Annals of Statistics, Ann. Statist. 31(3), 768-806, (June 2003), https://projecteuclid.org/journals/annals-of-statistics/volume-31/issue-3/How-do-bootstrap-and-permutation-tests-work/10.1214/aos/1056562462.full 👨🏫 EunYi Chung, Joseph P. Romano "Exact and asymptotically robust permutation tests," The Annals of Statistics, Ann. Statist. 41(2), 484-507, (April 2013), https://projecteuclid.org/journals/annals-of-statistics/volume-41/issue-2/Exact-and-asymptotically-robust-permutation-tests/10.1214/13-AOS1090.full 👨🏫 Noguchi, K., Konietschke, F., Marmolejo-Ramos, F. et al. Permutation tests are robust and powerful at 0.5% and 5% significance levels. (2021). https://link.springer.com/content/pdf/10.3758/s13428-021-01595-5.pdf 👩🏫 Check also: Amro Lubna (2022), Resampling-Based Inference Methods for Repeated Measures Data with Missing Values, https://eldorado.tu-dortmund.de/bitstream/2003/40978/1/Diss.pdf 💡 Huang, Peng et al. “Formulating appropriate statistical hypotheses for treatment comparison in clinical trial design and analysis.” Contemporary clinical trials vol. 39,2 (2014): 294-302, https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4254362/ |
Beta Was this translation helpful? Give feedback.
-
Wilcoxon test in R: how to compare 2 groups under the non-normality assumption - Stats and R
Learn how to do the Wilcoxon test (non-parametric version of the Student's t-test) in R, used to compare 2 groups when the normality assumption is violated
https://statsandr.com/blog/wilcoxon-test-in-r-how-to-compare-2-groups-under-the-non-normality-assumption/
Beta Was this translation helpful? Give feedback.
All reactions