The package HausdorffGoF computes the test statistic and p-values of the one-sample and two-sample Hausdorff (H) goodness-of-fit tests proposed by Dimitrova, Jia, and Kaishev (2026a, 2026b).
The H statistic measures the Hausdorff distance between the completed graphs of two cumulative distribution functions (cdfs) under the Chebyshev (l∞) metric. Geometrically, it equals the side length of the largest axis-aligned square (or hypercube in higher dimensions) that can be inscribed in the region between the two cdf curves. Three testing settings are covered:
A key advantage of the H test is its scale-dependence, which allows targeting its sensitivity to either the tails or body of the distribution, leading to improving its statistical power. Empirical results show that in terms of statistical power, the H test significantly outperforms classical goodness-of-fit tests such as Kolmogorov-Smirnov, Cramér-von Mises, and Anderson-Darling tests, making it highly attractive for practical applications, especially in areas where the tail behavior is targeted.
The full package vignette can be found here.
The package is available on CRAN and can be installed with:
install.packages("HausdorffGoF")
To install the latest development version from GitHub:
# install.packages("remotes")
# remotes::install_github("fakecloudsjy/HausdorffGoF")
install.packages("HausdorffGoF", repos = c('https://fakecloudsjy.r-universe.dev', 'https://cloud.r-project.org'))
Building from source requires a C++ compiler. On Windows, install Rtools; on macOS, install Xcode Command Line Tools (xcode-select --install).
library(HausdorffGoF)
# Bundle CDF, quantile function, and density into a NullDist object
null_exp <- distribution(
CDF = function(t) pexp(t, rate = 1),
CDFinverse = function(p) qexp(p, rate = 1),
pdf = function(t) dexp(t, rate = 1)
)
set.seed(1)
x <- rexp(50, rate = 1)
# Exact p-value
Hausdorff_test(x, null_exp)
# Scale-tuned: focus power on the right tail
Hausdorff_test(x, null_exp, scale_psi = c(0.99, 0.95))
set.seed(2)
x1 <- rnorm(40)
x2 <- rnorm(40, mean = 0.5)
# Monte Carlo permutation (default)
Hausdorff_test(x1, x2)
# Exact permutation (small samples)
Hausdorff_test(rnorm(8), rnorm(8), method = "exact")
# Scale-tuned: focus on right tail
Hausdorff_test(x1, x2, scale_psi = c(0.99, 0.95))
set.seed(3)
xm <- matrix(rnorm(100), ncol = 2)
ym <- matrix(rnorm(100, mean = 0.5), ncol = 2)
# Monte Carlo permutation
Hausdorff_test(xm, ym, nboots = 1000)
# Order-invariant statistic
Hausdorff_test(xm, ym, nboots = 1000, invariant = TRUE)
# One-sample
Hausdorff_stat(x, null_exp)
# Two-sample univariate
Hausdorff_stat(x1, x2)
# Two-sample bivariate
Hausdorff_stat(xm, ym)
| Function | Description |
|---|---|
Hausdorff_test() |
Unified S3 generic: one-sample, two-sample univariate, and bivariate H test |
Hausdorff_stat() |
Unified S3 generic: computes the H statistic without a p-value |
distribution() |
Constructs a NullDist object bundling CDF, quantile function, and density |
H_stat_1s_1d() |
One-sample H statistic (Algorithm 1, Dimitrova et al. 2026a) |
H_test_1s_1d() |
One-sample H test with exact p-value |
H_test_c_cdf() |
Low-level rectangle-probability p-value engine |
H_stat_2s_1d_tr() |
Two-sample univariate H statistic via transformation method (C++) |
H_stat_2s_1d_p() |
Two-sample univariate H statistic via projection method (C++) |
H_test_2s_1d() |
Two-sample univariate H test (exact or Monte Carlo permutation) |
H_stat_2s_2d() |
Two-sample bivariate H statistic (projection method, C++) |
H_test_2s_2d() |
Two-sample bivariate H test (exact or Monte Carlo permutation) |
One-sample exact p-values are expressed as a rectangle-crossing probability for uniform order statistics (Theorem 4, Dimitrova et al. 2026a) and evaluated in O(n² log n) time using the Exact-KS-FFT method of Dimitrova, Kaishev, and Tan (2020) via the KSgeneral package.
Two-sample p-values are computed by permutation (Proposition 3.5, Dimitrova et al. 2026b): exact enumeration of all C(m+n, m) splits for small samples, or Monte Carlo permutation otherwise.
Scale tuning via the scale_psi = c(ψ₁, ψ₂) argument computes the optimal scale σ* = (ψ₁ − ψ₂) / (F⁻¹(ψ₁) − F⁻¹(ψ₂)) and rescales the data before testing, directing power towards the left tail (c(0.05, 0.01)), body (c(0.70, 0.40)), or right tail (c(0.99, 0.95)).
Bivariate empirical cdf computation uses the fast divide-and-conquer algorithm of Langrené and Warin (2021), achieving O(N log² N) complexity, implemented via C++ code from the StOpt library (Copyright © 2020 EDF, LGPL-3).
If you use HausdorffGoF in a publication, please cite:
One-sample H test:
Dimitrina S. Dimitrova, Yun Jia, Vladimir K. Kaishev (2026a). "On a One Sample Goodness-of-fit Test Based on the Hausdorff Metric". Submitted.
Two-sample H test:
Dimitrina S. Dimitrova, Yun Jia, Vladimir K. Kaishev (2026b). "On a Two-Sample Multivariate Goodness-of-Fit Test Based on the Hausdorff Metric". Submitted.
GPL (≥ 3). See LICENSE for details.
This package includes C++ source code from the StOpt library (Copyright © 2020 EDF — Électricité de France), used under the GNU Lesser General Public License v3 (LGPL-3). Full copyright notices are available in inst/COPYRIGHTS.