Papers
Topics
Authors
Recent
Search
2000 character limit reached

MD2sample: R Package for Two-Sample Testing

Updated 7 July 2026
  • MD2sample is an R package for nonparametric multivariate two-sample testing designed to compare distributions in continuous and discrete data.
  • It integrates complementary methods—including EDF, distance-based, graph-based, and kernel tests—to robustly detect differences in dependence and marginal shifts.
  • The package supports extensive simulation studies, enabling systematic power evaluations and the incorporation of user-defined tests via efficient computational techniques.

Searching arXiv for the supplied MD2sample-related papers and closely related records. MD2sample is an R package for nonparametric multivariate two-sample testing, designed to run and compare a large collection of tests for continuous and discrete data and to support systematic power studies across diverse alternatives (Rolke, 12 May 2026). In the two-sample framework, one observes independent samples X1,,XnFX_1,\dots,X_n \sim F and Y1,,YmGY_1,\dots,Y_m \sim G, with the null hypothesis H0:F=GH_0: F = G against the general alternative H1:FGH_1: F \neq G (Rolke, 22 Jul 2025). The package is positioned around a central empirical conclusion: for multivariate data, no single method can be relied upon to provide good power uniformly across all alternatives, so MD2sample emphasizes breadth of methodology, comparative evaluation, and short lists of complementary tests (Rolke, 12 May 2026).

1. Statistical setting and motivation

MD2sample addresses the multivariate nonparametric two-sample problem in settings where reliable parametric models for FF and GG are unavailable or undesirable (Rolke, 22 Jul 2025). The package is intended for continuous data in arbitrary dimension and for discrete data in two dimensions, including binned or histogram representations (Rolke, 12 May 2026). The associated power studies explicitly examine d=2d=2 and d=5d=5 continuous settings and $2$-dimensional discrete settings (Rolke, 12 May 2026).

The methodological motivation is the heterogeneity of alternatives. Differences between FF and Y1,,YmGY_1,\dots,Y_m \sim G0 may appear in marginals, dependence, covariance structure, local clustering, or mixture composition (Rolke, 22 Jul 2025). The supplied studies distinguish cases with equal marginals, where only dependence changes, from cases with unequal marginals, where mean, variance, or marginal family changes occur (Rolke, 12 May 2026). This distinction matters because univariate marginal tests can completely miss dependence changes, especially in the “D2” and “D5” classes of scenarios described in the studies (Rolke, 22 Jul 2025).

A further motivation is that multivariate methods differ materially in what they detect well. EDF-based procedures may respond strongly to marginal differences; distance- and graph-based methods may be more effective for dependence changes or local structure; chi-square procedures can be strong when binning captures relevant features (Rolke, 12 May 2026). This suggests that MD2sample is less a single test than a comparative framework for selecting and combining tests with complementary sensitivity profiles.

2. Scope of the package and computational design

MD2sample is available on CRAN and is designed to provide a large collection of multivariate two-sample tests in a unified framework (Rolke, 22 Jul 2025). Its stated purposes include two-sample testing for multivariate data, support for power studies and simulation experiments, and the ability to combine multiple tests with multiplicity-corrected Y1,,YmGY_1,\dots,Y_m \sim G1-values (Rolke, 22 Jul 2025). The package also allows the addition of user-defined tests for comparison in simulation workflows (Rolke, 12 May 2026).

For continuous data, MD2sample implements EDF-based, nearest-neighbor, energy- or distance-based, graph-based, Ball divergence, and binning-based chi-square procedures (Rolke, 22 Jul 2025). For discrete data, it includes discrete analogues of KS, Kuiper, CvM, AD, nearest-neighbor methods, Aslan–Zech, Baringhaus–Franz, and a chi-square test on discrete cell counts (Rolke, 22 Jul 2025). In the broader workflow described in the 2026 paper, MD2sample is also used as the two-sample engine for hybrid goodness-of-fit tests in combination with MDgof, where a Monte Carlo sample from a fitted null model is compared to observed data (Rolke, 12 May 2026).

Implementation emphasizes computational practicality. The package uses Rcpp and parallel programming to handle computationally demanding distance calculations, graph constructions, permutations, and repeated simulations (Rolke, 12 May 2026). For some procedures, large-sample formulas or asymptotic approximations are used instead of full permutation calibration, which is particularly relevant for very large datasets (Rolke, 22 Jul 2025). Permutation tests are used for Y1,,YmGY_1,\dots,Y_m \sim G2-value computation for essentially all two-sample methods in the 2026 description unless otherwise stated, while the 2025 description identifies asymptotic or large-sample calibration for chi-square, FR, CF1–CF4, Ball divergence, and NN0 (Rolke, 12 May 2026, Rolke, 22 Jul 2025). This difference in emphasis reflects the package’s dual role as both a simulation platform and an applied testing toolkit.

3. Families of tests implemented in MD2sample

MD2sample collects several distinct classes of nonparametric two-sample procedures, each defined by a different representation of discrepancy between Y1,,YmGY_1,\dots,Y_m \sim G3 and Y1,,YmGY_1,\dots,Y_m \sim G4 (Rolke, 22 Jul 2025).

EDF-based tests

For empirical distribution functions Y1,,YmGY_1,\dots,Y_m \sim G5, Y1,,YmGY_1,\dots,Y_m \sim G6, and pooled Y1,,YmGY_1,\dots,Y_m \sim G7, MD2sample implements multivariate versions of Kolmogorov–Smirnov, Kuiper, Cramér–von Mises, and Anderson–Darling (Rolke, 22 Jul 2025). In the pooled-support formulation reported in the studies, the statistics are

Y1,,YmGY_1,\dots,Y_m \sim G8

Y1,,YmGY_1,\dots,Y_m \sim G9

H0:F=GH_0: F = G0

H0:F=GH_0: F = G1

The studies report that these EDF-type tests tend to work well for simple differences in distribution, especially when marginals differ, but can be weaker for pure dependence changes when marginals are equal (Rolke, 12 May 2026).

Nearest-neighbor procedures

Nearest-neighbor procedures in MD2sample include NN1, NN5, and a simple nearest-neighbor test denoted NN0 or NN (Rolke, 22 Jul 2025). For NN1 and NN5, each observation’s H0:F=GH_0: F = G2 nearest neighbors in the pooled sample are examined, and the statistic is based on the average number of same-sample neighbors for both samples (Rolke, 22 Jul 2025, Rolke, 12 May 2026). Under H0:F=GH_0: F = G3, labels are exchangeable; under H0:F=GH_0: F = G4, within-sample clustering increases the statistic (Rolke, 12 May 2026). The simple nearest-neighbor test counts points in the first sample whose nearest neighbor is also in the first sample and uses an approximate binomial distribution under H0:F=GH_0: F = G5 for large samples (Rolke, 22 Jul 2025).

These tests are described as particularly sensitive to local clustering differences and dependence changes, and NN5 is repeatedly identified as a stable compromise between locality and variance (Rolke, 12 May 2026).

Energy- and distance-based tests

The package implements the Aslan–Zech, Baringhaus–Franz, and Biswas–Ghosh tests (Rolke, 22 Jul 2025). Using Euclidean distance H0:F=GH_0: F = G6, the Aslan–Zech statistic is

H0:F=GH_0: F = G7

the Baringhaus–Franz statistic is

H0:F=GH_0: F = G8

and the Biswas–Ghosh statistic is based on

H0:F=GH_0: F = G9

H1:FGH_1: F \neq G0

with

H1:FGH_1: F \neq G1

These procedures compare cross-sample and within-sample distances in different ways (Rolke, 22 Jul 2025). The studies characterize AZ as very strong in H1:FGH_1: F \neq G2D continuous settings and BG as particularly designed to work well in higher dimensions, including cases where other tests lose power (Rolke, 12 May 2026).

Kernel-based testing via MMD

The 2026 study adds a kernel-based procedure, Maximum Mean Discrepancy, to the MD2sample-centered comparison (Rolke, 12 May 2026). For a positive definite kernel H1:FGH_1: F \neq G3,

H1:FGH_1: F \neq G4

with unbiased empirical estimator

H1:FGH_1: F \neq G5

MD2sample is described there as implementing an aggregated MMD using H1:FGH_1: F \neq G6 different bandwidths, usually Gaussian kernels with different H1:FGH_1: F \neq G7, following the “MMD aggregated two-sample test” of Schrab et al. 2023 (Rolke, 12 May 2026). In that study, MMD is identified as the single best general-purpose two-sample test for continuous data (Rolke, 12 May 2026).

Graph-based and ball-based procedures

MD2sample includes the Friedman–Rafsky MST test, Chen–Friedman tests CF1–CF4 via the gTests methodology, and Ball divergence via the Ball package (Rolke, 22 Jul 2025). Friedman–Rafsky constructs the minimum spanning tree on the pooled sample and evaluates how strongly the labels mix across edges; Chen–Friedman procedures use graph counts on MST or H1:FGH_1: F \neq G8-nearest-neighbor-type constructions; Ball divergence compares distributions of distances inside metric balls (Rolke, 22 Jul 2025, Rolke, 12 May 2026). These are omnibus procedures and are reported as competitive in complex shape and dependence changes, with CF2 sometimes strong in certain Dalitz-type or structured alternatives (Rolke, 12 May 2026).

Chi-square and discrete variants

For H1:FGH_1: F \neq G9-dimensional data, MD2sample includes chi-square tests based on equal-size or equal-probability binning, typically FF0 in the reported studies (Rolke, 22 Jul 2025). For pooled cell counts FF1, sample totals FF2, FF3, and FF4, the statistic given in the 2026 study is

FF5

The package merges bins until each contains at least FF6 observations from the combined sample to satisfy chi-square validity, and the papers note that power is often maximized using a relatively small number of bins, regardless of sample size (Rolke, 22 Jul 2025). Discrete analogues of EDF, nearest-neighbor, and energy tests are also implemented for FF7D discrete data (Rolke, 12 May 2026).

4. Simulation studies and empirical evaluation

The empirical characterization of MD2sample is grounded in extensive simulation studies (Rolke, 12 May 2026). The 2025 paper reports FF8 case studies in FF9D, together with GG0D discrete and GG1D continuous scenarios (Rolke, 22 Jul 2025). The 2026 paper broadens the discussion to goodness-of-fit as well as two-sample settings and explicitly states that the studies were carried out using MD2sample and MDgof (Rolke, 12 May 2026).

The simulated alternatives cover multivariate normal and GG2 families, uniform distributions on rectangles, copulas including Frank, Clayton, Gumbel, Galambos, Joe, Husler–Reiss, and mixtures, as well as Dalitz plot examples motivated by high-energy physics (Rolke, 12 May 2026, Rolke, 22 Jul 2025). The case taxonomy distinguishes equal-marginal dependence changes from unequal-marginal alternatives such as mean shifts, variance changes, or changes in marginal family (Rolke, 22 Jul 2025). Discrete scenarios are produced either intrinsically or by binning continuous scenarios into GG3 grids (Rolke, 12 May 2026).

The studies target nominal significance level GG4 (Rolke, 12 May 2026). For the 2026 power comparisons, typical sample sizes are GG5 or GG6, with GG7 used for reported power comparisons, and the alternative parameters are chosen so that the best method reaches approximately GG8–GG9 power at d=2d=20 (Rolke, 12 May 2026). Thousands of replications per scenario are used to estimate power reliably, and rejection frequencies are summarized both as mean power across scenarios and as the proportion of scenarios in which a method is within d=2d=21 of the best power for that scenario (Rolke, 12 May 2026, Rolke, 22 Jul 2025).

A central methodological conclusion is repeated across both papers: there is no universally best test (Rolke, 12 May 2026, Rolke, 22 Jul 2025). A method can be excellent for mean shifts and poor for subtle dependence changes, or superb on some copula alternatives and almost powerless on others (Rolke, 22 Jul 2025). MD2sample’s comparative structure is therefore integral to its purpose rather than an accessory feature.

The reported recommendations depend on data type and dimension.

For continuous d=2d=22-dimensional data, the 2026 study reports mean power d=2d=23 for MMD, d=2d=24 for AZ, d=2d=25 for ES chi-square, d=2d=26 for EP chi-square, d=2d=27 for BF, d=2d=28 for AD, d=2d=29 for NN5, d=5d=50 for CvM, d=5d=51 for Ball, and d=5d=52 for FR, CF1, and CF3 (Rolke, 12 May 2026). The corresponding “percentage close to best” values are d=5d=53 for MMD, d=5d=54 for AZ, d=5d=55 for ES, d=5d=56 for EP, and d=5d=57 for BF (Rolke, 12 May 2026). The same paper therefore characterizes MMD as the single most consistently powerful method in d=5d=58D and AZ as the second-best, while noting that BG remains useful in specific scenarios such as complex Dalitz-type shapes (Rolke, 12 May 2026).

The 2025 study, which predates the inclusion of MMD in the summarized comparison, gives a different ranking for continuous cases: AZ d=5d=59, ES $2$0, EP $2$1, BF $2$2, AD $2$3, NN5 $2$4, CvM $2$5, KS $2$6, and Ball $2$7, with BG at $2$8 mean power but sometimes essential (Rolke, 22 Jul 2025). In that study AZ is within $2$9 of the best power in FF0 of cases, far above other methods (Rolke, 22 Jul 2025). This suggests that AZ was the most robust performer among the then-compared methods, whereas the 2026 study’s addition of aggregated MMD shifts the overall default recommendation toward MMD for continuous data.

For continuous FF1-dimensional data, the 2026 study reports mean power FF2 for MMD, FF3 for AZ, FF4 for BF, FF5 for AD, FF6 for Ball, FF7–FF8 for KS, CvM, K, and NN5, and FF9 for BG (Rolke, 12 May 2026). Despite BG’s modest mean power, the smallest set of methods such that for every scenario at least one is best is reported as BG + MMD + NN5 (Rolke, 12 May 2026). The interpretation given is that MMD dominates on average, while BG and NN5 are essential for certain pathological or high-dimensional alternatives (Rolke, 12 May 2026).

For equal marginals, where only dependence changes, graph- and distance-based tests such as MMD, AZ, BG, NN5, and FR generally outperform EDF types (Rolke, 12 May 2026). With unequal marginals, EDF tests and binning-based chi-square become more competitive, but MMD and AZ remain very strong (Rolke, 12 May 2026).

For Y1,,YmGY_1,\dots,Y_m \sim G00-dimensional discrete data, the 2026 study reports mean power Y1,,YmGY_1,\dots,Y_m \sim G01 for chi-square, Y1,,YmGY_1,\dots,Y_m \sim G02 for NN, Y1,,YmGY_1,\dots,Y_m \sim G03 for AD, Y1,,YmGY_1,\dots,Y_m \sim G04 for Kuiper, Y1,,YmGY_1,\dots,Y_m \sim G05 for KS and CvM, and Y1,,YmGY_1,\dots,Y_m \sim G06 and Y1,,YmGY_1,\dots,Y_m \sim G07 for AZ and BF respectively (Rolke, 12 May 2026). The 2025 study gives closely aligned figures: chi-square Y1,,YmGY_1,\dots,Y_m \sim G08, NN Y1,,YmGY_1,\dots,Y_m \sim G09, AD Y1,,YmGY_1,\dots,Y_m \sim G10, K Y1,,YmGY_1,\dots,Y_m \sim G11, KS Y1,,YmGY_1,\dots,Y_m \sim G12, CvM Y1,,YmGY_1,\dots,Y_m \sim G13, AZ Y1,,YmGY_1,\dots,Y_m \sim G14, and BF Y1,,YmGY_1,\dots,Y_m \sim G15 (Rolke, 22 Jul 2025). Both sources therefore identify chi-square as clearly strongest on average for the studied discrete problems (Rolke, 12 May 2026, Rolke, 22 Jul 2025).

The recommendations in the two papers differ in detail. The 2025 study recommends for continuous data the set AZ, chi-square with small number of bins (ES, Y1,,YmGY_1,\dots,Y_m \sim G16 in Y1,,YmGY_1,\dots,Y_m \sim G17D), AD, NN5, and BG; for discrete data it recommends chi-square, AZ, CvM, and KS (Rolke, 22 Jul 2025). The 2026 study recommends for two-sample continuous Y1,,YmGY_1,\dots,Y_m \sim G18 data AZ, BG, and MMD; for continuous Y1,,YmGY_1,\dots,Y_m \sim G19, BG, MMD, and NN5; and for discrete Y1,,YmGY_1,\dots,Y_m \sim G20, AZ, AD, Kuiper, and chi-square (Rolke, 12 May 2026). The difference reflects the broader method set and updated comparative evidence in the later paper.

6. Practical use, limitations, and relation to adjacent tools

The studies describe a standard MD2sample workflow. For continuous data, inputs are matrices Y1,,YmGY_1,\dots,Y_m \sim G21 and Y1,,YmGY_1,\dots,Y_m \sim G22 of sizes Y1,,YmGY_1,\dots,Y_m \sim G23 and Y1,,YmGY_1,\dots,Y_m \sim G24; for discrete Y1,,YmGY_1,\dots,Y_m \sim G25D data, inputs may be count vectors together with bin centers or cell coordinates (Rolke, 12 May 2026). Tests compute the chosen statistic, generate Y1,,YmGY_1,\dots,Y_m \sim G26-values by permutation or large-sample calibration as appropriate, and can be embedded in repeated simulation loops for type I error and power estimation (Rolke, 22 Jul 2025, Rolke, 12 May 2026). The package contains built-in case studies and stored power-study results, and it supports test combination with multiplicity correction (Rolke, 22 Jul 2025, Rolke, 12 May 2026).

The reported guidance is pragmatic. If a single default test is needed for continuous data, the 2026 study recommends MMD (Rolke, 12 May 2026). If robustness across alternatives is the goal, the recommendation is to run a small complementary panel such as MMD + BG + AZ in Y1,,YmGY_1,\dots,Y_m \sim G27D or MMD + BG + NN5 in Y1,,YmGY_1,\dots,Y_m \sim G28D or higher, optionally combining Y1,,YmGY_1,\dots,Y_m \sim G29-values (Rolke, 12 May 2026). For discrete Y1,,YmGY_1,\dots,Y_m \sim G30D data, chi-square is the default, complemented by AD and Kuiper, with AZ as an optional addition (Rolke, 12 May 2026). The 2025 study similarly advises applying a battery of tests rather than relying on one method, especially when local structure, covariance stretch, or dependence changes are plausible (Rolke, 22 Jul 2025).

Several limitations are explicit. The systematic simulations extend only to Y1,,YmGY_1,\dots,Y_m \sim G31, so performance in much higher dimensions remains unstudied in these papers (Rolke, 12 May 2026). Discrete methods are implemented only for Y1,,YmGY_1,\dots,Y_m \sim G32D because higher-dimensional binning rapidly becomes impractical (Rolke, 12 May 2026). The discrete conclusions are specific to the chosen Y1,,YmGY_1,\dots,Y_m \sim G33 equal-size or related binning schemes, and the 2025 paper explicitly cautions that some methods, notably AZ, may have much better power under different binning choices (Rolke, 22 Jul 2025). Sample-size imbalance is not deeply explored, and computational cost remains nontrivial for full distance matrices, MST construction, and repeated permutations on large samples (Rolke, 22 Jul 2025, Rolke, 12 May 2026).

MD2sample is also closely related to MDgof. In the 2026 study, MD2sample serves as the two-sample testing engine for hybrid goodness-of-fit procedures in which an observed sample is compared to a Monte Carlo sample from a fitted null model, with MC sample sizes equal to the data size or five times larger (Rolke, 12 May 2026). This places MD2sample at the intersection of classical two-sample testing and simulation-based goodness-of-fit assessment.

Taken together, the supplied papers define MD2sample as a research-oriented package whose distinguishing feature is not merely the number of implemented tests, but the empirical program accompanying them: a large simulation library, explicit power comparisons, and concrete short-list recommendations that acknowledge the absence of any uniformly dominant multivariate two-sample procedure (Rolke, 12 May 2026, Rolke, 22 Jul 2025).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to MD2sample.