Time commitment
5 - 10 minutes
Video
Transcript
The one sample t-test is the parametric statistic; it assumes normality. If you have broken that assumption, if you had a statistically significant Shapiro-Wilk statistic, that means you can't use the one sample t-test, you'd have to use something else. That's “something else” that you can use is the Wilcoxon signed-rank test. A Wilcoxon signed-rank test is used to determine whether the median – not the mean, the median – of a single continuous variable differs from a pre-specified constant. This test is non-parametric, which means it does not assume normality. And I've left you some resources in the R code to help you run this test. As we've already mentioned, every test has certain assumptions that must be met in order for the results of the test to be valid.
Assumption one for the Wilcoxon signed-rank test is that you have one continuous or ordinal value. We haven't talked too much about ordinal values yet. We've talked a lot about continuous values; a lot of statistics that are parametric require continuous variables or the continuous data type. So an ordinal variable…let's say, for example, you wanted to know what size of drink different people wanted. “1” could be a small drink, “2” could be a medium drink, “3” could be a large drink. That has a certain order, it has to go 1-2-3 or 3-2-1. It doesn't make sense to say 2-1-3 (medium, small, large). So I've left you some code for if you're dealing with an ordinal variable in your own research. Today, we're still going to use Fake_Data1, which we already know is continuous. So if you were just here for the one sample t-test, we've already talked about running line 92 and / or line 93. We've already run these, we don't need to run them again right now. But we can run line 94 to take a glimpse() of our fake data [glimpse(Fake_Data)]. And we're going to use Fake_Data1. So we have 30 rows, 7 columns; Fake_Data1 is listed as <dbl> or double type, which means it's got some decimals. It's RStudio’s way of saying “continuous data”. So we've met our assumption: Fake_Data1 is continuous. If you were using ordinal data for your own research, and you needed to set it to make sure it was being treated appropriately, I've left you some code. That's on line 98. For example, if we wanted to use the “Group” variable, if I show you the glimpse down here, $Group is listed as <int> or integer data type. RStudio thinks it's a number right now, because the options are 1, 2, or 3. We know that this actually means something else. In my fake example, a small drink, a medium drink, a large drink. So on line 98, we could change the data type to make sure that RStudio is treating that data appropriately if we were using this variable. So we would say: for Fake_Data$Group, use the factor() function, set order = TRUE (i.e., there is an order), and tell it which order it goes in (so in this case, we've got a 1, a 2, and then a 3; the levels of the order go 1-2-3). If I Run this, I'll show you what it looks like. We can then say what class() is the group variable [class(Fake_Data$Group)]. And if I run class(), it says Fake_Data$Group is an “ordered” “factor”; an ordinal variable. This is RStudio's way of saying “ordinal”. So that would be if you're using the grouping variable.
You'll notice the assumptions for the Wilcoxon signed-rank test are pretty short, because there's only this one assumption. I've left you an expert tip, but this isn't an assumption, this is just help. The non-parametric tests don't care about outliers because they're not using means, they're using medians. Again, always remove impossible values, but if you were doing this test on your own data, you don't need to remove outliers because that's not an assumption of this test. We've passed our assumption: assumption 1, one continuous variable. That means we can run the Wilcoxon sign test. We're looking to see whether Fake_Data1's median differs from a pre-specified constant; and we're going to be checking our fake data value of 85. That will be our pre-specified constant. We can review the wilcox.test(), so if I Run line 108, it's: ?wilcox.test(), we get some information in our Help window. It says wilcox.test. It's from the stats package, which we get through tidyverse. And it says: “Wilcoxon Rank Sum and Signed Rank Tests”, so you can do two different tests here. “Performs one- and two-sample Wilcoxon tests on vectors of data; the latter is also known as a ‘Mann-Whitney Test’”. We'll cover Mann-Whitney next semester. The Usage: “wilcox.test”, you need an “X”. What is X? “A numeric vector of data values. Non-finite (e.g., infinite or missing) values will be omitted”. And then the other thing we're going to need is mu: “a number specifying an optional parameter used to form the null hypothesis. See ‘Details’”. Sounds a little confusing, but all we have to do, is similarly for the one sample t-test: which variable or which column of data are you using, and what's your pre-specified constant? What are you comparing that variable to? We can do this on line 110, so on line 110: wilcox.test(Fake_Data$Fake_Data1, mu = 85). So what we're doing here, is we're using the wilcox.test() function, and we're saying: in our fake data set, in the Fake_Data1 column, compare that column to the value 85 (which I've gotten somewhere from the literature; today. I actually pulled it from thin air). If I Run line 110, what do we get? It gives you the blue text for what you ran. It says “Wilcoxon signed rank exact test”. It gives you the data, so the column of data you asked it to run. It gives you your “V” statistic, a p-value, and it says: “alternative hypothesis: true location is not equal to 85”. What does all this mean? Oh, I think I've left you a slightly more complicated version. Let's run this really quick and see how it's different. The slightly more complicated version on 112: we've told it it's a two-sided test, we've asked for confidence intervals at the 95% level. So if you needed your median and your confidence intervals, you could run the slightly more complex version on 112. It just gives you a little bit more information, but the same beginning information: which column, which pre-specified value. This other stuff is if you want it to calculate your median and a confidence interval to match what you did for the one-sample t-test [wilcox.test(Fake_Data$Fake_Data1, mu = 85, alternative = “two.sided”, conf.int = TRUE, conf.level = .95)]. So what does all this tell you? Well, it's saying the median is 87.13144. We compared that to a value of 85. Is it different than a value of 85? To answer that question, we look at our p-value. If p is less than (<) .05, we can say it is statistically significantly different than the pre-specified value. So here our p-value…let me read it out with all our decimals, we've got (if I do it right): 0.0000000001863 which is less than (<) .05, which means the median of Fake_Data1 is significantly different than our pre-specified value of 85. And because our median is 87.1, we actually know that using the Wilcoxon sign-rank test, our variable or our column of data is actually higher than our pre-specified value. That's how to run the test. We might also want to report an effect size. The p-value does not tell you how large this effect is. So the effect size will tell us: “How large is this effect?”. We can calculate “r” which is not the same as Pearson's r; it's the effect size that we use for the Wilcoxon signed-rank test. It's required that you have the “rstatix” package to actually run this, so if you've not installed this package before, you'll need to run line 116, which is: install.packages(“rstatix”). I already have this on my computer, I don't need to run this right now. But I will run line 117, which is telling the computer “I already have this on my computer, I would like to use this package right now”. So I'm going to run library(rstatix). I get a little red text. It says: “The following objects are masked from ‘package:effectsize’”. So this is not an error code, it's just saying I have so many packages installed and some of them do similar things that it's going to use one package instead of the other. So that's okay, it's not an error code. If you do get red text saying you need the “coin” package, you will need to run line 119. I didn't get that error code today, so I don't need to run line 119, but if you just got something that says you need coin, run line 119 [install.packages(“coin”)]. Okay. How do I get my effect size? I'm going to use the wilcox_effsize() function, which reads as follows: wilcox_effsize(Fake_Data, Fake_Data1 ~ 1, mu = 85, alternative = “two.sided”, ci = TRUE). What is this actually doing? It's saying: “I want to run the wilcox_effsize() function to get the effect size we need; my data set is Fake_Data; Fake_Data1 ~ 1; our pre-specified constant is 85; it's going to be a two-sided test; and I would like a confidence interval, please return a confidence interval”. If I highlight 120 and Run it…oh, it's thinking for a very long time. Mine took a little minute, so yours might also take a minute. But it should run. It's going to give you in blue text the thing that you just asked it for. And it returns a “tibble”; it's a data type we're not going to worry about today, but it gives you what's called a tibble. It says: you just asked for this on Fake_Data1. Our effect size .873. Our n, or number of participants, is 30. Our lower bound of the confidence interval, our higher bound of the confidence interval. And this one actually gives you some text, it says: magnitude (i.e., how big is this effect? How big is our .873? This is our r value; this is our effect size for the Wilcoxon signed-rank test). This one actually tells you that's a large effect size. Effect sizes vary a little bit field-to-field, but around…I think it's .2 is generally considered small, .4 is generally considered medium, and .6 or higher is generally considered large. So because we have a .873, that's considered large.
And I've left you on line 122, how do you actually write about this? Well, it's the Wilcoxon signed-rank test, the statistic (the V) is 465 which if I scroll up, we got that… here, our V is 465. Our p-value, you can either write it in scientific notation as written in the text ,or you can write it out with all your zeros. And our r value, which is our effect size, is this .873. You could also report the median of your sample, which if you did the slightly more complicated test, it tells you that at the very bottom, our 87.1. And that is how you run a Wilcoxon signed-rank test.
License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
- Ask Chat is a collaborative service
- Ask Us Online Chat hours
- Contact Us