When two independent samples share a similar center, how can one compare their spread? The Ansari–Bradley test does not compare sample variances directly. Instead it looks at how many positions each group occupies at the ends versus the middle of the pooled ordering. It assigns low scores at the ends and gradually higher scores toward the center: the more a group falls at the ends, the smaller its score sum. That lets a rank statistic test whether two populations share the same scale parameter.[1]
Interpreting the result as a pure scale comparison requires stating the model first. For example, the two populations may have distribution functions F((x−θ)/sX) and F((y−θ)/sY): they share a common location θ and a common shape F, with positive scales sX and sY. The null hypothesis is sX/sY=1; the two-sided alternative is that the ratio differs from 1, and one-sided alternatives are that it is less than or greater than 1.[1]
Making the ends and the center the objects of comparison
Pool the N observations from groups X and Y and assign pooled ranks R from smallest to largest. Define each observation’s symmetric score as A=min(R, N+1−R), then sum the scores that belong to X to obtain the statistic B. When N=8, the scores from the smallest to the largest value are 1, 2, 3, 4, 4, 3, 2, 1.
This scoring groups ranks that point in opposite size directions but are equally far from the center: the smallest and largest both receive 1, and the second-smallest and second-largest both receive 2. If X is relatively more dispersed, its observations tend to occupy the ends of the pooled sequence, so B tends to be small; if X is relatively more concentrated, it tends to occupy the middle, so B tends to be large. The direction of the statistic is therefore opposite to the direction of X’s scale.
How eight numbers yield B=12
Construct two groups of four values each: X=[−2.1, −0.4, 0.4, 2.1], Y=[−4.3, −1.2, 1.2, 4.3]. Both sample medians are 0, and the raw observations have no ties. After pooled ranking, X has ranks 2, 4, 5, 7 with scores 2, 4, 4, 2, so B=12; Y has scores 1, 3, 3, 1.

Two constructed groups of four untied values each; symmetric scores are computed and all 70 group-label assignments are enumerated. Small B corresponds to a more dispersed X; the less alternative uses the upper tail of B. The figure is an algorithmic calculation on constructed data.
X occupies two of the four central positions, while Y occupies the two outermost ends, so X’s score sum exceeds Y’s 8. That ordering matches the construction in which X is more concentrated. To judge how common such a B is under the null, place it in the null distribution of the statistic.
Why exact tail probabilities must be read in reverse
Under the null, assign four of the eight positions to X; there are C(8,4)=70 equally weighted label assignments. Computing B for each yields a null mean of 10. For the observed B=12, the inclusive lower-tail probability is P(B≤12)=65/70≈0.9286, and the upper-tail probability is P(B≥12)=14/70=0.2.
If the prechosen alternative is sX/sY<1—that is, X has the smaller scale—larger values of B support that direction, so the one-sided p-value is the upper tail P(B≥12)=0.2. Conversely, the alternative sX/sY>1 corresponds to smaller B, and the one-sided p-value is the lower tail P(B≤12)≈0.9286. SciPy’s alternative='less' and 'greater' refer to the direction of the scale ratio, not to whether B itself is smaller or larger.[1]
In this example, SciPy’s exact two-sided p-value takes twice the smaller one-sided tail probability, capped at 1: min(1, 2×0.2)=0.4.[1] At a 0.05 significance level, the result does not provide enough evidence to reject equal scale. p=0.4 is not “the probability that the two scales are the same”; failing to reject the null is also not proof that the scales are equivalent.
Putting the test back into the research question
Before use, confirm that the two samples are independent, that the research question truly concerns scale, and that a common-location, common-shape scale-family model is appropriate. The one-sided direction should be fixed by the research question in advance. When reporting, state both sample sizes, whether the raw observations had ties, the p-value method used, the alternative direction, and the statistic; for this example one may report B=12 with exact two-sided p=0.4.
The symmetric scores themselves repeat: both outermost of the eight positions receive 1, which does not mean the raw observations were tied. If the raw observations have ties, first use average ranks and then compute the symmetric scores; one must not indiscriminately apply the exact calibration for the untied case. SciPy provides asymptotic and permutation methods, and also an exact method for untied data.[1]
Common location and shape are central to a scale interpretation: if the groups also differ in location or shape, the composition of the pooled ranks can change as well, and rejecting the null cannot automatically be read as “different variances.” The scale discussed by the Ansari–Bradley test also does not require population variances to exist. In the example the two sample medians happen to be equal—a fact about the sample that does not prove the populations share a common location.
References
- [1] SciPy Community. scipy.stats.ansari. SciPy v1.18.0 Manual.