Introduction
A one-sample Wilcoxon signed rank test is applied when you are measuring values of a single variable that you are comparing to some test mean and when this variable is not normally distributed. In this blog entry, we’ll show you how to conduct a one-sample Wilcoxon signed rank test in R. You’ll also learn how to test for normalcy of distribution and create a 95% confidence interval graph for your data.
Create Data
First, we’ll create mock data, then we’ll show you how to test their normality, conduct a one-sample Wilcoxon signed rank test in R, and generate a box plot. Let’s assume we’re measuring IQ for 1,000 subjects.
iq2 <- runif(1000, min=90, max=140)
iq <- round(iq2, digits = 0)
Test for Normality
We’ll use the Shapiro-Wilk test to assess normality of IQ distribution in the sample, then create a histogram:
shapiro.test(iq)
The null hypothesis for the Shapiro-Wilk test is normal distribution. The null hypothesis is rejected, W = .95266, p < .0001, so we cannot assume normal distribution (if the distribution had been normal, we could have attempted a one-sample t-test). The histogram demonstrates the non-normality of the distribution as well:
hist(iq)
The One-Sample Wilcoxon Signed Rank Test
Now let’s run the one-sample Wilcoxon signed rank test. We want to check if the sample median is significantly different from a test value, mu. Let's pick 105 as our mu.
Now we enter the following code:
results <- wilcox.test(iq, mu = 105)
results
The null hypothesis is that the true location is equal to 105. Because p < .0001, we reject the null, meaning that the true location is significantly different from 105.
Graphic Support
Finally, let’s create a box plot from these data:
boxplot(iq,
main = "IQ",
ylab = "Number of people",
col="lightsteelblue1",
border="black"
)
BridgeText can help you with all of your statistical analysis needs.