Wilcoxon signed-rank test

Compare two measurements of the same participants – before and after, two conditions – without assuming normality: the nonparametric alternative to the paired-samples t-test. The differences are ranked by size, and the test checks whether the increases and decreases are balanced. The output: medians, the ranks table as in SPSS, T, z, asymptotic and exact p, two effect measures (rrb and r), a histogram of the differences and a report sentence in English.

Calculator

Loading the data

Drag an Excel file or an SPSS file (.sav) here, or click to choose
In the site's standard template: row = participant, column = variable, first row = headers. CSV is also accepted.
The two measurements – two columns in the same row of the participant (e.g., "attitude_score" and "attitude_score_2" in the Hebrew example); if you computed scale scores on the Cronbach's alpha page – upload here the file you downloaded from there.
Just want to try it out? Download a sample data file (120 participants: an attitude scale score at two measurements, with a legend): English example
or

Paste columns directly from the sheet (including the header row) – select them in Excel, copy, and paste here:

A
B
C
D
E
F
You can also just paste – the data will be loaded and displayed automatically.

Selecting the two measurements

Guide

When to use?

When the two sets of scores are related – the same participants twice, or matched pairs – and the paired t-test is not appropriate. Field (2024, section 7.5) opens with an example: the psychologist from the previous section now wants to test the change in depression within each participant, from Sunday to Wednesday, for each of the two drugs; because the distributions were not normal on one of the days and the sample is small, "the sampling distribution will be non-normal too", hence a nonparametric test. Pallant (2020, chapter 16): "the nonparametric alternative to the repeated-measures t-test – instead of comparing means, Wilcoxon converts scores to ranks and compares them at Time 1 and Time 2"; her example – a fear of statistics test before and after an intervention program (n = 30). Gravetter and Wallnau (2017, Appendix E.3) – "an alternative to the repeated-measures t-test", with the same reasons as in Appendix E.1 for switching to ranks: ordinal data, violated assumptions, high variance, an undetermined score.

On this site, the natural place for two situations: a single rating item measured twice (per the site convention – an ordinal variable, Variables and levels of measurement); and a scale score or quantitative variable when the differences do not look normal (Normality testing on the difference column), when there are outliers, or when the sample is small. Not to be confused with Mann-Whitney (the Wilcoxon rank-sum test) – two separate groups; Field warns that there is "a second Wilcoxon that tests something else" (section 7.4). When there are many pairs (30 or more) and the data are quantitative, the paired t-test is the default, and Gravetter and Wallnau prefer it when the data suit it (Appendix E.1).

The logic: signed ranks of differences

The test "is based on ranking the differences between the scores in the two conditions" (Field, 2024, Section 7.5.1). The steps: compute the difference for each participant (in Field – "the Sunday score subtracted from the Wednesday score", that is, the second minus the first; the same here); a zero difference – the participant leaves the ranking; record the sign and rank the differences by their absolute value, from smallest to largest, with the mean of the ranks for identical values – as in Mann-Whitney; then sum the ranks of the positive differences into T⁺ and of the negative ones into T⁻. In Field's example (Table 7.2): ecstasy – two participants with no change, T⁺ = 36, T⁻ = 0; alcohol – T⁺ = 8, T⁻ = 47. Gravetter and Wallnau (Appendix E.3) illustrate with eight participants: the differences are ranked "by size, regardless of direction", the positive ranks sum to 3 and the negative ones to 33.

Which T. Field (and SPSS in the new menu) calls T the sum of the positive ranks – 36 and 8; Gravetter and Wallnau (and their Table B10) – the smaller of the two – 3. The page prints both. Significance. In a small sample – the exact distribution: Table B10 of Gravetter and Wallnau (for n = 8, T ≤ 3 is significant at .05 – so 3 is rejected), and Exact Sig. in SPSS; Field (Box 7.2): below 50 – the exact one. In a large sample – the normal approximation: the expected value n(n + 1)/4 and the standard error √(n(n + 1)(2n + 1)/24), which "are functions of the sample size, n" – the number of non-zero differences: in Field 8 and 10 (Equations 7.14-7.19: 18 and 7.14, 27.5 and 9.81), and z is the distance of T from its expected value in standard error units (7.20-7.22: 2.53 and −1.99; Gravetter & Wallnau: "when the sample is larger than 20 the approximation is very accurate", and in their example z = −2.10). SPSS corrects the standard error for ties – and so does the page (7.12 and 9.80 in Field, instead of 7.14 and 9.81); Gravetter and Wallnau do not correct.

How to read the output?

Table 1 – medians. The median, quartiles and range of each measurement and of the differences – what is reported instead of means (Field, 2024, section 7.5.7; Pallant, 2020, chapter 16, where they are produced in a separate step in Frequencies). Table 2 – ranks. The SPSS Ranks table: how many differences are negative, how many positive, how many zeros, and the mean rank and sum of ranks of each sign. Here the direction is read: "the larger number of differences in a particular direction tells you the direction of the result" (Field, Sam's tips) – in Field, for ecstasy 8 positive and 0 negative (depression increased), for alcohol 1 vs. 9 (it decreased). Table 3 – the test. n (the non-zero differences), T, the standard error, z – signed: positive when the second measurement is higher (in the old SPSS output, z is computed from the smaller sum and is always negative; in the new menu it is signed, as here) – asymptotic p and exact p (2·P(T ≤ Tsmaller) from the distribution without ties; site convention: computed up to 50 differences), and the two effect measures. In Field's example: ecstasy T = 36, SE = 7.12, z = 2.53, p = .012; alcohol T = 8, SE = 9.80, z = −1.99, p = .047 – "an opposite effect of the two drugs" (section 7.5.5), and these values are among the page's checks. The chart of the differences – like the histogram in the SPSS output, positive in blue and negative in red: "the ratio between the bars is a quick indication" of the direction (section 7.5.4).

Effect size – two yardsticks, "both-and"

Field's rrb (2024, section 7.5.6): the rank-biserial correlation for repeated measures, in Kerby's simple formula: rrb = (T⁺ − T⁻)/(T⁺ + T⁻) (Equation 7.23) – "the difference between the positive and negative ranks as a proportion of all the ranks; this is literally the effect as a proportion". Ecstasy: (36 − 0)/36 = 1 – 100% of the ranks in the direction "Wednesday higher than Sunday"; alcohol: (8 − 47)/55 = −.71 – 71% in the opposite direction. The sign tells the direction. Pallant's r (2020, chapter 16): r = z/√N – "ignore the sign", and N is "the number of observations over the two time points, not the number of cases": in her example z = 4.18, N = 60 (30 participants × 2), r = .54, a "large effect" by Cohen's conventions (1988, pp. 79-83: .1/.3/.5). The page does as she does (N = 2 × pairs) and says so in the table note; computing with the number of participants gives a value √2 times larger. The two measures are not identical and cannot be converted; report at least one, and say which.

Assumptions and warnings

The assumptions (Pallant, 2020, Chapter 16): random sampling; and independent observations – with the exception of repeated measures: "the same participants are tested again at different times or under different conditions" – this is exactly this test. Field (note 2 to chapter 7): nonparametric tests also assume a continuous distribution – so in rating data with many identical differences the tie correction matters. Zero differences. Field and SPSS exclude them, and n becomes smaller; Gravetter and Wallnau (Appendix E.3) note that excluding them "ignores the fact that a zero difference is evidence in favor of the null hypothesis", suggest dividing them equally between the positives and the negatives (and with an odd number – dropping one), and ask that how they were handled be reported. The page follows SPSS and reports their number; in a rating item where most participants did not move – that is the finding. Power. Ranks lose the size of the differences (Field, Box 7.1); the sign test, which also ignores the ranks, "lacks power unless the sample is very small" (Tip 7.2). With fewer than six differences the test cannot come out significant at .05.

Missing values. A participant is included when they have both measurements (/MISSING ANALYSIS). What the page does not compute. An exact p above 50 differences, Monte Carlo, the sign test, McNemar (for two dichotomous measurements) and Marginal Homogeneity (Field's Tip 7.2), the Hodges-Lehmann confidence interval (from R), testing by group (in SPSS – Split File, section 7.5.2; here run each group in a separate file), bootstrap.

And how do you do it in SPSS?

The new way (Pallant, 2020, Chapter 16; Field, 2024, Section 7.5.3): Analyze › Nonparametric Tests › Related Samples… – in Objective: Customize analysis; in Fields: the two measurements to Test Fields; in Settings: Customize tests and Wilcoxon matched-pair signed-rank (2 samples). The output: Hypothesis Test Summary, and on double-click – Related-Samples Wilcoxon Signed Rank Test Summary with the colored histogram: Total N, Test Statistic (= T⁺), Standard Error, Standardized Test Statistic (the z, signed) and Asymptotic Sig.; Field (section 7.5.2) shows how to test by group with Data › Split File. The medians – Pallant produces them in Frequencies with Quartiles.

The old way, which the page generates as syntax: Analyze › Nonparametric Tests › Legacy Dialogs › 2 Related Samples… – the pair to Test Pairs, Wilcoxon checked:

NPAR TESTS
  /WILCOXON=attitude_score WITH attitude_score_2 (PAIRED)
  /MISSING ANALYSIS.

FREQUENCIES VARIABLES=attitude_score attitude_score_2
  /FORMAT=NOTABLE
  /NTILES=4
  /ORDER=ANALYSIS.

Reading the output. Ranks = Table 2 – Negative Ranks (the second smaller than the first), Positive Ranks, Ties, with N, Mean Rank, Sum of Ranks; Test Statistics – Z (from the smaller sum, always negative; the footnote says "based on negative/positive ranks") and Asymp. Sig. (2-tailed); Frequencies – the medians. The syntax was checked against PSPP (the free implementation): the counts, the mean ranks, the sums and z are identical – but PSPP signs the difference the other way (first minus second), so "negative" and "positive" are swapped.

And how do you do it in R?

In base R, wilcox.test(x2, x1, paired = TRUE) – R's statistic V is T⁺ (the sum of the positive ranks of x2 − x1); the default adds a continuity correction – correct = FALSE gives the p of SPSS and of the page; exact = TRUE is computed only without ties and without zeros. The script was run as is on the sample data file and gave the table values (in the comments). The site rule for R: a UTF-8 file, every comment line starts with an English word, and a UTF-8 locale for Hebrew names.

# Wilcoxon signed-rank test – Professor Stat. This file is saved in UTF-8; every comment line starts with an English word
library(readxl)   # reading Excel

# Loading: the standard template – row = participant, column = variable; the sheet "data"
d <- read_excel("C:/Rdata/DATA_wx_example_eng.xlsx", sheet = "data")
ok <- !is.na(d[["attitude_score"]]) & !is.na(d[["attitude_score_2"]])
x1 <- d[["attitude_score"]][ok]; x2 <- d[["attitude_score_2"]][ok]

# Medians and quartiles (type = 6 = SPSS) – Table 1
median(x1); median(x2)                                  # 3.25, 3.50
quantile(x2 - x1, c(.25, .5, .75), type = 6)            # The differences

# Differences (second minus first), removing zeros, ranks of |difference|, T+ and T− – Table 2
dd <- x2 - x1; nz <- dd[dd != 0]; r <- rank(abs(nz))
Tp <- sum(r[nz > 0]); Tm <- sum(r[nz < 0]); n <- length(nz)
c(zeros = sum(dd == 0), n = n, Tplus = Tp, Tminus = Tm)  # 14 zeros, n = 99, T+ = 3507, T− = 1443

# The test: V = T+; asymptotic p without continuity correction = SPSS (with tie correction) – Table 3
wt <- wilcox.test(x2, x1, paired = TRUE, exact = FALSE, correct = FALSE)
wt                                                      # V = 3507, p = .0003

# Signed z (positive = the second is higher), r_rb (Field) and r = |z|/√N with N = 2 × pairs (Pallant)
z <- sign(Tp - n * (n + 1) / 4) * abs(qnorm(wt$p.value / 2))
c(z = z, r_rb = (Tp - Tm) / (Tp + Tm), r = abs(z) / sqrt(2 * length(dd)))   # 3.62, .417, .240

# Small sample without ties and without zeros – exact p (Table E.1 of Gravetter and Wallnau: the differences themselves)
wilcox.test(c(4, -14, 5, -20, -6, -16, -8, -24), exact = TRUE)   # V = 3, p = .039

Reporting the results

Field (2024, section 7.5.7): "report the statistic (T), the exact significance and an effect measure" – with the medians of the two conditions: "For ecstasy users, depression levels were significantly higher on Wednesday (Mdn = 33.50) than on Sunday (Mdn = 17.50), T = 36, p = .012, rrb = 1. For alcohol users the opposite: significantly lower on Wednesday (Mdn = 7.50) than on Sunday (Mdn = 16.0), T = 8, p = .047, rrb = −.71" – or with z instead of T. Pallant (2020, chapter 16): "z = −4.18, n = 30, p < .001, with a large effect (r = .54). The median decreased from 40 to 38". Gravetter and Wallnau (Appendix E.3) add the sums of ranks and the handling of zeros. The report sentences in the output are built this way – medians, n, T, z, p (the exact one when computed), rrb and r. Formatting rules (American Psychological Association [APA], 2020, Section 6.36): p and r without a zero before the decimal point; T and z with one.

Common mistakes

Confusing it with Mann-Whitney. Two Wilcoxon tests: rank sum – for separate groups; signed ranks – for the same participants (Field, 2024, Section 7.5).

Reading the direction from the sign of z in the old output. There it is always negative; the direction – from the counts and the ranks (section 7.5.4).

Reporting means. The test is on ranks; report medians (Field, Section 7.5.7; Pallant, 2020, Chapter 16).

Forgetting the zeros. They leave the computation, but not the story: Gravetter and Wallnau ask to report how many there were and how they were handled (Appendix E.3).

Computing Pallant's r with the number of participants. In her version N is the number of observations – doubled; the value comes out √2 times smaller, and you say which N.

Running to Wilcoxon every time a normality test is significant. With 30 pairs or more, the central limit theorem covers t (Field, 2024, section 6.2.7; Normality testing) – and Wilcoxon loses the size of the differences (Box 7.1).

Using the sign test when ranks are available. It ignores the size of the change – it lacks power (Tip 7.2).

References

American Psychological Association. (2020). Publication manual of the American Psychological Association (7th ed.). https://doi.org/10.1037/0000165-000

Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.

Field, A. (2024). Discovering statistics using IBM SPSS statistics (6th ed.). SAGE.

Gravetter, F. J., & Wallnau, L. B. (2017). Statistics for the behavioral sciences (10th ed.). Cengage Learning.

Pallant, J. (2020). SPSS survival manual: A step by step guide to data analysis using IBM SPSS (7th ed.). Open University Press.

Wilcoxon (1945), King and colleagues (2011) and Kerby (2014) – as cited in Field (2024). Per the site rule, the reference list includes only sources read in the original; Gravetter and Wallnau (2017, Appendix E, pp. 692-695), Cohen (1988), Pallant (2020) and APA (2020) – by page, chapter and section of the printed edition; Field (2024) in a reflowable digital copy – by section, equation and box (his Table 7.1, from which Table 7.2 is derived, is the page's test file). The syntax – validated against PSPP; R was run in 4.3.3.