One-Sample Wilcoxon Signed Rank Test
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 i.e. a theoretical value. In R Language one can perform this test very easily.
Implementation in R
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:
- x: a numeric vector containing your data values
- mu: the theoretical mean/median value. Default is 0 but you can change it.
- alternative: the alternative hypothesis. Allowed value is one of “two.sided” (default), “greater” or “less”.
Example: Here, let’s use an example data set containing the weight of 10 rabbits. Let’s know if the median weight of the rabbit differs from 25g?
R
# R program to illustrate # one-sample Wilcoxon signed-rank test # The data set set.seed (1234) myData = data.frame ( name = paste0 ( rep ( "R_" , 10), 1:10), weight = round ( rnorm (10, 30, 2), 1) ) # Print the data print (myData) # One-sample wilcoxon test result = wilcox.test (myData$weight, mu = 25) # Printing the results print (result) |
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
In the above output, the p-value of the test is 0.005793, which is less than the significance level alpha = 0.05. So we can reject the null hypothesis and conclude that the average weight of the rabbit is significantly different from 25g with a p-value = 0.005793.
If one wants to test whether the median weight of the rabbit is less than 25g (one-tailed test), then the code will be:
R
# R program to illustrate # one-sample Wilcoxon signed-rank test # The data set set.seed (1234) myData = data.frame ( name = paste0 ( rep ( "R_" , 10), 1:10), weight = round ( rnorm (10, 30, 2), 1) ) # One-sample wilcoxon test wilcox.test (myData$weight, mu = 25, alternative = "less" ) # Printing the results print (result) |
Output:
Wilcoxon signed rank exact test data: myData$weight V = 55, p-value = 1 alternative hypothesis: true location is less than 25
Or, If one wants to test whether the median weight of the rabbit is greater than 25g (one-tailed test), then the code will be:
R
# R program to illustrate # one-sample Wilcoxon sign-rank test # The data set set.seed (1234) myData = data.frame ( name = paste0 ( rep ( "R_" , 10), 1:10), weight = round ( rnorm (10, 30, 2), 1) ) # One-sample wilcoxon test wilcox.test (myData$weight, mu = 25, alternative = "greater" ) # Printing the results print (result) |
Output:
Wilcoxon signed rank exact test data: myData$weight V = 55, p-value = 1 alternative hypothesis: true location is less than 25
Wilcoxon Signed Rank Test in R Programming
The Wilcoxon signed-rank test is a non-parametric statistical hypothesis test used to compare two related samples, matched samples, or repeated measurements on a single sample to estimate whether their population means ranks differ e.g. it is a paired difference test. It can be applied as an alternative to the paired Student’s t-test also known as “t-test for matched pairs” or “t-test for dependent samples” when the distribution of the difference between the two samples’ means cannot be assumed to be normally distributed. A Wilcoxon signed-rank test is a nonparametric test that can be used to determine whether two dependent samples were selected from populations having the same distribution.