![]() |
VOOZH | about |
The Wilcoxon signed rank test is a non-parametric method used to compare two related groups. It works well when we have matched data or repeated measurements from the same group and want to see if there is a meaningful difference between them. This test is often used as an alternative to the paired t-test, especially when the data does not follow a normal distribution.
In simple terms, the Wilcoxon test helps us find out if the differences between two sets of related data are likely due to chance or if they suggest a real change.
This test can be divided into two parts:
The one-sample Wilcoxon signed-rank test is a non-parametric alternative to a one-sample t-test , when the data cannot be assumed to be normally distributed. It’s used to determine whether the median of the sample is equal to a known standard value (theoretical value) .
To perform a one-sample Wilcoxon test, R provides a function wilcox.test() that can be used as follow:
Syntax: wilcox.test(x, mu = 0, alternative = "two.sided")
Parameters:
Output:
name weight
1 R_1 27.6
2 R_2 30.6
3 R_3 32.2
4 R_4 25.3
5 R_5 30.9
6 R_6 31.0
7 R_7 28.9
8 R_8 28.9
9 R_9 28.9
10 R_10 28.2
Wilcoxon signed rank test with continuity correction
data: myData$weight
V = 55, p-value = 0.005793
alternative hypothesis: true location is not equal to 25
Since the p-value of the test is 0.005793, which is less than the significance level alpha = 0.05, we can reject the null hypothesis and conclude that the average weight of the rabbit is significantly different from 25g.
To test whether the median is less than 25g,
Output:
Wilcoxon signed rank exact test
data: myData$weight
V = 55, p-value = 0.9979
alternative hypothesis: true location is less than 25
To test whether the median is greater than 25g,
Output:
Wilcoxon signed rank exact test
data: myData$weight
V = 55, p-value = 0.002897
alternative hypothesis: true location is less than 25
The paired samples Wilcoxon test is a non-parametric alternative to paired t-test used to compare paired data. It’s used when you have two related measurements for the same subjects, like before and after a treatment. It compares whether there is a significant shift in the median.
To perform Paired Samples Wilcoxon-test, the R provides a function wilcox.test() that can be used as follow:
Syntax: wilcox.test(x, y, paired = TRUE, alternative = "two.sided")
Parameters:
Output:
Wilcoxon signed rank test
data: before and after
V = 0, p-value = 0.001953
alternative hypothesis: true location shift is not equal to 0
In the above output, the p-value of the test is 0.001953, which is less than the significance level alpha = 0.05. We can conclude that the median weight of the mice before treatment is significantly different from the median weight after treatment with a p-value = 0.001953.
To check if weight before treatment is less than after:
Output:
Wilcoxon signed rank test
data: weight by group
V = 55, p-value = 0.0009766
alternative hypothesis: true location shift is less than 0
To check if weight before treatment is greater than after:
Output:
Wilcoxon signed rank test
data: weight by group
V = 55, p-value = 1
alternative hypothesis: true location shift is greater than 0
In this article, we performed the Wilcoxon Signed Rank Test in R for both one-sample and paired sample scenarios, along with practical examples and interpretation of results.