How to do a Wilcoxon signed-rank test (in R)
Task
Assume we a sample of data,
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 for matched pairs
Solution
We’re going to use fake data for illustrative purposes,
but you can replace our fake data with your real data.
Say our sample,
1
2
# Replace the next line with your data
sample <- c(19, 4, 23, 16, 1, 8, 30, 25, 13)
We choose a value,
Two-tailed test
To test the null hypothesis
1
2
a <- 10
wilcox.test(sample, mu = a, alternative = "two.sided")
Warning message in wilcox.test.default(sample, mu = a, alternative = "two.sided"):
“cannot compute exact p-value with ties”
Wilcoxon signed rank test with continuity correction
data: sample
V = 35, p-value = 0.1544
alternative hypothesis: true location is not equal to 10
Our p-value, 0.1544, is greater than
Right-tailed test
To test the null hypothesis
1
wilcox.test(sample, mu = a, alternative = "less")
Warning message in wilcox.test.default(sample, mu = a, alternative = "less"):
“cannot compute exact p-value with ties”
Wilcoxon signed rank test with continuity correction
data: sample
V = 35, p-value = 0.9386
alternative hypothesis: true location is less than 10
Our p-value, 0.9386, is greater than
Left-tailed test
To test the null hypothesis
1
wilcox.test(sample, mu = a, alternative = "greater")
Warning message in wilcox.test.default(sample, mu = a, alternative = "greater"):
“cannot compute exact p-value with ties”
Wilcoxon signed rank test with continuity correction
data: sample
V = 35, p-value = 0.0772
alternative hypothesis: true location is greater than 10
Our p-value, 0.0772, 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)