Nonparametric methods: The Wilcoxon rank-sum test (2)
Our Wilcoxon rank-sum test is the nonparametric equivalent of the independent t test. It actually calculates the sum of the ranks for both the IPA and the wheat beer group. As these beers are rated on a scale from 1 to 5, we regard a score of 5 as the highest possible score and a score of 1 as the lowest possible score. The largest possible difference score thus is 4.
Above are displayed the scores of our two groups. Each score is ranked. In case of a tie in rating, the average rank is taken. In R, you can do a Wilcoxon rank-sum test with the function wilcox.test()
. You can give this function two different vectors with scores. Alternatively, you can use the formula interface when you are doing a rank-sum test. In this formula interface you specify your dependent variable ~ your independent variable, like so: wilcox.test(dependent_variable ~ independent_variable)
. If we would use this test on the data a provided in the table and we presume that this data is contained in a dataframe beer_data
, we could do so in the following way: wilcox.test(beer_data$rating ~ beer_data$group)
. We can also specify the alternative parameter. By default this is set to "two.sided" meaning that we are doing a two-sided test. If you want to check whether you first group is greater than your second group, you change this to "greater".
This exercise is part of the course
Inferential Statistics
Exercise instructions
- There is a dataframe
beer_data
available in your console. It contains two vectors:rating
andgroup
. Peform a Wilcoxon rank-sum test using the functionwilcox.test()
. You actually want to test the hypothesis whether the IPA group experienced greater satisfaction than the wheat beer group. - Assign your conclusion to the variable
conclusion
. Is the null hypothesis that the IPA group is equally satisfied as the wheat beer group rejected? Assign either "rejected" or "accepted" to the variableconclusion
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# do a Wilcoxon rank-sum test
# assign your conclusion to the variable conclusion