ADescribe · Guide test 126
Cucconi test
Uses ranks to test whether two distributions differ in location, scale, or both.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Compare distributions (two or more groups) — Do the groups come from the same distribution — anywhere, not only in their centers?
In Compare distributions (two or more groups), choose Test = Cucconi (location and scale).
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 · Cucconi test
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how C varies across samples when H₀ is true, Exp(1), the large-sample law of C (asymptotic: P(C ≥ c) = e^(−c)).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .209).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- standardized sums of squared ranks and squared reverse ranks
- their correlation under H₀
The verdict
C = 1.57, p = .209
p > α = .050: compatible with H₀
One rank statistic sensitive to shifts in center and spread together. Asymptotically (U, V) is bivariate normal, so C is exponential.
- Statistic
- 1.566
- p-value
- 0.2088
Cucconi test on Group 1: n = 25; Group 2: n = 25: C = 1.57, p = .209. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: two distributions agree; alternatives include location and scale.
Assumptions
Independent observations and groups; permutation calibration with a documented tie convention.
Formula
Parameters and notation
For first sample size m and total N, A=ΣR², B=Σ(N+1−R)². U=(A−E0A)/√Var0A, V=(B−E0B)/√Var0B; ρ=Corr0(A,B). Conditional permutation moments define all centering/covariance terms.
Structure of the method
Compute squared pooled ranks and squared reverse ranks for one sample, standardize both sums by their null moments and combine them through their null correlation. The resulting quadratic statistic jointly emphasizes location and dispersion departures.
Estimated and nuisance parameters
Rank sums, their conditional means/variances and correlation are estimated or computed under the declared permutation construction. Untied closed-form moments and tie-aware conditional moments must not be silently interchanged.
Settings and design choices
Choose permutation versus bootstrap construction, tie-ranking convention, resampling budget and significance level. These procedures use different null-generation mechanisms; calling both resampling does not make their interpretation identical.
Fitting and adaptation
For equality of independent distributions, exchange labels at fixed group sizes and recompute the exact chosen Cucconi statistic. If using bootstrap calibration, specify its centering and pooled/null sampling model explicitly. New observations require reranking and recalibration. The existing example uses permutation with an untied-form statistic on midranks; permutation calibrates that chosen statistic conditionally.
Sensitivity and robustness
Large tied blocks change score covariance and can cause degeneracy. Shape differences may generate rejection even without a simple location or scale shift. Report the implemented statistic and resampling rule; do not infer which component changed merely from a significant combined result.
How to use and calibrate
Use the Cucconi permutation or documented bootstrap distribution; the two rank directions jointly capture location and scale.
Example application
Compare two groups when either average level or variability may change.
Interpretation and pitfalls
Watch out
Bootstrap and permutation versions test under different constructions; specify which was used. A location/scale interpretation assumes suitable shapes.
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.
Python and R
Direct squared-rank Cucconi statistic, calibrated by label permutations. Ties use average ranks; report the chosen permutation implementation.
Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: base R
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
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)
cucconi<-function(a,b) {n<-length(a);m<-length(b);N<-n+m;r<-rank(c(a,b))[seq_len(n)];den<-sqrt(n*m*(N+1)*(2*N+1)*(8*N+11)/5);U<-(6*sum(r^2)-n*(N+1)*(2*N+1))/den;V<-(6*sum((N+1-r)^2)-n*(N+1)*(2*N+1))/den;rho<-2*(N^2-4)/((2*N+1)*(8*N+11))-1;(U^2+V^2-2*rho*U*V)/(2*(1-rho^2))}
T<-cucconi(x,y);pool<-c(x,y);n<-length(x);set.seed(2026);B<-999
null<-replicate(B,{z<-sample(pool);cucconi(z[seq_len(n)],z[-seq_len(n)])})
print(c(statistic=T,p=(1+sum(null>=T))/(B+1)))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
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)
cucconi<-function(a,b) {n<-length(a);m<-length(b);N<-n+m;r<-rank(c(a,b))[seq_len(n)];den<-sqrt(n*m*(N+1)*(2*N+1)*(8*N+11)/5);U<-(6*sum(r^2)-n*(N+1)*(2*N+1))/den;V<-(6*sum((N+1-r)^2)-n*(N+1)*(2*N+1))/den;rho<-2*(N^2-4)/((2*N+1)*(8*N+11))-1;(U^2+V^2-2*rho*U*V)/(2*(1-rho^2))}
T<-cucconi(x,y);pool<-c(x,y);n<-length(x);set.seed(2026);B<-999
null<-replicate(B,{z<-sample(pool);cucconi(z[seq_len(n)],z[-seq_len(n)])})
print(c(statistic=T,p=(1+sum(null>=T))/(B+1)))
Output
statistic p 2.684351 0.063000
Sources
- Statistics guide v4 (historical):
- Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 126, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT126.