BCompare groups · Guide test 033
Wilcoxon signed rank test
Tests symmetry of paired differences about a specified center using signs and absolute ranks.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Wilcoxon signed-rank test — Did paired measurements change systematically (without assuming normal differences)?
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Wilcoxon signed-rank test
Alternative
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how V varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the total probability of outcomes no more likely than yours (p = .015).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- rank of |dᵢ| among the non-zero differences
- sum of ranks of the positive differences
- V's center when H₀ is true
The verdict
V = 102, p = .015
p ≤ α = .050: reject H₀
Uses both the sign and the size (rank) of each difference, and assumes the differences are symmetric about their center. Without ties or zeros R uses V's exact null distribution. This bench follows R's defaults. The CodeSplash method uses the tie-corrected normal approximation unless you choose Exact in its options.
- Statistic
- 102.000
- p-value
- 0.0151
Wilcoxon signed-rank test on Before: n = 15; After: n = 15: V = 102, p = .015. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: the paired difference distribution is symmetric about zero; shift alternatives are conventional.
Assumptions
Independent pairs; continuous, symmetrically distributed differences for the classical location test. Absolute difference ranks must be meaningful.
Formula
Parameters and notation
Di is a difference minus its null shift. Standard handling removes zeros; Pratt and other conventions differ. Use midranks for ties.
Structure of the method
Rank absolute nonzero differences, attach their signs, and sum positive ranks. Conditional sign enumeration supplies an exact reference when the chosen tie/zero convention and symmetry model justify it; a large-sample route uses tie- and zero-adjusted variance with optional continuity correction. Roundoff can change ranks even when measurement differences should tie.
Estimated and nuisance parameters
Estimate signed rank totals and, optionally, a Hodges–Lehmann pseudomedian. The symmetry center is the null parameter; population variance is not estimated for the basic test. The median and pseudomedian coincide under symmetry, but they need not coincide generally, so the reported location target should be stated precisely.
Settings and design choices
Choose zero convention, tie/rank precision, exact versus approximate or permutation method, continuity correction, direction, and alpha. Software support for exact inference with ties is version-dependent. Record package versions and options instead of relying on an automatic method switch when comparing Python and R results.
Fitting and adaptation
Compute a single harmonized difference vector before either language's test, rounding only to a scientifically justified measurement precision. Recompute ranks and null calibration after data changes. A sign-flip resampling method relies on symmetry or a corresponding randomization argument; it is not universally valid for arbitrary asymmetric paired differences.
Sensitivity and robustness
Asymmetry can invalidate a simple median interpretation, and many zeros reduce useful information. The baseline Python explicitly rounds differences while the R call subtracts raw decimal inputs internally; floating-point ties can therefore disagree. Harmonizing differences is a reproducibility fix, not an invitation to round away real distinctions.
How to use and calibrate
Use exact sign enumeration when applicable or a tie/zero corrected normal approximation. Estimate a pseudomedian with the Hodges–Lehmann procedure if useful.
Example application
Compare paired instrument readings when differences are symmetric but heavy tailed.
Interpretation and pitfalls
Watch out
Without symmetry this is not simply a median test. Software exact calculations may differ with ties or zeros.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
- Rewritten in the review: R code.
R codedocs.scipy.org
Align the difference rounding with Python so floating-point artifacts do not create different ties.
Corrected R code
x <- c(4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0) y <- c(4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9) d <- round(x-y,10) print(wilcox.test(d,mu=0,exact=FALSE,correct=TRUE))
Python and R
Paired differences should be symmetric for a location interpretation. Rounding here prevents floating-point subtraction from breaking mathematical ties.
Validated — Executed successfully in the validation environment · needs numpy, scipy
import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x = np.array([4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0])
y = np.array([4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9])
print(stats.wilcoxon(np.round(x-y,10),method="approx",correction=True))
Output
WilcoxonResult(statistic=np.float64(3.0), pvalue=np.float64(0.014116388749862393))
Validated — Executed successfully in the validation environment · needs Base/standard library
x <- c(4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0)
y <- c(4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9)
print(wilcox.test(x,y,paired=TRUE,exact=FALSE,correct=TRUE))
Output
Wilcoxon signed rank test with continuity correction data: x and y V = 52, p-value = 0.01412 alternative hypothesis: true location shift is not equal to 0
Sources
- SciPy — SciPy · wilcoxondocs.scipy.org
- scipy.stats.wilcoxondocs.scipy.org
- Reference's record:
- Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 033, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT033.