Two samples can share the same mean and still differ in shape: one concentrates in the middle, the other puts more mass in the extremes. The Baumgartner–Weiss–Schindler (BWS) two-sample test compares the full distributions of two independent samples. Its distinctive feature is that it gives more weight to rank deviations in the tails, so differences at the ends stand out more strongly in the statistic.[1]
Let the cumulative distribution functions of the two groups be F and G. The null hypothesis is F=G, that is, the entire distributions coincide; the two-sided alternative is that F and G differ at least somewhere. The test is not about equality of means or medians.[1]
Seeing departures through pooled ranks
Pool the two samples and rank the observations from smallest to largest. Suppose group x has n values and group y has m, so the total is N=n+m; after sorting the x values in increasing order, write Rᵢ for the rank of the i-th of them in the pooled sample. Under a reference of uniform mixing of the two groups, compare Rᵢ with Ni/n: the larger the departure, the less that group's behavior at this order position looks like even mixing. Do the same for group y.
For group x, set tᵢ=i/(n+1). Its statistic is:
Bₓ = (1/n) Σᵢ₌₁ⁿ (Rᵢ−Ni/n)² / [tᵢ(1−tᵢ)mN/n].
Swap the roles of the two groups to obtain Bᵧ, then take B=(Bₓ+Bᵧ)/2.
The key piece in the denominator is tᵢ(1−tᵢ): it is largest in the middle and smaller near 0 or 1. Holding the other scales fixed, the same squared rank deviation divided by a smaller denominator contributes more. For example, at t=1/2 the factor is 1/4, and at t=1/7 it is 6/49; the same squared rank deviation receives about twice the weight in the latter case. What BWS emphasizes, therefore, is rank or cumulative-distribution departures at the ends of the distribution, not a direct bonus for large raw observations.[1]
Same mean, ranks clustered in different places
Consider a constructed numerical example: x=[−1.2, −0.8, −0.2, 0.2, 0.8, 1.2]; y=[−4, −3, −2, 2, 3, 4]. Both means are 0, but x is more concentrated while y sits farther out in both tails. After pooling and ranking, the ranks of x are [4, 5, 6, 7, 8, 9] and those of y are [1, 2, 3, 10, 11, 12]. Group y occupies the three smallest and three largest positions, which is exactly the setting for watching how tail placement affects the BWS statistic.

ECDF, BWS weighted rank terms, and all 924 label assignments for two groups of six constructed values each; both means are 0, and the statistic and exact permutation tail probability match SciPy.
The left panel's empirical cumulative distribution functions (ECDFs) show the two groups differing at the ends; the middle panel breaks out each order position's contribution to Bₓ or Bᵧ. Substituting the ranks above into the formula yields B=1.53125. That number summarizes how far the two groups depart from even mixing, but by itself it does not say how unusual the difference is: it must be placed in a reference distribution under the null.
Calibrating the result with every label assignment
Under the null, keep these 12 numbers fixed, assign 6 of them to x and the rest to y, and recompute B for every assignment. There are C(12,6)=924 assignments; 154 of them produce a statistic at least as large as the observed value. The exact permutation p-value is therefore 154/924=1/6, about 0.167. The right panel shows all 924 statistics and where the observed value sits.
Here “two-sided” means interest in any distributional difference. Because B already folds both directions of departure into a square, larger departures mean larger B, so what one counts in the reference distribution is the upper tail of B at least as large as the observation; that upper-tail probability is not multiplied by 2 mechanically.[1]
If a significance level of 0.05 is chosen in advance, 0.167 is larger than 0.05, so this example does not reject the null that the two distributions are the same. Different scatter patterns in the figure are not the same as this small-sample test already providing enough evidence; failing to reject the null also does not prove that the two population distributions coincide.
When this permutation reading is used, the two samples need to be independent, and under the null the group labels must be exchangeable. One chooses BWS when the aim is to test the whole distribution and to care about tail rank departures; the tail weighting does not mean the test is more powerful than every alternative against every kind of distributional difference.[1]
References
- [1] SciPy community. scipy.stats.bws_test — SciPy v1.18.0 Manual.