How to do a Wilcoxon signed-rank test for matched pairs (in R)
Task
Assume we have two samples of data that come in matched pairs,
Consider measuring the difference in each pair,
Related tasks:
- How to do a Kruskal-Wallis test
- How to do a Wilcoxon rank-sum test
- How to do a Wilcoxon signed-rank test
Solution
The method we will use is equivalent to subtracting the two samples and then performing the signed-rank test. See how to do a Wilcoxon signed-rank test to compare the two methods.
We’re going to use fake data for illustrative purposes, but you can replace our fake data with your real data.
1
2
3
# Replace sample1 and sample2 with your data
sample1 <- c(156, 133, 90, 176, 119, 120, 40, 52, 167, 80)
sample2 <- c(45, 36, 78, 54, 12, 25, 39, 48, 52, 70)
We choose a value,
Two-tailed test
To test the null hypothesis
1
wilcox.test(sample1, sample2, alternative = "two.sided", mu = 0, paired = TRUE)
Wilcoxon signed rank exact test
data: sample1 and sample2
V = 55, p-value = 0.001953
alternative hypothesis: true location shift is not equal to 0
Our p-value, 0.00195, is less than
Right-tailed test
To test the null hypothesis
1
wilcox.test(sample1, sample2, alternative = "greater", mu = 0, paired = TRUE)
Wilcoxon signed rank exact test
data: sample1 and sample2
V = 55, p-value = 0.0009766
alternative hypothesis: true location shift is greater than 0
Our p-value, 0.0009766, is less than
Left-tailed test
To test the null hypothesis
1
wilcox.test(sample1, sample2, alternative = "less", mu = 0, paired = TRUE)
Wilcoxon signed rank exact test
data: sample1 and sample2
V = 55, p-value = 1
alternative hypothesis: true location shift is less than 0
Our p-value, 1.0, is greater than
NOTE: If there are ties in the data and there are fewer than 50 observations in
each sample, then R will compute a
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Contributed by Elizabeth Czarniak (CZARNIA_ELIZ@bentley.edu)