Comparison of 2 samples with a Wilcoxon rank-sum test
“Blah blah blah Flo! You talk nice and pretty, but our data are crappy: we have less than 30 records per sample, and on top of that it is nowhere near a Normal distribution! What should we do then, Big Cheese?!”
Well, first, stop calling me “Big Cheese”, and give me a minute to regroup after this vicious hit to my perfect data world…
Ok, let’s take care of this. In the case of small sample sizes with strange distributions, we need to use a non-parametric test (i.e. that does not make inferences about the parameters of the distribution, such as the mean). One such test is the Wilcoxon rank-sum test (a.k.a. Mann–Whitney U test or Wilcoxon–Mann–Whitney test). This test, rather than comparing the values of the records in two samples, will compare the ranks of those values once sorted all together. Basically, it helps you look at if, on average, values of one sample are higher than the values of the other sample. Instead of comparing the means, we are comparing the medians. Let’s take a look at our size data again:
wilcox.test(men, women)
Wilcoxon rank sum test with continuity correction
data: men and women
W = 74.5, p-value = 0.00243
alternative hypothesis: true location shift is not equal to 0
Warning message:
In wilcox.test.default(men, women) : cannot compute exact p-value with ties
(Noticed how the formulation to call the test is similar? This is actually a pattern that is quite common among statistical tests in R)
Once again, we detect the difference between the 2 groups. Concerning the error message, do not worry, it simply indicates that the value of P could not be exactly calculated because some values are the same in our two samples, leading to ties in the rank assigned to each record.
Comparison of 2 samples with a Wilcoxon signed-rank test for paired data
As previously mentioned with the t-test, you can… no, you should use a paired test when your data are paired! In this case, the test is called a Wilcoxon signed-rank test.
No detection of an effect if pairing is not considered:
wilcox.test(IQbefore,IQafter)
Wilcoxon rank sum test with continuity correction
data: IQbefore and IQafter
W = 37.5, p-value = 0.5992
alternative hypothesis: true location shift is not equal to 0
Warning message:
In wilcox.test.default(IQbefore, IQafter) :
cannot compute exact p-value with ties
But magic happens as soon as we take the pairing into account:
wilcox.test(IQbefore,IQafter, paired=T)
Wilcoxon signed rank test with continuity correction
data: IQbefore and IQafter
V = 36, p-value = 0.01368
alternative hypothesis: true location shift is not equal to 0
Warning message:
In wilcox.test.default(IQbefore, IQafter, paired = T) :
cannot compute exact p-value with ties
INTRODUCTION
No, don't run away! It will be fine. Stats are cool.
KRUSKAL-WALLIS RANK SUM TEST
Comparing more than two samples with a non-parametric test
FISHER’S EXACT TEST
Comparing several observed distribution
STUDENT’S T-TESTS
Comparing the mean of two samples
BINOMIAL TEST
Comparing observed percentages to theoretical probabilities
CORRELATION AND REGRESSION
Correlation, regression and GLM!
ANOVA
Comparing the mean of more than two samples
CHI SQUARE TEST
*cue "Ride of the Valkyries"
CONCLUSION
After this dreadful interlude, let's make some art!