One-sample Wilcoxon test in R

By Data Tricks, 28 July 2020

What is a one-sample Wilcoxon test?

A one-sample Wilcoxon test is the non-parametric alternative of a one-sample t-test. It assumes that the data are not normally distributed.

A one-sample Wilcoxon test is used to test whether the median of a population, from which a sample is drawn, is statistically different from a hypothesised value. It is a non-parametric alternative to a one-sample t-test, where it is assumed that the data are not normally distributed.

A one-sample Wilcoxon test has a null hypothesis that the population median is equal to the hypothesised value, and an alternative hypothesis that it is not equal. This is called a two-tailed t-test.

We can also perform a one-tailed t-test if we have a prior belief that the population median is either larger or smaller than the hypothesised value. In a one-tailed test, the null hypothesis is the same but the alternative hypothesis is that the population median is larger (or smaller, as appropriate) than the hypothesised value.

Example in R

First let’s create a set of values to use in this example:

set.seed(150)
data <- data.frame(Value = sample(c(1:30), 100, replace = TRUE))

Let’s assume that the hypothesised median value is 15. The null hypothesis is therefore that the median of the population is equal to 15, whilst the alternative hypothesis is that the median is different.

test <- wilcox.test(data$Value, mu = 15, conf.int = TRUE)

Now analyse the result of the test:

> test
       
       Wilcoxon signed rank test with continuity correction

data: data$Value
V = 2457, p-value = 0.216
alternative hypothesis: true location is not equal to 15
95 percent confidence interval:
 14.49996 18.00006
sample estimates:
(pseudo)median
      16.00004

p-value

The p-value is 0.216, above the 5% significance level and therefore the null hypothesis cannot be rejected.

95% confidence interval

The 95% confidence interval for our test is 14.50 to 18.00. This means that at the 5% significance level, the null hypothesis cannot be rejected for hypothesised medians between 14.50 and 18.00.

Is a one-sample Wilcoxon test the right test?

Use our interactive tool to help you choose the right statistical test or read our article on how to choose the right statistical test.

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Please note that your first comment on this site will be moderated, after which you will be able to comment freely.