How to run a 1-sample Wilcoxon test
- Copy the measurement column together with the header and paste it.
- Select the measurement column and enter the reference median. You can also choose how values exactly equal to the reference are handled (zero differences).
- Press Analyze and check the p-value and the Hodges-Lehmann estimate in the results table.
Worked example with sample data
The sample data are the repair times (h) of 20 machine breakdowns, and the target is a median repair time of 4 hours. The analysis uses 4 as the reference median.
The results table shows a median of 5.4 hours, a rank-sum statistic of 20 and a p-value of 0.0007076. The p-value is far below 0.05, so the interpretation concludes that the median is statistically significantly different from the reference (4). Only 4 of the 20 repairs were shorter than 4 hours, and even those were close to the target, so the rank sum of the negative differences (20) is very small.
The Hodges-Lehmann estimate of 1.675 (confidence interval 0.65 to 3.45) means repairs typically take about 1.7 hours longer than the target. The median confidence interval in the chart (4.6 to 6.4) also does not contain the red reference line at 4.
The mean (6.28) is pulled well above the median by two long repairs of 12.4 and 15.2 hours (skewness 1.50, 2 outliers by the IQR rule). A t test on the mean of such skewed data is strongly affected by outliers, so the Wilcoxon test on the median fits better, and the two long repairs deserve a separate root-cause review.
How it is calculated
The absolute differences between each value and the reference median are ranked, and the sum of the ranks of positive differences (W+) is compared with that of negative differences (W-). For a two-sided test the rank-sum statistic is the smaller of the two.
The p-value is computed the same way as SciPy's wilcoxon: with 50 or fewer values and no ties or zero differences, the exact distribution is used; with ties or zeros, a permutation distribution that counts every sign combination is used for 13 or fewer values, and the normal approximation otherwise.
Hodges-Lehmann estimate and median confidence interval
The Hodges-Lehmann estimate is the median of all Walsh averages ((di+dj)/2) of the differences from the reference, so it shows how far the center lies from the reference.
The interval in the median + confidence interval chart is a distribution-free interval based on the sign test (binomial distribution).
What the result shows
The results table, a dot plot with the reference line, a box plot and the median with its confidence interval.
How to read the 1-sample Wilcoxon result
- If the p-value is below the significance level, the median differs from the reference. The interpretation tells you whether the median is above or below the reference.
- The Hodges-Lehmann estimate is the location shift from the reference. If its confidence interval does not contain 0, the conclusion is the same as a significant difference.
- If the data are roughly symmetric and normal, the 1-sample t test has more power.
Frequently asked questions
How is it different from the 1-sample t test?
The t test looks at the mean; the Wilcoxon test looks at the median (location) through ranks, so it is less sensitive to outliers and skewed distributions.
Which zero-difference method should I choose?
The default, wilcox, drops values exactly equal to the reference. If there are many such values, switch to pratt or zsplit and see whether the result changes much.
How many values do I need?
It runs from 1 value, but at least 6 values are needed for a two-sided result to be significant at the 5% level.