Why Compare Groups by Depth?
In multivariate data, a group can differ from another in location, spread, shape, or tail behavior. A depth function provides an ordering of observations from more central to more peripheral relative to a distribution. Comparing the groups’ positions in a common ordering gives a rank-based way to detect differences without reducing each vector to one arbitrarily chosen coordinate.
The word common matters. If each group is ranked relative to its own depth contours, the ranks can look similar even when the groups occupy different parts of the sample space. For a direct group comparison, first evaluate every observation using a depth function based on the pooled distribution, then compare the resulting pooled depth scores across groups. This tutorial develops two complementary summaries: pooled depth ranks and empirical distributions of pooled depth scores.
The depth function may be, for example, halfspace depth or simplicial depth. The test depends on the chosen depth: different depth functions can order the same observations differently. In the rank tests below, the pooled scores are held fixed while group labels are permuted. Thus, the statistic is driven by how the observed labels are arranged along the pooled depth ordering.
Null Hypotheses and What These Tests Detect
Suppose the groups are independent samples from distributions \(F_1,\ldots,F_k\). A standard null for an exact permutation test is equality of the full distributions:
Under this null, observations are exchangeable across group labels when the group sizes are fixed. A depth-rank test can then be calibrated by comparing the observed statistic with its values under all reallocations of the labels that preserve those sizes.
The chosen statistic describes which features of a difference the procedure is sensitive to. A group with unusually high pooled depth ranks tends to have observations more central in the pooled sample; a group with unusually low ranks tends to have more peripheral observations. A difference in depth distributions can reflect location, scale, or shape differences, but a depth-based statistic is not guaranteed to detect every possible difference between multivariate distributions. In particular, equality of depth-score distributions is generally weaker than equality of the full distributions.
Two Groups: A Pooled Depth Rank Statistic
For two groups, let \(n_1+n_2=N\) and define \(W_1=\sum_{j=1}^{n_1}R_{1j}\), the rank sum for group 1. Under a balanced arrangement of labels, group 1’s expected rank sum is \(n_1(N+1)/2\). A convenient two-sided statistic is the squared departure from this value:
A large value means that group 1 has ranks unusually high or unusually low relative to the pooled ordering. The sign of the unsquared departure indicates direction: a positive departure means higher pooled depth ranks, and a negative departure means lower ranks. The finite-sample test does not need a normal or chi-squared approximation; its reference distribution is obtained by permuting the labels.
Worked Example: Two Groups With Separated Depth Ranks
Suppose a two-dimensional data set has \(N=8\) observations, and a chosen pooled depth calculation gives eight distinct scores in increasing order: \(0.08, 0.14, 0.21, 0.29, 0.38, 0.49, 0.63, 0.80\). Group 1 contains the four observations with ranks \(5,6,7,8\), while group 2 contains ranks \(1,2,3,4\). Test for a two-sided group difference using \(T_2\).
Here \(n_1=n_2=4\), and group 1’s rank sum is \(W_1=5+6+7+8=26\). Under the null’s balanced rank allocation, its expected sum is \(4(8+1)/2=18\). Therefore,
There are \(\binom{8}{4}=70\) possible assignments of four ranks to group 1. Because the rank total is \(1+\cdots+8=36\), an assignment gives \(T_2\ge64\) exactly when its rank sum is at least 26 or at most 10. Only the set \(\{5,6,7,8\}\) has sum at least 26, and only \(\{1,2,3,4\}\) has sum at most 10. Thus the exact two-sided permutation \(p\)-value is \(2/70\approx0.0286\). This calculation tests whether the observed separation is unusual under exchangeability; it does not, on its own, identify whether location, spread, or another feature caused it.
Several Groups: Between-Group Variation in Ranks
For \(k\) independent groups, let \(\bar R_g=n_g^{-1}\sum_{j=1}^{n_g}R_{gj}\) be group \(g\)’s mean pooled rank. The overall mean rank is \((N+1)/2\). A direct measure of between-group rank separation is
The statistic weights each group’s squared departure by its size. Large values indicate that at least some group mean ranks are far from the overall mean. A familiar scaled version, when there are no tied depth scores, is
For finite-sample inference in this tutorial, \(H_R\) is calibrated by permutation rather than by relying on a large-sample reference distribution.
To verify the identity, note that \(R_g=n_g\bar R_g\), so
Substituting this expression into \(H_R\) gives
because the second term is \(3(N+1)\) and cancels the final term. This proves the stated identity. \(\square\)
Worked Example: Three Groups With Different Mean Depth Ranks
Suppose there are three groups of size 3, and the nine distinct pooled depth ranks are allocated as follows: group A has ranks \(1,2,6\), group B has \(3,4,8\), and group C has \(5,7,9\). Their rank sums are \(9,15,21\), so their mean ranks are \(3,5,7\). The overall mean rank is \((9+1)/2=5\).
The between-group rank variation is
The scaled statistic is \(H_R=12(24)/(9\cdot10)=3.2\). The possible assignments of nine ranks to three labelled groups of size 3 number \(9!/(3!3!3!)=1680\). To obtain the exact \(p\)-value, calculate \(H_R\) for each such assignment and take the proportion at least 3.2. This defines a finite-sample test without requiring a chi-squared approximation.
Comparing Empirical Depth Distributions
A mean-rank statistic emphasizes shifts in average depth rank. A more distributional comparison asks whether the groups differ across the full range of pooled depth scores. Let \(\widehat H_g(t)\) be the empirical distribution function of the pooled scores in group \(g\), and let \(\widehat H(t)\) be the empirical distribution function of all pooled scores. One omnibus discrepancy is
The integral is an average squared difference over the observed pooled score distribution. A large value means that one or more groups have an empirical depth-score distribution unlike the pooled distribution. Since \(\widehat H\) is discrete, the integral is a finite weighted sum over the pooled scores. With distinct scores, each observed score has pooled mass \(1/N\). As with the rank statistic, labels are permuted while the pooled scores remain fixed.
Worked Example: A Difference Across the Depth-Score Distribution
Take four distinct increasing pooled depth scores, with ranks \(1,2,3,4\), and two groups of size 2. Suppose group A receives ranks \(\{1,2\}\) and group B receives \(\{3,4\}\). At the four ordered scores, the pooled empirical distribution has values \(1/4,1/2,3/4,1\). Group A’s empirical distribution has values \(1/2,1,1,1\), so its differences from the pooled distribution are \(1/4,1/2,1/4,0\). Consequently,
Group B has the opposite differences, \(-1/4,-1/2,-1/4,0\), and its squared integral is also \(3/32\). Therefore \(T_D=2(3/32)+2(3/32)=3/8\). There are \(\binom{4}{2}=6\) assignments of two scores to group A. The observed value is maximal: the two contiguous allocations \(\{1,2\}\) and \(\{3,4\}\) produce \(3/8\), while the other four allocations produce smaller values. The upper-tail permutation \(p\)-value is thus \(2/6=1/3\). The numerical discrepancy is large relative to these four scores, but the exact reference set is small, so the evidence is not significant at a 0.05 level.
Finite-Sample Permutation Calibration
For fixed group sizes, the number of distinct label allocations is \(M=N!/\prod_{g=1}^k n_g!\). For either statistic, calculate its value for the observed labels and for each allocation. For a statistic \(T\) where large values indicate stronger evidence, the nonrandomized upper-tail permutation \(p\)-value is
The use of “greater than or equal to” includes allocations tied with the observed statistic. When there are no ties in the depth scores, the pooled ranks are unchanged by relabelling. If depth scores themselves are tied, a tie-handling rule is needed; the distinct-score calculations above do not specify one.
To prove this, condition on the pooled observations. Under the null, every allocation of the \(N\) observations to labelled groups of the fixed sizes has the same conditional probability, so the observed allocation is uniform over the \(M\) possibilities. The pooled depth scores and the statistic value for each allocation are then fixed. Order those \(M\) statistic values from largest to smallest, retaining repeated values. For an observed allocation, its permutation \(p\)-value is the proportion of all \(M\) values at least as large as its own. The set of allocations whose \(p\)-value is at most \(\alpha\) occupies at most an \(\alpha\) fraction of this ordered list: any tied block at the cutoff is included in full, which can only make the fraction smaller than the cutoff. Uniformity of the observed allocation therefore gives the stated conditional inequality. Averaging over the pooled observations gives the unconditional inequality as well. \(\square\)
Interpretation and a Common Mistake
A depth-rank test gives an interpretable direction: a group’s ranks can be higher or lower than the pooled center-to-outlyingness ordering. The empirical-distribution statistic gives a broader comparison across that ordering, rather than focusing only on mean ranks. Neither summary identifies the particular multivariate feature responsible for a rejection. Graphs of the vectors or of the group-specific depth-score distributions can help describe the observed difference, but they do not change the test’s null calibration.
- Mistake: “The groups have the same distribution of depth scores, so permuting the original group labels must be valid.”
Correction: Equal depth-score distributions do not generally imply that the original multivariate observations are exchangeable. The exact permutation guarantee here is justified under equality of the full group distributions. - Mistake: “A large rank statistic proves a location shift.”
Correction: The statistic detects a difference in the selected depth ordering; changes in spread or shape can also affect that ordering. - Mistake: “Permuting labels means recomputing a different pooled depth ordering for each allocation.”
Correction: In the pooled-depth procedures defined here, the pooled sample is fixed, so the pooled scores and ranks stay fixed. Only the group labels change.
Check Your Understanding
Work through these questions using the definitions and results above.
- For two groups, what does a positive value of \(W_1-n_1(N+1)/2\) say about group 1’s pooled depth ranks?
- State the null hypothesis that justifies the finite-sample permutation calibration for independent groups.
- For three groups with distinct pooled ranks, explain why \(H_R\) and \(B_R\) yield the same ordering of label assignments.
- Why is equality of the groups’ depth-score distributions not, in general, enough to justify permutation of the original vectors?
- What kind of group difference can a large \(T_D\) indicate that a comparison of mean ranks may summarize less directly?