ADescribe · Guide test 096
Ansari–Bradley test
Compares the scale of two independent distributions, assuming suitable alignment of their centers.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Equal spread tests — Do two or more groups have the same spread?
In Equal spread tests, choose Test = Ansari–Bradley.
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 · Ansari–Bradley test
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how z varies across samples when H₀ is true (normal approximation).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .017).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- pooled rank
- scores largest in the middle, smallest at both ends
The verdict
AB = 254.00, z = 2.38, p = .017
p ≤ α = .050: reject H₀
A rank test of dispersion that assumes equal medians; a location difference masquerades as a scale difference.
- Statistic
- 2.383
- p-value
- 0.0172
Ansari–Bradley test on Group 1: n = 20; Group 2: n = 20: AB = 254.00, z = 2.38, p = .017. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: the two population scales are equal.
Assumptions
Independent samples from distributions with a common location and comparable shape under a scale model; continuous observations for simple rank calibration. Location shifts can confound scale tests.
Formula
Parameters and notation
Pooled ranks receive scores 1,2,… inward from both ends. Larger A generally means the first sample is less dispersed.
Structure of the method
Pool the two samples, assign symmetric scores increasing from both extremes toward the center, and sum the first sample’s scores. An exact rank distribution or tie-adjusted normal reference assesses scale differences when the distributions share a suitable common center and shape.
Estimated and nuisance parameters
Observed ranks, symmetric scores, and group sizes define the statistic. The common location is a nuisance assumption, not automatically removed by the raw rank calculation. Larger first-sample score sums usually indicate greater concentration near the center, hence smaller rather than larger scale.
Settings and design choices
Prespecify scale direction, tie handling, exact versus asymptotic method, and any location-alignment strategy. Aligning sample medians by estimation changes finite-sample calibration and must not be portrayed as the original exact rank test without justification. Software alternative labels refer to scale, not raw statistic size.
Fitting and adaptation
New observations require re-pooling and re-ranking. Exact or conditional permutation calculations keep sample sizes and the permitted score allocation fixed. If centers are estimated, a valid resampling analysis must address that additional step. No neural fitting or fine-tuning is involved.
Sensitivity and robustness
A location shift can masquerade as a scale difference. Heavy ties, extreme imbalance, or very small samples reduce resolution and may disable an exact software route. Check group centers and shapes and interpret the estimated scale ratio where available rather than relying only on the p-value.
How to use and calibrate
Use exact rank enumeration or a tie corrected normal approximation.
Example application
Compare dispersion between two independent measurement processes.
Interpretation and pitfalls
Watch out
Do not interpret unequal locations as evidence of a scale difference. Estimated recentering changes finite sample calibration.
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
Scale interpretation requires a common location; an unmodeled location difference can affect rank scale tests.
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.ansari(x,y))
Output
AnsariResult(statistic=np.float64(51.0), pvalue=np.float64(0.5413702095537719))
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(ansari.test(x,y,exact=FALSE))
Output
Ansari-Bradley test data: x and y AB = 51, p-value = 0.5414 alternative hypothesis: true ratio of scales is not equal to 1
Sources
- R stats — R stats · ansari.teststat.ethz.ch
- ansari.teststat.ethz.ch
- Statistics guide v4 (historical):
- R: Executed successfully in the validation environment
- 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 096, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT096.