Abstract
In an extension of Kendall's $\tau$, Bergsma and Dassios (2014) introduced a covariance measure $\tau^*$ for two ordinal random variables that vanishes if and only if the two variables are independent. For a sample of size $n$, a direct computation of $t^*$, the empirical version of $\tau^*$, requires $O(n^4)$ operations. We derive an algorithm that computes the statistic using only $O(n^2\log(n))$ operations.
Introduction
Detecting dependence between variables is a fundamental task in statistics. While traditional measures like Kendall’s $\tau$ or Spearman’s $\rho$ are effective for monotonic relationships, they often fail to detect more complex, non-linear forms of dependence. The Bergsma-Dassios sign covariance ($\tau^*$) addresses this limitation, as it is zero if and only if the variables are independent. However, the empirical estimator $t^*$ is a U-statistic of order 4, meaning a naive calculation requires $O(n^4)$ time—an impossible feat for modern datasets. This paper presents a breakthrough algorithm that reduces this complexity to $O(n^2 \log n)$, making the statistic practical for large-scale use.
Geometric Interpretation of Sign Covariance
The $t^*$ statistic is calculated by examining quadruples of data points. Each quadruple is classified based on the relative geometric positions of its points in the plane. Specifically, configurations are categorized as concordant, discordant, or inseparable.
In the case of no ties, $t^*$ can be determined solely by counting concordant quadruples. However, the $O(n^4)$ requirement to check every combination makes this approach unscalable without algorithmic optimization. The core "aha!" moment of this research is realizing that the complex sign covariance function can be broken down into simpler counts of points falling into specific quadrants relative to each other.
The $O(n^2 \log n)$ Algorithm
The authors' key innovation is transforming the quadruple-counting problem into a more efficient sorting and searching task. The algorithm sorts the data by one variable and then iterates through pairs of points $(k, l)$. By using a balanced binary search tree (specifically a red-black tree) to manage the second variable, the algorithm can query the number of points satisfying concordance conditions in $O(\log n)$ time per pair, rather than the linear time required by a naive search.
Handling Ties in Real-World Data
Real-world datasets frequently contain duplicate values, or "ties," which complicates the counting process. The authors introduce a two-pass algorithm to handle these "inseparable" points. This involves a geometric decomposition of the plane into specific regions relative to the points being processed.
This spatial partitioning allows the algorithm to maintain its $O(n^2 \log n)$ efficiency even when the data is not perfectly continuous. The first pass counts most quantities, while a second pass in reverse order corrects for over-counted discordant quadruples.
Performance and Results
Benchmarking on simulated datasets demonstrates the algorithm's transformative impact. For a sample size of $n=300$, the computation time is reduced from nearly 29 seconds to just 0.01 seconds. The algorithm scales gracefully, processing $n=10,000$ observations in approximately 19 seconds—a task that would take years using the naive $O(n^4)$ method.
Furthermore, the exact calculation provided by this algorithm is significantly more reliable than Monte-Carlo subsampling. Subsampling methods, while faster, exhibit high variance, which can lead to inconsistent results in scientific testing. The $O(n^2 \log n)$ algorithm provides the precision of the full statistic with manageable computational overhead.
Conclusion
By providing an $O(n^2 \log n)$ algorithm, this work removes the primary barrier to using the Bergsma-Dassios sign covariance in practice. The implementation is available in the R package TauStar, enabling researchers to perform robust independence tests on datasets with thousands of observations. While $O(n^2)$ remains a challenge for truly massive datasets, this improvement represents a significant leap forward in non-parametric statistics.
Summary updated