<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.2 20190208//EN"
                  "JATS-archivearticle1.dtd">
<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="1.2" article-type="other">
<front>
<journal-meta>
<journal-id journal-id-type="publisher-id">jrepstat</journal-id>
<journal-title-group>
<journal-title>Journal of Reproducible Statistics</journal-title>
</journal-title-group>
<publisher>
<publisher-name>FAIR Press</publisher-name>
</publisher>
</journal-meta>
<article-meta>
<title-group>
<article-title>A Computational Framework for Multivariate Goodness-of-Fit and Two-Sample Testing: MDgof and MD2sample</article-title>
</title-group>
<contrib-group>
<contrib contrib-type="author">
<contrib-id contrib-id-type="orcid">https://orcid.org/0000-0002-3514-726X</contrib-id>
<name>
<surname>Rolke</surname>
<given-names>Wolfgang</given-names>
</name>
<aff>Department of Mathematical Sciences, University of Puerto Rico at Mayagüez, Mayagüez, Puerto Rico 00681, USA</aff>
</contrib>
</contrib-group>
<pub-date date-type="pub" publication-format="electronic">
<year>2026</year>
</pub-date>
<volume>1</volume>
<elocation-id>8</elocation-id>
<history>
<date date-type="received" iso-8601-date="2026-10-12"><day>12</day><month>10</month><year>2026</year></date>
<date date-type="accepted" iso-8601-date="2026-10-23"><day>23</day><month>10</month><year>2026</year></date>
</history>
<permissions>
<license license-type="open-access" xlink:href="https://creativecommons.org/licenses/by/4.0/">
<license-p>This is an open access article distributed under the terms of the Creative Commons Attribution 4.0 International License (CC-BY 4.0), which permits unrestricted use, distribution and reproduction in any medium provided the original work is properly cited.</license-p>
</license>
</permissions>
<self-uri content-type="html" xlink:href="https://jrepstat.fairpressjournals.com/articles/a-computational-framework-for-multivariate-goodness-of-fit-and-two-sample-testing-mdgof-and-md2sample/"/>
<abstract>
<p>Multivariate goodness-of-fit and nonparametric two-sample testing comprise a large collection of procedures whose relative performance can depend strongly on the alternative distribution, dimension, sample size, and treatment of nuisance parameters. Systematic comparison is difficult when methods are implemented through different interfaces and require separate simulation code. We present a unified computational framework for implementing, comparing, benchmarking, and extending multivariate goodness-of-fit and two-sample procedures, implemented in the MDgof and MD2sample packages for R. The framework supports continuous and discrete data, simple and composite null hypotheses, simulation-based inference, adjusted p values for simultaneous testing, power estimation, user-defined test statistics, and large collections of benchmark alternatives. A parallel application programming interface is used across the two packages so that workflows learned for one testing problem transfer directly to the other. Computationally intensive components use Rcpp and parallel processing where appropriate. The resulting framework provides reusable statistical-computing infrastructure for applied testing and for reproducible Monte Carlo comparison of existing and newly proposed multivariate procedures.</p>
</abstract>
<kwd-group kwd-group-type="author">
<kwd>goodness-of-fit</kwd>
<kwd>two-sample tests</kwd>
<kwd>multivariate data</kwd>
<kwd>benchmarking</kwd>
<kwd>power studies</kwd>
<kwd>R</kwd>
</kwd-group>
<custom-meta-group>
<custom-meta>
<meta-name>data-availability-route</meta-name>
<meta-value>open</meta-value>
</custom-meta>
<custom-meta>
<meta-name>founding-article</meta-name>
<meta-value>true</meta-value>
</custom-meta>
</custom-meta-group>
</article-meta>
</front>
<body>
<sec id="introduction">
  <title>Introduction</title>
  <p>Multivariate goodness-of-fit and nonparametric two-sample testing
  are fundamental statistical problems. In the goodness-of-fit problem,
  observations are compared with a specified probability model; in the
  two-sample problem, two independent samples are compared without
  specifying their common distribution under the null hypothesis. Both
  problems arise in many scientific settings and have generated a large
  literature of procedures based on empirical distribution functions,
  nearest neighbors, graphs, kernels, energy-type distances,
  characteristic functions, and multivariate depth; see, for example,
  Thas (2010) and Rayner et al. (2009).</p>
  <p>The practical difficulty is not a shortage of tests but the absence
  of a uniformly best procedure. Power can change substantially with the
  form of the alternative, dimension, sample size, and whether nuisance
  parameters are estimated. Consequently, an applied analyst may wish to
  compare several procedures, while a methodological researcher
  proposing a new statistic must evaluate it against established
  competitors over many alternatives. When implementations are
  distributed among packages with different interfaces, data
  conventions, output formats, and resampling schemes, such comparisons
  require substantial additional programming and can be difficult to
  reproduce.</p>
  <p>The <named-content content-type="sans-serif">MDgof</named-content>
  and <named-content content-type="sans-serif">MD2sample</named-content>
  packages (Rolke, 2026b, 2026a) address this computational problem
  through a common framework for multivariate goodness-of-fit and
  two-sample testing. The principal contribution is a common
  computational framework in which existing and newly proposed
  statistics can be implemented, calibrated, compared, and benchmarked
  under common conditions. The framework supports continuous and
  discrete data, simple and composite null hypotheses, hybrid
  goodness-of-fit problems based on simulated reference samples,
  simultaneous inference, Monte Carlo power studies, and systematic
  benchmarking. The computational contribution is the integration of
  these tasks in a single extensible workflow, so that calibration and
  comparative simulation need not be reimplemented separately for each
  statistic.</p>
  <p>Four design features are central. First, built-in procedures are
  exposed through common testing and power interfaces rather than
  unrelated method-specific functions. Second, user-defined statistics
  can be inserted into the same resampling and benchmarking machinery
  used by the built-in procedures. Third, the packages provide
  collections of simulation scenarios so that competing procedures can
  be evaluated under identical alternatives and sample sizes. Fourth,
  <named-content content-type="sans-serif">MDgof</named-content> and
  <named-content content-type="sans-serif">MD2sample</named-content>
  deliberately use parallel names for analogous user-facing operations.
  This is an interface-design choice: a user who has learned the
  workflow for one testing problem can transfer that knowledge to the
  other without learning a second vocabulary. Simultaneous attachment of
  both packages is not required; namespace-qualified calls such as
  <monospace>MDgof::gof_test()</monospace> and
  <monospace>MD2sample::twosample_test()</monospace> remain
  unambiguous.</p>
  <p>Computationally intensive components use
  <named-content content-type="sans-serif">Rcpp</named-content>
  (Eddelbuettel et al., 2024) and parallel processing where appropriate.
  The packages also give explicit attention to multivariate discrete
  data, for which general-purpose software is less extensive than for
  continuous data. This makes it possible to use the same overall
  computational strategy for continuous observations, discrete count
  representations, and simulation-based hybrid problems.</p>
  <p>The present work builds on the computational approach developed for
  the univariate goodness-of-fit and two-sample problems in the
  <named-content content-type="sans-serif">R</named-content> packages
  <named-content content-type="sans-serif">Rgof</named-content> and
  <named-content content-type="sans-serif">R2sample</named-content>
  (Rolke, 2025). MDgof and MD2sample extend this approach to
  multivariate problems, for which the available test statistics, data
  representations, and computational requirements are substantially
  different. The four packages nevertheless share a similar workflow for
  testing, power estimation, user-defined procedures, and comparative
  simulation.</p>
  <p>The remainder of the paper is organized around the computational
  framework. Section 2 defines the statistical settings handled by the
  software. Section 3 summarizes the implemented procedures and their
  relation to existing software. Sections 4–7 describe simultaneous
  inference, the common testing interface, extensibility, power
  estimation, and benchmarking. Section 8 discusses computational
  performance, Section 9 gives representative applications, and the
  final section summarizes the role of the framework in methodological
  development and comparative simulation.</p>
</sec>
<sec id="statistical-problems-and-computational-setting">
  <title>Statistical problems and computational setting</title>
  <p>For multivariate goodness-of-fit, let
  <inline-formula><alternatives>
  <tex-math><![CDATA[\mathbf{X}_1,\ldots,\mathbf{X}_n]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:msub><mml:mi mathvariant="bold-italic">𝑿</mml:mi><mml:mn>1</mml:mn></mml:msub><mml:mo>,</mml:mo><mml:mi>…</mml:mi><mml:mo>,</mml:mo><mml:msub><mml:mi mathvariant="bold-italic">𝑿</mml:mi><mml:mi>n</mml:mi></mml:msub></mml:mrow></mml:math></alternatives></inline-formula>
  be observations from an unknown distribution
  <inline-formula><alternatives>
  <tex-math><![CDATA[F]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>F</mml:mi></mml:math></alternatives></inline-formula>.
  The null hypothesis is <disp-formula><alternatives>
  <tex-math><![CDATA[H_0:F=F_0,]]></tex-math>
  <mml:math display="block" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:msub><mml:mi>H</mml:mi><mml:mn>0</mml:mn></mml:msub><mml:mo>:</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:msub><mml:mi>F</mml:mi><mml:mn>0</mml:mn></mml:msub><mml:mo>,</mml:mo></mml:mrow></mml:math></alternatives></disp-formula>
  where <inline-formula><alternatives>
  <tex-math><![CDATA[F_0]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>F</mml:mi><mml:mn>0</mml:mn></mml:msub></mml:math></alternatives></inline-formula>
  may be completely specified or may contain parameters estimated from
  the data. For multivariate two-sample testing, let
  <inline-formula><alternatives>
  <tex-math><![CDATA[\mathbf{X}_1,\ldots,\mathbf{X}_n\sim F]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:msub><mml:mi mathvariant="bold-italic">𝑿</mml:mi><mml:mn>1</mml:mn></mml:msub><mml:mo>,</mml:mo><mml:mi>…</mml:mi><mml:mo>,</mml:mo><mml:msub><mml:mi mathvariant="bold-italic">𝑿</mml:mi><mml:mi>n</mml:mi></mml:msub><mml:mo>∼</mml:mo><mml:mi>F</mml:mi></mml:mrow></mml:math></alternatives></inline-formula>
  and <inline-formula><alternatives>
  <tex-math><![CDATA[\mathbf{Y}_1,\ldots,\mathbf{Y}_m\sim G]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:msub><mml:mi mathvariant="bold-italic">𝒀</mml:mi><mml:mn>1</mml:mn></mml:msub><mml:mo>,</mml:mo><mml:mi>…</mml:mi><mml:mo>,</mml:mo><mml:msub><mml:mi mathvariant="bold-italic">𝒀</mml:mi><mml:mi>m</mml:mi></mml:msub><mml:mo>∼</mml:mo><mml:mi>G</mml:mi></mml:mrow></mml:math></alternatives></inline-formula>
  be independent samples. The null hypothesis is
  <disp-formula><alternatives>
  <tex-math><![CDATA[H_0:F=G.]]></tex-math>
  <mml:math display="block" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:msub><mml:mi>H</mml:mi><mml:mn>0</mml:mn></mml:msub><mml:mo>:</mml:mo><mml:mi>F</mml:mi><mml:mo>=</mml:mo><mml:mi>G</mml:mi><mml:mi>.</mml:mi></mml:mrow></mml:math></alternatives></disp-formula>
  The packages support both continuous multivariate observations and
  discrete data represented through support points and their observed
  counts.</p>
  <p>A useful intermediate case is a goodness-of-fit problem in which
  evaluation of <inline-formula><alternatives>
  <tex-math><![CDATA[F_0]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>F</mml:mi><mml:mn>0</mml:mn></mml:msub></mml:math></alternatives></inline-formula>
  is difficult or unavailable but simulation from the model is feasible.
  A Monte Carlo sample from the fitted or specified null model can then
  be compared with the observed sample using a two-sample statistic. We
  refer to this as the hybrid problem. It is particularly useful for
  models in which generation is straightforward but high-dimensional
  distribution-function or likelihood calculations are computationally
  prohibitive.</p>
  <p>When parameters of <inline-formula><alternatives>
  <tex-math><![CDATA[F_0]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>F</mml:mi><mml:mn>0</mml:mn></mml:msub></mml:math></alternatives></inline-formula>
  are estimated from the observed data, calibration must reproduce the
  estimation step. A permutation calibration that treats the fitted
  distribution as fixed can be inappropriate. The framework therefore
  allows the user to provide an estimator and a null-data generator,
  yielding a parametric-bootstrap calibration in which parameters are
  re-estimated as required. This same separation between the test
  statistic and the data-generating mechanism is important for the power
  and benchmarking routines described below.</p>
  <p>From a computational perspective, the three settings share the same
  basic pipeline: <disp-formula><alternatives>
  <tex-math><![CDATA[\text{data}\longrightarrow
  \text{test statistic(s)}\longrightarrow
  \text{null calibration}\longrightarrow
  p\text{-value(s)}\longrightarrow
  \text{power and benchmarking}.]]></tex-math>
  <mml:math display="block" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mtext mathvariant="normal">data</mml:mtext><mml:mo>→</mml:mo><mml:mtext mathvariant="normal">test statistic(s)</mml:mtext><mml:mo>→</mml:mo><mml:mtext mathvariant="normal">null calibration</mml:mtext><mml:mo>→</mml:mo><mml:mi>p</mml:mi><mml:mtext mathvariant="normal">-value(s)</mml:mtext><mml:mo>→</mml:mo><mml:mtext mathvariant="normal">power and benchmarking</mml:mtext><mml:mi>.</mml:mi></mml:mrow></mml:math></alternatives></disp-formula>
  The software is organized around this pipeline. Differences among
  goodness-of-fit, two-sample, continuous, discrete, and hybrid problems
  are handled primarily through the data representation and
  null-generation mechanism rather than through unrelated user
  workflows.</p>
</sec>
<sec id="implemented-procedures-and-relation-to-existing-software">
  <title>Implemented procedures and relation to existing
  software</title>
  <p>The framework contains a broad collection of classical and recent
  multivariate procedures.
  Tables <xref alt="1" rid="tabU003Amethods-gof">1</xref>
  and <xref alt="2" rid="tabU003Amethods-two-sample">2</xref> summarize
  the methods currently available for goodness-of-fit and two-sample
  analysis, respectively. The purpose of including many methods is not
  to claim that one family dominates the others, but to make procedures
  based on different principles available under a common computational
  interface.</p>
  <table-wrap>
    <caption>
      <p>Goodness-of-fit methods implemented in
      <named-content content-type="sans-serif">MDgof</named-content>.</p>
    </caption>
    <table id="tabU003Amethods-gof">
      <tbody>
        <tr>
          <td align="left"></td>
          <td align="center" colspan="2"><named-content content-type="sans-serif">MDgof</named-content></td>
        </tr>
        <tr>
          <td align="left">Method</td>
          <td align="right">Continuous</td>
          <td align="right">Discrete</td>
        </tr>
        <tr>
          <td align="left">Chi-square tests</td>
          <td align="right">Yes (2D only)</td>
          <td align="right">Yes (2D only)</td>
        </tr>
        <tr>
          <td align="left">Kolmogorov-Smirnov</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Kuiper</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Cramer-von Mises</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Anderson-Darling</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Bickel-Breiman</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left">Bakshaev-Rudzkis</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left">Fasano-Franceschini</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left">Ripley</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left">Total variation</td>
          <td align="right">No</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Kullback–Leibler</td>
          <td align="right">No</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Hellinger</td>
          <td align="right">No</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left"></td>
          <td align="right"></td>
          <td align="right"></td>
        </tr>
      </tbody>
    </table>
  </table-wrap>
  <table-wrap>
    <caption>
      <p>Two-sample methods implemented in
      <named-content content-type="sans-serif">MD2sample</named-content>.</p>
    </caption>
    <table id="tabU003Amethods-two-sample">
      <tbody>
        <tr>
          <td align="left"></td>
          <td align="center" colspan="2"><named-content content-type="sans-serif">MD2sample</named-content></td>
        </tr>
        <tr>
          <td align="left">Method</td>
          <td align="right">Continuous</td>
          <td align="right">Discrete</td>
        </tr>
        <tr>
          <td align="left">Chi-square tests</td>
          <td align="right">Yes (2D only)</td>
          <td align="right">Yes (2D only)</td>
        </tr>
        <tr>
          <td align="left">Kolmogorov-Smirnov</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Kuiper</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Cramer-von Mises</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Anderson-Darling</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">nearest-neighbor</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Aslan-Zech</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Biswas-Ghosh</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left">Baringhaus-Franz</td>
          <td align="right">Yes</td>
          <td align="right">Yes</td>
        </tr>
        <tr>
          <td align="left">Maximum mean discrepancy</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left">Friedman–Rafsky</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left">Simple 1-Nearest Neighbor</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left">Chen-Friedman</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left">Ball divergence</td>
          <td align="right">Yes</td>
          <td align="right">No</td>
        </tr>
        <tr>
          <td align="left"></td>
          <td align="right"></td>
          <td align="right"></td>
        </tr>
      </tbody>
    </table>
  </table-wrap>
  <p>The implemented statistics span several methodological families.
  Empirical-distribution-function procedures include multivariate
  versions or approximations to Kolmogorov–Smirnov, Kuiper, Cramér–von
  Mises, and Anderson–Darling statistics (Anderson, 1962; Anderson &amp;
  Darling, 1952; Cramér, 1928; Kolmogorov, 1933; Kuiper, 1960; Mises,
  1928; Pettitt, 1976; Smirnov, 1939). For continuous multivariate
  goodness-of-fit, the empirical-distribution-function statistics are
  evaluated at the observed data points; this avoids the
  <inline-formula><alternatives>
  <tex-math><![CDATA[n^d]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msup><mml:mi>n</mml:mi><mml:mi>d</mml:mi></mml:msup></mml:math></alternatives></inline-formula>
  evaluations required by a full search over coordinate combinations,
  but it should be regarded as a computational approximation rather than
  the exact multivariate extension.</p>
  <p>Other goodness-of-fit procedures use nearest-neighbor distances,
  density estimation, Rosenblatt-type transformations, spatial
  statistics, or discrepancies between observed and expected discrete
  counts (Bakshaev &amp; Rudzkis, 2015; Bickel &amp; Breiman, 1983;
  Fasano &amp; Franceschini, 1987; Ripley, 1976). The two-sample
  collection includes nearest-neighbor, distance-based, kernel, graph,
  and Ball-divergence procedures, including methods of Aslan &amp; Zech
  (2005), Baringhaus &amp; Franz (2004), Biswas &amp; Ghosh (2014),
  Gretton et al. (2012), Friedman &amp; Rafsky (1979), Chen &amp;
  Friedman (2017), and Pan et al. (2018). These established statistics
  serve both as practical testing procedures and as reference
  competitors for newly proposed methods.</p>
  <sec id="comparison-with-related-software">
    <title>Comparison with related software</title>
    <p>Several
    <named-content content-type="sans-serif">R</named-content> packages
    implement important subsets of multivariate goodness-of-fit or
    two-sample methodology. For example,
    <named-content content-type="sans-serif">energy</named-content>
    concentrates on energy statistics and related distance-based
    methods,
    <named-content content-type="sans-serif">Ball</named-content>
    provides Ball-divergence procedures, and other packages implement
    particular multivariate normality, goodness-of-fit, kernel, or
    individual two-sample procedures. Such packages are valuable
    implementations of their respective methodological families.</p>
    <p>In particular, independent implementations of several statistics
    included in
    <named-content content-type="sans-serif">MD2sample</named-content>
    are available in
    <named-content content-type="sans-serif">cramer</named-content> for
    the Baringhaus–Franz test (Franz, 2024),
    <named-content content-type="sans-serif">energy</named-content> for
    the energy statistic (Rizzo &amp; Székely, 2024),
    <named-content content-type="sans-serif">kernlab</named-content> for
    maximum mean discrepancy (Karatzoglou et al., 2004), and
    <named-content content-type="sans-serif">fasano.franceschini.test</named-content>
    for the Fasano–Franceschini test (Puritz et al., 2023). These
    implementations provide potential reference points for checking
    built-in statistics, subject to differences in normalization, tuning
    parameters, and calibration.</p>
    <p>The objective of
    <named-content content-type="sans-serif">MDgof</named-content> and
    <named-content content-type="sans-serif">MD2sample</named-content>
    is different. The packages provide common infrastructure for
    applying heterogeneous procedures and comparing them under identical
    simulation conditions. A user-defined statistic can be passed
    through the same calibration, power, and benchmarking machinery as
    the built-in statistics. Thus the framework is complementary to
    packages devoted to particular methodologies: those packages provide
    specialized implementations, whereas
    <named-content content-type="sans-serif">MDgof</named-content> and
    <named-content content-type="sans-serif">MD2sample</named-content>
    emphasize integration, extensibility, and comparative
    computation.</p>
  </sec>
</sec>
<sec id="simultaneous-inference">
  <title>Simultaneous inference and adjusted
  <inline-formula><alternatives>
  <tex-math><![CDATA[p]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> values</title>
  <p>Because no single multivariate test has uniformly high power, an
  analyst may apply several procedures and use the smallest individual
  <inline-formula><alternatives>
  <tex-math><![CDATA[p]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> value
  as evidence against the common null hypothesis. The unadjusted minimum
  is not itself a valid level-<inline-formula><alternatives>
  <tex-math><![CDATA[\alpha]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>α</mml:mi></mml:math></alternatives></inline-formula>
  test because the individual statistics are dependent and the
  probability of at least one small <inline-formula><alternatives>
  <tex-math><![CDATA[p]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> value
  exceeds <inline-formula><alternatives>
  <tex-math><![CDATA[\alpha]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>α</mml:mi></mml:math></alternatives></inline-formula>.</p>
  <p>The packages therefore calibrate the minimum
  <inline-formula><alternatives>
  <tex-math><![CDATA[p]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> value
  by resampling under the joint null hypothesis. If
  <inline-formula><alternatives>
  <tex-math><![CDATA[P_{\min}]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>P</mml:mi><mml:mi mathvariant="normal">min</mml:mi></mml:msub></mml:math></alternatives></inline-formula>
  denotes the minimum of the individual <inline-formula><alternatives>
  <tex-math><![CDATA[p]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> values
  and <inline-formula><alternatives>
  <tex-math><![CDATA[H_0]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>H</mml:mi><mml:mn>0</mml:mn></mml:msub></mml:math></alternatives></inline-formula>
  is true, let <inline-formula><alternatives>
  <tex-math><![CDATA[F_{\min}]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>F</mml:mi><mml:mi mathvariant="normal">min</mml:mi></mml:msub></mml:math></alternatives></inline-formula>
  be its null distribution function. The combined adjusted value is
  <disp-formula><alternatives>
  <tex-math><![CDATA[p_{\mathrm{adj}} = F_{\min}(p_{\min,\mathrm{obs}}).]]></tex-math>
  <mml:math display="block" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:msub><mml:mi>p</mml:mi><mml:mrow><mml:mi mathvariant="normal">a</mml:mi><mml:mi mathvariant="normal">d</mml:mi><mml:mi mathvariant="normal">j</mml:mi></mml:mrow></mml:msub><mml:mo>=</mml:mo><mml:msub><mml:mi>F</mml:mi><mml:mi mathvariant="normal">min</mml:mi></mml:msub><mml:mo stretchy="false" form="prefix">(</mml:mo><mml:msub><mml:mi>p</mml:mi><mml:mrow><mml:mrow><mml:mi mathvariant="normal">min</mml:mi><mml:mo>&#8289;</mml:mo></mml:mrow><mml:mo>,</mml:mo><mml:mrow><mml:mi mathvariant="normal">o</mml:mi><mml:mi mathvariant="normal">b</mml:mi><mml:mi mathvariant="normal">s</mml:mi></mml:mrow></mml:mrow></mml:msub><mml:mo stretchy="false" form="postfix">)</mml:mo><mml:mi>.</mml:mi></mml:mrow></mml:math></alternatives></disp-formula>
  Because <inline-formula><alternatives>
  <tex-math><![CDATA[F_{\min}]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>F</mml:mi><mml:mi mathvariant="normal">min</mml:mi></mml:msub></mml:math></alternatives></inline-formula>
  is generally unavailable analytically, it is estimated from resampled
  data generated under the same null model. The computational algorithm
  is:</p>
  <list list-type="bullet">
    <list-item>
      <p>Generate a new data set under the null hypothesis, run the
      desired tests and record the smallest
      <inline-formula><alternatives>
      <tex-math><![CDATA[p]]></tex-math>
      <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> value.</p>
    </list-item>
    <list-item>
      <p>Repeat this step for the number of replications specified by
      the second component of <monospace>B</monospace>.</p>
    </list-item>
    <list-item>
      <p>Use the empirical distribution function
      <inline-formula><alternatives>
      <tex-math><![CDATA[\hat{F}_{\min}]]></tex-math>
      <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mover><mml:mi>F</mml:mi><mml:mo accent="true">̂</mml:mo></mml:mover><mml:mi mathvariant="normal">min</mml:mi></mml:msub></mml:math></alternatives></inline-formula>
      of the simulated minimum <inline-formula><alternatives>
      <tex-math><![CDATA[p]]></tex-math>
      <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> values
      to estimate <inline-formula><alternatives>
      <tex-math><![CDATA[F_{\min}]]></tex-math>
      <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>F</mml:mi><mml:mi mathvariant="normal">min</mml:mi></mml:msub></mml:math></alternatives></inline-formula>.</p>
    </list-item>
    <list-item>
      <p>Apply <inline-formula><alternatives>
      <tex-math><![CDATA[\hat{F}_{\min}]]></tex-math>
      <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mover><mml:mi>F</mml:mi><mml:mo accent="true">̂</mml:mo></mml:mover><mml:mi mathvariant="normal">min</mml:mi></mml:msub></mml:math></alternatives></inline-formula>
      to the observed minimum <inline-formula><alternatives>
      <tex-math><![CDATA[p]]></tex-math>
      <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> value
      <inline-formula><alternatives>
      <tex-math><![CDATA[p_{\min,\mathrm{obs}}]]></tex-math>
      <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msub><mml:mi>p</mml:mi><mml:mrow><mml:mrow><mml:mi mathvariant="normal">min</mml:mi><mml:mo>&#8289;</mml:mo></mml:mrow><mml:mo>,</mml:mo><mml:mrow><mml:mi mathvariant="normal">o</mml:mi><mml:mi mathvariant="normal">b</mml:mi><mml:mi mathvariant="normal">s</mml:mi></mml:mrow></mml:mrow></mml:msub></mml:math></alternatives></inline-formula>
      to obtain the adjusted <inline-formula><alternatives>
      <tex-math><![CDATA[p]]></tex-math>
      <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> value.</p>
    </list-item>
  </list>
  <p>For an example, see (Rolke, 2025). For a general discussion of
  <inline-formula><alternatives>
  <tex-math><![CDATA[p]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> value
  adjustments based on resampling see (Westfall &amp; Young, 1993).</p>
  <p><monospace>MDgof::gof_test_adjusted_pvalue()</monospace> and
  <monospace>MD2sample::twosample_test_adjusted_pvalue()</monospace>
  compute these adjusted <inline-formula><alternatives>
  <tex-math><![CDATA[p]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> values.
  Both functions have the default argument
  <monospace>B = c(5000, 1000)</monospace>. The first component
  specifies the number of simulation replications used to estimate the
  individual <inline-formula><alternatives>
  <tex-math><![CDATA[p]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> values,
  and the second specifies the number used to estimate the null
  distribution function of their minimum. The two stages are performed
  serially rather than by nesting the full individual calibration inside
  every second-stage replication; the computational cost is therefore
  associated with the two successive stages rather than their product.
  Both provide a <monospace>doMethods</monospace> argument for
  specifying the tests to combine;
  <monospace>doMethods=&quot;all&quot;</monospace> includes every method
  available for the given data type and dimension. The default
  selections are smaller subsets. For example, for discrete data
  <monospace>MD2sample::twosample_test_adjusted_pvalue()</monospace>
  combines Chi-square, Kolmogorov–Smirnov, Aslan–Zech, and Cramér–von
  Mises by default, whereas
  <monospace>MD2sample::twosample_test()</monospace> reports eight
  tests. For four-dimensional continuous data, the default
  <monospace>MDgof::gof_test()</monospace> selection reports qK, qCvM,
  and qAD. Specifying <monospace>doMethods=&quot;all&quot;</monospace>
  in both testing routines also includes qKS and BR, allowing the same
  five methods to be compared. Method availability depends on data type
  and dimension; in particular, the chi-square implementations are
  limited to two dimensions. See
  Section <xref alt="5" rid="secU003Atesting">5</xref> for the testing
  interfaces. For an example using this adjustment in simultaneous
  confidence bands, see (Aldor-Noiman et al., 2013).</p>
</sec>
<sec id="secU003Atesting">
  <title>Computational framework, testing, and extensibility</title>
  <p>The public interfaces separate three components that are often
  intertwined in method-specific implementations: the observed data, the
  statistic to be evaluated, and the mechanism used to generate or
  resample data under the null hypothesis. This separation is what
  allows the same computational machinery to serve built-in and
  user-defined statistics.</p>
  <p>The two packages intentionally expose analogous workflows with
  parallel naming conventions. This reduces the learning cost for users
  moving between goodness-of-fit and two-sample problems. The packages
  need not be attached simultaneously; examples in this paper use
  namespace-qualified calls when the package identity is useful.</p>
  <p>A user-defined statistic is supplied through
  <monospace>TS</monospace>; auxiliary objects or functions required by
  that statistic can be passed through <monospace>TSextra</monospace>.
  Once supplied, the statistic can participate in testing, power
  estimation, and benchmarking without requiring the user to implement
  separate Monte Carlo loops. This is the principal extensibility
  mechanism of the framework.</p>
  <sec id="goodness-of-fit">
    <title>Goodness-of-fit</title>
    <p>The routine to carry out a goodness-of-fit hypothesis test is
    <monospace>MDgof::gof_test()</monospace>. Its arguments are</p>
    <list list-type="bullet">
      <list-item>
        <p>x: a data set, either the continuous outcomes or the counts
        in the discrete case. In the continuous data case it is a matrix
        with each row representing an observation. In the discrete case
        it is a matrix with three columns, the values of x, the values
        of y and the corresponding counts</p>
      </list-item>
      <list-item>
        <p>pnull: a function to calculate values for the cdf.</p>
      </list-item>
      <list-item>
        <p>rnull: a function to generate new data under the null
        hypothesis.</p>
      </list-item>
      <list-item>
        <p>dnull: a function evaluating the density under the null
        hypothesis, when required by a test such as BB.</p>
      </list-item>
      <list-item>
        <p>phat=function(x) -99: a function to estimate parameters, or
        -99 if null hypothesis is simple and no parameters are
        estimated.</p>
      </list-item>
      <list-item>
        <p>TS: routine to calculate test statistics other than those
        included.</p>
      </list-item>
      <list-item>
        <p>TSextra: a list passed to TS.</p>
      </list-item>
      <list-item>
        <p>rate=0, the rate of the Poisson random variable if the sample
        size was random.</p>
      </list-item>
      <list-item>
        <p>nbins=c(5, 5): number of bins in x and y directions to use in
        chi-square tests.</p>
      </list-item>
      <list-item>
        <p>Ranges=matrix(c(-Inf, Inf, -Inf, Inf), 2, 2): range of
        continuous random variables.</p>
      </list-item>
      <list-item>
        <p>minexpcount=5: required minimal expected counts for
        chi-square tests.</p>
      </list-item>
      <list-item>
        <p>maxProcessor: number of cores to use for parallel processing,
        1 means no parallel programming.</p>
      </list-item>
      <list-item>
        <p>doMethods: vector with names of methods to include.</p>
      </list-item>
      <list-item>
        <p>B=5000: number of simulation runs.</p>
      </list-item>
      <list-item>
        <p>seed=NULL: if provided, initializes the simulations for
        reproducibility. For a fixed parallel configuration, the seed is
        also passed to the worker processes. Changing
        <monospace>maxProcessor</monospace> can change the simulated
        results.</p>
      </list-item>
      <list-item>
        <p>ReturnTSextra = FALSE, returns a list for TSextra, needed for
        some checks.</p>
      </list-item>
    </list>
    <p>TSextra is a list object that allows the creator of a new method
    to provide their test statistic with needed additional information.
    As an example, say a new method requires a routine that finds the
    median of each variable. This can be done with</p>
    <preformat>TSextra = list(med = function(x) apply(x, 2, median))</preformat>
    <p>The formats of the routines pnull and rnull have to be as
    follows. If no parameters are estimated pnull is a function of one
    variable (the data) and rnull has no arguments. We will use as an
    example the standard normal distribution for continuous data.</p>
    <preformat>pnullC = function (x) {
    f = function(x) mvtnorm::pmvnorm(rep(-Inf, length(x)), x)
    if (!is.matrix(x))
        return(f(x))
    apply(x, 1, f)
}
rnullC = function() mvtnorm::rmvnorm(100, c(0, 0))</preformat>
    <p>Notice that the function pnull should accept both a vector and a
    matrix.</p>
    <p>Here is an example run:</p>
    <preformat>set.seed(1234)
x = rnullC()
gof_test(x, pnullC, rnullC, B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>$statistics
     qK    qCvM     qAD      FF      RK      EP
 0.1740  0.2940  2.1220  0.4610  0.0495 18.1000

$p.values
    qK   qCvM    qAD     FF     RK     EP
0.1920 0.0440 0.2320 0.7240 0.8480 0.1538</preformat>
    <p>If the density is known it can be added and several more tests
    run:</p>
    <preformat>dnullC = function (x) {
    f = function(x) mvtnorm::dmvnorm(x)
    if (!is.matrix(x))
        return(f(x))
    apply(x, 1, f)
}
gof_test(x, pnullC, rnullC, dnull = dnullC, B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>$statistics
      qK     qCvM      qAD       FF       RK       EP       BB
 0.17400  0.29400  2.12200  0.46100  0.04950 18.10000  0.00647

$p.values
    qK   qCvM    qAD     FF     RK     EP     BB
0.1920 0.0440 0.2320 0.7240 0.8480 0.1538 0.8360</preformat>
    <p>As discussed before, one can also run tests by generating a
    second data set under the null hypothesis, and then running a
    two-sample test. This is easy to do with
    <monospace>MDgof::hybrid_test()</monospace>. In the following run we
    will generate MC data sets twice the size of the actual data:</p>
    <preformat>MDgof::hybrid_test(x, rnullC, nMC = 2, B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>Data is assumed to be continuous
MD2sample two-sample tests
Data: continuous  | n.x = 100  | n.y = 200  | dimension = 2  | B = 250

 method statistic p.value
     KS   0.13000   0.372
      K   0.22500   0.132
    CvM   0.17710   0.232
     AD   1.11680   0.292
    NN1   1.18000   0.012
    NN5   2.30000   0.000
     AZ   0.06003   0.368
     BF   0.25570   0.452
     BG   0.07833   0.728
    MMD   0.01627   0.340</preformat>
    <p>For the case of discrete data the formats of pnull and rnull are
    the same.</p>
    <p>In the case where parameters are estimated pnull has to be a
    function of two arguments, the data and the estimated parameters,
    and rnull a function of the estimated parameters. As an example we
    consider the case of a discrete random vector of Binomial random
    variables. Under the null hypothesis we have
    <inline-formula><alternatives>
    <tex-math><![CDATA[X\sim Bin(10, p), Y|X=x\sim Bin(5, 0.5+x/100)]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>X</mml:mi><mml:mo>∼</mml:mo><mml:mi>B</mml:mi><mml:mi>i</mml:mi><mml:mi>n</mml:mi><mml:mo stretchy="false" form="prefix">(</mml:mo><mml:mn>10</mml:mn><mml:mo>,</mml:mo><mml:mi>p</mml:mi><mml:mo stretchy="false" form="postfix">)</mml:mo><mml:mo>,</mml:mo><mml:mi>Y</mml:mi><mml:mo stretchy="false" form="prefix">|</mml:mo><mml:mi>X</mml:mi><mml:mo>=</mml:mo><mml:mi>x</mml:mi><mml:mo>∼</mml:mo><mml:mi>B</mml:mi><mml:mi>i</mml:mi><mml:mi>n</mml:mi><mml:mo stretchy="false" form="prefix">(</mml:mo><mml:mn>5</mml:mn><mml:mo>,</mml:mo><mml:mn>0.5</mml:mn><mml:mo>+</mml:mo><mml:mi>x</mml:mi><mml:mi>/</mml:mi><mml:mn>100</mml:mn><mml:mo stretchy="false" form="postfix">)</mml:mo></mml:mrow></mml:math></alternatives></inline-formula>.
    Instead we will generate data from <inline-formula><alternatives>
    <tex-math><![CDATA[X\sim Bin(10, p), Y|X=x\sim Bin(5, K+x/100)]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>X</mml:mi><mml:mo>∼</mml:mo><mml:mi>B</mml:mi><mml:mi>i</mml:mi><mml:mi>n</mml:mi><mml:mo stretchy="false" form="prefix">(</mml:mo><mml:mn>10</mml:mn><mml:mo>,</mml:mo><mml:mi>p</mml:mi><mml:mo stretchy="false" form="postfix">)</mml:mo><mml:mo>,</mml:mo><mml:mi>Y</mml:mi><mml:mo stretchy="false" form="prefix">|</mml:mo><mml:mi>X</mml:mi><mml:mo>=</mml:mo><mml:mi>x</mml:mi><mml:mo>∼</mml:mo><mml:mi>B</mml:mi><mml:mi>i</mml:mi><mml:mi>n</mml:mi><mml:mo stretchy="false" form="prefix">(</mml:mo><mml:mn>5</mml:mn><mml:mo>,</mml:mo><mml:mi>K</mml:mi><mml:mo>+</mml:mo><mml:mi>x</mml:mi><mml:mi>/</mml:mi><mml:mn>100</mml:mn><mml:mo stretchy="false" form="postfix">)</mml:mo></mml:mrow></mml:math></alternatives></inline-formula>,
    so for <inline-formula><alternatives>
    <tex-math><![CDATA[K\ne 0.5]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>K</mml:mi><mml:mo>≠</mml:mo><mml:mn>0.5</mml:mn></mml:mrow></mml:math></alternatives></inline-formula>
    the null hypothesis is false</p>
    <preformat>pnullD = function(x, p) {
  f = function(x) sum(dbinom(0:x[1], 10, p[1])*pbinom(x[2], 5, 0.5+0:x[1]/100))
  if(!is.matrix(x)) x = rbind(x)
  apply(x, 1, f)
}
rnullD = function(p = 0.5) {
  x = stats::rbinom(1000, 10, p)
  y = stats::rbinom(1000, 5, 0.5+x/100)
  MDgof::sq2rec(table(x, y))
}
raltD = function(K = 0.5) {
  x = stats::rbinom(1000, 10, 0.5)
  y = stats::rbinom(1000, 5, K+x/100)
  MDgof::sq2rec(table(x, y))
}

phatD = function(x) {
  tx = tapply(x[, 3], x[, 1], sum)
  mean(rep(as.numeric(names(tx)), times = tx))/10
}</preformat>
    <p>These routines make use of
    <monospace>MDgof::sq2rec()</monospace>, which transforms discrete
    data as generated by the
    <named-content content-type="sans-serif">R</named-content> function
    <monospace>table()</monospace> into the format required by
    <monospace>MDgof::gof_test()</monospace>. A simple example is as
    follows:</p>
    <preformat>x = stats::rbinom(1000, 2, 0.5)
y = stats::rbinom(1000, 2, 0.7+x/100)
head(cbind(x, y))</preformat>
    <preformat>     x y
[1,] 1 2
[2,] 0 1
[3,] 2 2
[4,] 0 1
[5,] 0 1
[6,] 1 1</preformat>
    <preformat>MDgof::sq2rec(table(x, y))</preformat>
    <preformat>      [,1] [,2] [,3]
 [1,]    0    0   30
 [2,]    1    0   38
 [3,]    2    0   13
 [4,]    0    1  107
 [5,]    1    1  216
 [6,]    2    1   96
 [7,]    0    2  121
 [8,]    1    2  244
 [9,]    2    2  135</preformat>
    <preformat>set.seed(1234)
x = rnullD(0.57)
MDgof::gof_test(x, pnullD, rnullD, phat = phatD, B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>$statistics
       K       AD       KL        P
0.048100 0.001270 0.042600 89.900000

$p.values
    K    AD    KL     P
0.104 0.116 0.016 0.072</preformat>
  </sec>
  <sec id="two-sample">
    <title>Two-sample</title>
    <p>The routine to carry out a two-sample hypothesis test is
    <monospace>MD2sample::twosample_test()</monospace>. Its arguments
    are</p>
    <list list-type="bullet">
      <list-item>
        <p>x: a data set, either the continuous outcomes or the counts
        in the discrete case. It could also be a matrix with columns
        vals_x, vals_y, x and y, indicating discrete data.</p>
      </list-item>
      <list-item>
        <p>y: a data set, either the continuous outcomes or the counts
        in the discrete case.</p>
      </list-item>
      <list-item>
        <p>vals_x: values of a discrete rv.</p>
      </list-item>
      <list-item>
        <p>vals_y: values of a discrete rv.</p>
      </list-item>
      <list-item>
        <p>TS: routine to calculate test statistics other than those
        included.</p>
      </list-item>
      <list-item>
        <p>TSextra: a list passed to TS.</p>
      </list-item>
      <list-item>
        <p>B=5000: number of simulation runs.</p>
      </list-item>
      <list-item>
        <p>seed=NULL: can be used for reproducibility.</p>
      </list-item>
      <list-item>
        <p>nbins=c(5, 5): number of bins in x and y directions to use in
        chi-square tests.</p>
      </list-item>
      <list-item>
        <p>Ranges=matrix(c(-Inf, Inf, -Inf, Inf), 2, 2): range of
        continuous random variables.</p>
      </list-item>
      <list-item>
        <p>minexpcount=5: required minimal expected counts for
        chi-square tests.</p>
      </list-item>
      <list-item>
        <p>maxProcessor: number of cores to use for parallel processing,
        1 means no parallel programming.</p>
      </list-item>
      <list-item>
        <p>DoTransform=TRUE: should continuous data be transformed to
        unit interval?</p>
      </list-item>
      <list-item>
        <p><monospace>samplingmethod=&quot;Binomial&quot;</monospace>:
        sampling method for discrete data</p>
      </list-item>
      <list-item>
        <p><monospace>doMethods=&quot;all&quot;</monospace>: include all
        methods available for the data type and dimension.</p>
      </list-item>
      <list-item>
        <p>SuppressMessages=FALSE, should informative messages be
        printed?</p>
      </list-item>
      <list-item>
        <p>rnull: routine to generate new data, for parametric
        bootstrap.</p>
      </list-item>
      <list-item>
        <p>LargeSampleOnly=FALSE: run only methods with large sample
        theory? Used for very large data sets.</p>
      </list-item>
    </list>
    <p>As an example for continuous data, we will generate data from a
    uniform distribution in 5 dimensions</p>
    <preformat>set.seed(1234)
x = matrix(runif(500), ncol = 5)
y = matrix(runif(500), ncol = 5)
MD2sample::twosample_test(x, y, B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>$statistics
       KS         K       CvM        AD       NN1       NN5
 0.100000  0.190000  0.034400  0.981400  0.890000  5.110000
       AZ        BF        BG       MMD        FR       NN0
 0.097470  0.622400  2.924600  0.024200  0.568300  0.220000
      CF1       CF2       CF3       CF4      Ball
 0.568300  1.484000 -0.568000  1.077500  0.012600

$p.values
    KS      K    CvM     AD    NN1    NN5     AZ     BF     BG
0.6040 0.3120 0.3280 0.5200 0.8960 0.2680 0.0400 0.0320 0.0320
   MMD     FR    NN0    CF1    CF2    CF3    CF4   Ball
0.0600 0.7151 0.8644 0.7151 0.4762 0.7151 0.4051 0.0236</preformat>
    <p>For a discrete two-sample example, we generate two sets of counts
    over four categories, representing the combinations of two binary
    variables. The second sample uses different category
    probabilities.</p>
    <preformat>set.seed(1234)
x = table(sample(1:4, size = 1000, replace = TRUE))
y = table(sample(1:4, size = 1000, replace = TRUE,
                 prob = c(1, 1.5, 1, 1)))
vals_x = rep(1:2, 2)
vals_y = rep(1:2, each = 2)
MD2sample::twosample_test(x, y, vals_x, vals_y,
                          B = 250, seed = 1234)</preformat>
    <preformat>$statistics
       KS        K      CvM       AD       NN       AZ       BF ChiSquare
  0.08400  0.13200  1.41150  5.95920 10.07200  0.03334  0.08924  19.76900

$p.values
       KS        K      CvM       AD       NN       AZ       BF ChiSquare
   0.0000   0.0000   0.0000   0.0000   0.0000   0.0000   0.0000    0.0002</preformat>
  </sec>
</sec>
<sec id="secU003Apower">
  <title>Monte Carlo power estimation and user-defined
  procedures</title>
  <p>The illustrative power calculations in this section use
  <inline-formula><alternatives>
  <tex-math><![CDATA[B=250]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>B</mml:mi><mml:mo>=</mml:mo><mml:mn>250</mml:mn></mml:mrow></mml:math></alternatives></inline-formula>
  Monte Carlo replications to keep computation times reasonable. For an
  estimated rejection probability <inline-formula><alternatives>
  <tex-math><![CDATA[\hat{\pi}]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mover><mml:mi>π</mml:mi><mml:mo accent="true">̂</mml:mo></mml:mover></mml:math></alternatives></inline-formula>,
  the Monte Carlo standard error is approximately
  <inline-formula><alternatives>
  <tex-math><![CDATA[\sqrt{\hat{\pi}(1-\hat{\pi})/B}]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:msqrt><mml:mrow><mml:mover><mml:mi>π</mml:mi><mml:mo accent="true">̂</mml:mo></mml:mover><mml:mo stretchy="false" form="prefix">(</mml:mo><mml:mn>1</mml:mn><mml:mo>−</mml:mo><mml:mover><mml:mi>π</mml:mi><mml:mo accent="true">̂</mml:mo></mml:mover><mml:mo stretchy="false" form="postfix">)</mml:mo><mml:mi>/</mml:mi><mml:mi>B</mml:mi></mml:mrow></mml:msqrt></mml:math></alternatives></inline-formula>.
  With <inline-formula><alternatives>
  <tex-math><![CDATA[B=250]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>B</mml:mi><mml:mo>=</mml:mo><mml:mn>250</mml:mn></mml:mrow></mml:math></alternatives></inline-formula>,
  this is at most approximately 0.032 and is approximately 0.014 when
  the rejection probability is 0.05. The tabulated values illustrate the
  software and should not be interpreted as precise power estimates;
  larger simulation sizes are appropriate for substantive power
  comparisons.</p>
  <sec id="goodness-of-fit-1">
    <title>Goodness-of-fit</title>
    <p>The routine to carry out power estimation for the goodness-of-fit
    methods is <monospace>MDgof::gof_power()</monospace>. Its arguments
    are again pnull, rnull, phat, dnull, TS, TSextra, Ranges, nbins,
    minexpcount, rate, maxProcessor, seed and B=1000, as in
    <monospace>MDgof::gof_test()</monospace>. Also the formats of these
    functions are the same. In addition we have</p>
    <list list-type="bullet">
      <list-item>
        <p>ralt: a function to generate data under the alternative
        hypothesis. It should have one argument.</p>
      </list-item>
      <list-item>
        <p>param_alt: a vector of values passed to ralt.</p>
      </list-item>
      <list-item>
        <p>With.p.value=FALSE: does the user supplied test routine TS
        find its own <inline-formula><alternatives>
        <tex-math><![CDATA[p]]></tex-math>
        <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> values,
        or should simulation be used?</p>
      </list-item>
      <list-item>
        <p>alpha=0.05: type I error probability.</p>
      </list-item>
    </list>
    <p>As an example we will again use the case described above, testing
    whether the data comes from a multivariate standard normal
    distribution. As an alternative we will use a multivariate normal
    with correlation:</p>
    <preformat>raltC = function(s) {
  mvtnorm::rmvnorm(100, c(0, 0), sigma = matrix(c(1, s, s, 1), 2, 2))
}
MDgof::gof_power(pnullC, rnullC, raltC, c(0, 0.5), B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>      qKS    qK  qCvM   qAD    BR    FF    RK    ES    EP
0   0.052 0.080 0.032 0.048 0.084 0.084 0.068 0.072 0.084
0.5 0.404 0.208 0.576 0.624 0.088 0.252 0.148 0.700 0.816</preformat>
    <p>Again we can run the hybrid tests instead:</p>
    <preformat>MDgof::hybrid_power(rnullC, raltC, c(0, 0.5), B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>        KS      K    CvM     AD    NN1    NN5     AZ     BF
0   0.088 0.060 0.076 0.076 0.072 0.052 0.048 0.056
0.5 0.116 0.136 0.196 0.276 0.248 0.260 0.220 0.188
        BG    MMD     FR    NN0    CF1    CF2    CF3    CF4
0   0.052 0.060 0.032 0.092 0.032 0.044 0.032 0.036
0.5 0.040 0.284 0.164 0.148 0.164 0.104 0.164 0.116
      Ball    ES    EP
0   0.048 0.056 0.064
0.5 0.080 0.416 0.316</preformat>
    <p><monospace>MDgof::gof_test()</monospace> and
    <monospace>MDgof::gof_power()</monospace> allow the user to also run
    their own tests. As an example,
    <named-content content-type="sans-serif">MDgof</named-content>
    includes the routine <monospace>newTS()</monospace>, which runs a
    simple chi-square test with 9 bins and both equal space and equal
    probability bins. We also need to include the arguments
    <monospace>TSextra</monospace>, which is a list of items passed to
    the testing routine. In this example it tells
    <monospace>newTS()</monospace> to run the version for continuous
    data and without estimation, and then return a
    <inline-formula><alternatives>
    <tex-math><![CDATA[p]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula> value.</p>
    <preformat>TSextra = list(Continuous = TRUE,
             WithEstimation = FALSE,
             Withpvalue = TRUE)
MDgof::gof_power(pnullC, rnullC, raltC, c(0, 0.5),
                 TS = newTS, TSextra = TSextra, With.p.value = TRUE,
                 B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>     ES33  EP33
0   0.056 0.048
0.5 0.596 0.860</preformat>
    <p>Here <monospace>ES33</monospace> and <monospace>EP33</monospace>
    are labels for the user-defined statistics supplied through
    <monospace>TS</monospace>; they are not built-in methods.</p>
    <p>The discrete examples below report different method sets because
    <monospace>gof_test()</monospace> and
    <monospace>gof_power()</monospace> use different default method
    selections; the <monospace>doMethods</monospace> argument permits an
    explicit selection.</p>
    <p>Next a power estimation for the discrete data case:</p>
    <preformat>MDgof::gof_power(pnullD, rnullD, raltD, c(0.5, 0.53), phat = phatD, B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>       KS     K   CvM    AD    TV    KL     H     P
0.5  0.024 0.012 0.020 0.024 0.068 0.068 0.060 0.124
0.53 0.928 0.844 0.928 0.936 0.536 0.556 0.468 0.372</preformat>
  </sec>
  <sec id="two-sample-1">
    <title>Two-sample</title>
    <p>For the two-sample problem we have the routine
    <monospace>MD2sample::twosample_power()</monospace>. Its arguments
    are the same as <monospace>MD2sample::twosample_test()</monospace>,
    except</p>
    <list list-type="bullet">
      <list-item>
        <p>f: a function that generates either a list with two data sets
        for continuous data, or a single matrix for discrete data.</p>
      </list-item>
      <list-item>
        <p>... either one or two vectors of values to be passed to
        f.</p>
      </list-item>
      <list-item>
        <p>alpha=0.05: type I error probability.</p>
      </list-item>
    </list>
    <p>As an example for continuous data, we consider the following
    power study: one data set has a uniform distribution on the unit
    square in 5 dimensions. The other comes from a Frank copula with
    parameter <inline-formula><alternatives>
    <tex-math><![CDATA[\theta]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>θ</mml:mi></mml:math></alternatives></inline-formula>.
    Note that if <inline-formula><alternatives>
    <tex-math><![CDATA[\theta=0]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>θ</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow></mml:math></alternatives></inline-formula>,
    the null hypothesis is true</p>
    <preformat>f = function (theta = 0, d = 2) {
    x = matrix(stats::runif(500), ncol = 5)
    if (theta == 0)
      return(list(x = x, y = matrix(runif(500), ncol = 5)))
    cop = copula::frankCopula(theta, 5)
    list(x = x, y = copula::rCopula(100, cop))
}
MD2sample::twosample_power(f, c(0, 3.5), B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>        KS      K    CvM     AD    NN1    NN5     AZ     BF
0   0.052 0.056 0.040 0.036 0.056 0.048 0.052 0.052
3.5 0.872 0.596 0.988 0.988 0.912 0.992 1.000 0.988
        BG    MMD     FR    NN0    CF1    CF2    CF3    CF4
0   0.056 0.044 0.044 0.052 0.044 0.032 0.044 0.052
3.5 0.060 1.000 0.936 0.544 0.936 0.924 0.936 0.916
      Ball
0   0.032
3.5 0.948</preformat>
    <p>As with the goodness-of-fit routines, the user again can run
    other tests not included in
    <named-content content-type="sans-serif">MD2sample</named-content>.</p>
  </sec>
</sec>
<sec id="secU003Abenchmarking">
  <title>Benchmarking and comparative simulation</title>
  <p>A central purpose of the framework is to compare the power of
  competing methods, including methods supplied by the user, under
  common Monte Carlo conditions. In both packages this functionality is
  provided by <monospace>run.studies()</monospace>. By fixing the
  data-generating scenarios, sample sizes, type I error level, and
  simulation size across procedures, the framework removes a substantial
  source of incidental variation from comparative studies.</p>
  <p>Both packages include a large number of case studies, that is,
  distributions for the null hypothesis and for an alternative
  hypothesis. They can be found in the routine
  <monospace>case.studies()</monospace>. The two packages provide 140
  distinct case names, corresponding to 250 study configurations when
  continuous and discrete versions, parameter estimation, and
  five-dimensional cases are counted separately. Both packages include
  vignettes with detailed descriptions of the studies. For a listing one
  can run</p>
  <preformat>MDgof::case.studies(Continuous = TRUE,
                    WithEstimation = TRUE,
                    Dim = 5,
                    ReturnCaseNames = TRUE)[1:10]</preformat>
  <preformat> [1] &quot;uniform.uniform-diagonal-n&quot; &quot;uniform.uniform-diagonal-b&quot;
 [3] &quot;normal-ind.normal-corA&quot;     &quot;normal-ind.normal-corB&quot;
 [5] &quot;t-ind.t-cor&quot;                &quot;uniform.Frank&quot;
 [7] &quot;uniform.Clayton&quot;            &quot;uniform.Gumbel&quot;
 [9] &quot;uniform.Joe&quot;                &quot;mix.uniform.Clayton&quot;</preformat>
  <p>The names are chosen to give some idea of the type of study. For
  example, in the first study the null hypothesis specifies independent
  uniform data, where the actual data is uniform with some data on the
  main diagonal in such a way that the marginals are still all uniforms.
  Many of the studies are based on copulas using the
  <named-content content-type="sans-serif">R</named-content> package
  <named-content content-type="sans-serif">copula</named-content>.</p>
  <p>Let’s say we want to compare the power of the included test
  <monospace>MDgof::newTS()</monospace> with those included in the
  package for the case of continuous data without parameter estimation.
  We can run</p>
  <preformat>TSextra = list(Continuous = TRUE, WithEstimation = FALSE, Withpvalue = TRUE)
res = MDgof::run.studies(TS = newTS, TSextra = TSextra, With.p.value = TRUE, B = 250, maxProcessor = 1, seed = 1234)</preformat>
  <preformat>Average rank of each test across studies:
ES33 EP33  qKS   qK qCvM  qAD   BB   BR  KSD   FF   RK   ES   EP
10.0  9.3  6.7  6.3  7.0  6.8  2.0  5.1  5.2  8.2  5.4  9.6  9.3</preformat>
  <p>res contains the detailed power estimates. The summary reports the
  average rank of each method across the selected scenarios, with larger
  values indicating better average performance.</p>
  <p>Arguments common to <monospace>MDgof::run.studies()</monospace> and
  <monospace>MD2sample::run.studies()</monospace> are:</p>
  <list list-type="bullet">
    <list-item>
      <p>study: number(s) or name(s) of studies to run. If missing all
      are run.</p>
    </list-item>
    <list-item>
      <p>Continuous=TRUE: is data continuous?</p>
    </list-item>
    <list-item>
      <p>TS: new test statistic (optional).</p>
    </list-item>
    <list-item>
      <p>TSextra: list passed to TS (optional).</p>
    </list-item>
    <list-item>
      <p>With.p.value = FALSE, does new test routine find
      <inline-formula><alternatives>
      <tex-math><![CDATA[p]]></tex-math>
      <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula>
      values?</p>
    </list-item>
    <list-item>
      <p>alpha=0.05: type I error probability for tests.</p>
    </list-item>
    <list-item>
      <p>param_alt: parameter vectors for alternative hypothesis. This
      should be a vector or a matrix. If missing, the values from the
      included studies are used.</p>
    </list-item>
    <list-item>
      <p>nsample: sample size(s). This should be one number, or two for
      MD2sample if different sample sizes are needed.</p>
    </list-item>
    <list-item>
      <p>SuppressMessages = FALSE: should informative messages be
      printed?</p>
    </list-item>
    <list-item>
      <p>B = 1000: simulation sample size.</p>
    </list-item>
    <list-item>
      <p>maxProcessor: number of processors to use. If missing, the
      number of processors in the computer minus 1 is used. If =1, no
      parallel processing is used.</p>
    </list-item>
  </list>
  <p>Arguments specific to
  <monospace>MDgof::run.studies()</monospace>:</p>
  <list list-type="bullet">
    <list-item>
      <p>WithEstimation = FALSE: should case studies with parameter
      estimation be run?</p>
    </list-item>
    <list-item>
      <p>Hybrid = FALSE: should two-sample methods be used?</p>
    </list-item>
    <list-item>
      <p>nMC5 = FALSE: if Hybrid=TRUE, should the MC data set have the
      same size as the real data, or be 5 times as large?</p>
    </list-item>
    <list-item>
      <p>Dim = 2: should 2-D case studies be run, or 5-D?</p>
    </list-item>
  </list>
  <p>As an example, the package
  <named-content content-type="sans-serif">MDgof</named-content>
  includes the routine <monospace>newTS()</monospace>. This runs a
  chi-square test with a 3 by 3 grid of bins, either equal space or
  equal probability. To see how these tests perform for continuous data
  without parameter estimation, we can run</p>
  <preformat>TSextra = list(Continuous = TRUE, WithEstimation = FALSE, Withpvalue = TRUE)
res = MDgof::run.studies(TS = MDgof::newTS, TSextra = TSextra, With.p.value = TRUE, B = 250, maxProcessor = 1, seed = 1234)</preformat>
  <preformat>Average rank of each test across studies:
ES33 EP33  qKS   qK qCvM  qAD   BB   BR  KSD   FF   RK   ES   EP
10.0  9.3  6.7  6.3  7.0  6.8  2.0  5.1  5.2  8.2  5.4  9.6  9.3</preformat>
  <p>The <monospace>run.studies()</monospace> routines can be used
  to</p>
  <list list-type="bullet">
    <list-item>
      <p>rerun the studies with the included tests.</p>
    </list-item>
    <list-item>
      <p>rerun the studies with the included tests, but with changed
      parameters for the alternatives, a different type I error
      probability and/or different sample sizes.</p>
    </list-item>
  </list>
  <p>The method labels in the output abbreviate the procedures in
  Tables 1 and 2: KS (Kolmogorov–Smirnov), K (Kuiper), CvM (Cramér–von
  Mises), AD (Anderson–Darling), NN (nearest-neighbor), AZ (Aslan–Zech),
  BF (Baringhaus–Franz), BG (Biswas–Ghosh), MMD (maximum mean
  discrepancy), FR (Friedman–Rafsky), CF (Chen–Friedman), and BR
  (Bakshaev–Rudzkis). The q-prefixed labels identify goodness-of-fit EDF
  statistics; additional labels are defined by the respective package
  documentation.</p>
</sec>
<sec id="secU003Acomputation">
  <title>Computational performance</title>
  <p>All computations in this article were performed on an Intel Core
  i9-14900F system with 32 GB RAM running Windows 11 Home (build 26200),
  using R version 4.6.0 (2026-04-24 ucrt). The package versions were
  <monospace>mvtnorm</monospace> 1.4.2, <monospace>copula</monospace>
  1.1.7, <monospace>Ball</monospace> 1.3.13,
  <monospace>energy</monospace> 1.7.12, <monospace>GGally</monospace>
  2.4.0, and <monospace>Rcpp</monospace> 1.1.1-1.1. The versions of the
  packages presented here were <monospace>MDgof</monospace> 1.2.1 and
  <monospace>MD2sample</monospace> 1.4.2. The latter includes the
  corrected cross-sample distance guard in the Aslan–Zech statistic,
  which tests <monospace>Dz(i,nx+j)&gt;0</monospace> before evaluating
  <monospace>log(Dz(i,nx+j))</monospace>. To illustrate the
  computational costs, we include two examples.</p>
  <sec id="goodness-of-fit-continuous-data">
    <title>Goodness-of-fit, continuous data</title>
    <p>Here the example is the first of the case studies. The null
    hypothesis specifies a uniform distribution in two dimensions with
    1000 observations:</p>
    <preformat>tmp = MDgof::case.studies(1, nsample = 1000)
x = tmp$rnull()
tp = proc.time()
a = MDgof::gof_test(x, tmp$pnull, tmp$rnull, dnull = tmp$dnull, B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat></preformat>
    <preformat>proc.time()-tp</preformat>
    <preformat>   user  system elapsed
  43.28    0.92   45.78</preformat>
    <p>The elapsed time was therefore about 46 seconds.</p>
  </sec>
  <sec id="two-sample-continuous-data">
    <title>Two-sample, continuous data</title>
    <p>Both data sets come from a uniform distribution in 5 dimensions
    with 100 observations:</p>
    <preformat>x = matrix(runif(500), ncol = 5)
y = matrix(runif(500), ncol = 5)
tp = proc.time()
a = MD2sample::twosample_test(x, y, B = 250, maxProcessor = 1, seed = 1234)</preformat>
    <preformat>Data is assumed to be continuous</preformat>
    <preformat>proc.time()-tp</preformat>
    <preformat>   user  system elapsed
   5.65    0.44    6.16</preformat>
    <p>The elapsed time was therefore about 6 seconds.</p>
  </sec>
</sec>
<sec id="secU003Aexamples">
  <title>Applications</title>
  <p>The following examples illustrate the use of
  <named-content content-type="sans-serif">MDgof</named-content> and
  <named-content content-type="sans-serif">MD2sample</named-content>
  with real datasets. Their purpose is to demonstrate the software
  interface, including parameter estimation and adjusted
  <inline-formula><alternatives>
  <tex-math><![CDATA[p]]></tex-math>
  <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula>-values,
  rather than to provide comprehensive statistical analyses of the
  underlying scientific questions. The full code and fixed data used for
  these examples are included in the replication material.</p>
  <sec id="fishers-iris-data">
    <title>Fisher’s iris data</title>
    <p>As an illustration with continuous data, consider Fisher’s iris
    data (Fisher, 1936). We use the 50 observations on the setosa
    variety to demonstrate a goodness-of-fit test of a four-dimensional
    multivariate normal distribution, with its mean vector and
    covariance matrix estimated from the data.
    Figure <xref alt="1" rid="figU003Afig1">1</xref> shows a scatterplot
    matrix.</p>
    <preformat>setosa = iris3[, , 1]
p = GGally::ggpairs(
  setosa,
  progress = FALSE
) +
  ggplot2::theme_bw(base_size = 13) +
  ggplot2::theme(
    axis.text = ggplot2::element_text(size = 10),
    strip.text = ggplot2::element_text(size = 12),
    strip.text.x = ggplot2::element_text(size = 12),
    strip.text.y = ggplot2::element_text(size = 12)
  )
print(p)</preformat>
    <fig id="figU003Afig1">
      <caption><p>Scatterplot matrix of the setosa variety of Fisher’s
      iris data.</p></caption>
      <graphic mimetype="image" mime-subtype="png" xlink:href="setosa.png" />
    </fig>
    <p>We specify the null cumulative distribution function, density,
    simulation routine, and parameter estimator:</p>
    <preformat>pnull = function (x, p) {
    f = function(x)
       mvtnorm::pmvnorm(rep(-Inf, length(x)), x,
              mean = p[1:4],
              sigma = matrix(p[5:20], nrow = 4))
    if (!is.matrix(x)) return(f(x))
    apply(x, 1, f)
}
dnull = function (x, p) {
    f = function(x)
       mvtnorm::dmvnorm(x,
              mean = p[1:4],
              sigma = matrix(p[5:20], nrow = 4))
    if (!is.matrix(x)) return(f(x))
    apply(x, 1, f)
}
rnull = function(p) mvtnorm::rmvnorm(50,
              mean = p[1:4],
              sigma = matrix(p[5:20], nrow = 4))
phat = function(x) c(apply(x, 2, mean), cov(x))</preformat>
    <p>The tests can then be run as follows, using a fixed random
    seed:</p>
    <preformat>MDgof::gof_test(setosa, pnull, rnull, B = 1000,
        dnull = dnull, phat = phat, seed = 1234,
        doMethods = &quot;all&quot;, maxProcessor = 1)</preformat>
    <preformat>MDgof multivariate goodness-of-fit tests
Data: continuous  | n = 50  | dimension = 4  | B = 1000

 method statistic p.value
    qKS     0.268   0.000
     qK     0.278   0.000
   qCvM     0.748   0.000
    qAD     8.419   0.083
     BR     1.309   0.564</preformat>
    <p>The individual tests give different results, which motivates
    illustrating the adjusted <inline-formula><alternatives>
    <tex-math><![CDATA[p]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula>-value
    procedure. We use the same five methods in the adjusted test by
    specifying <monospace>doMethods = &quot;all&quot;</monospace>:</p>
    <preformat>MDgof::gof_test_adjusted_pvalue(setosa, pnull, rnull,
        B = 1000, dnull = dnull, phat = phat,
        seed = 1234, doMethods = &quot;all&quot;, maxProcessor = 1)</preformat>
    <preformat>p values of individual tests:
qKS : 0
qK : 0
qCvM : 0
qAD : 0.083
BR : 0.875

adjusted p value of combined tests: 0

  qKS    qK  qCvM   qAD    BR Min p
0.000 0.000 0.000 0.083 0.875 0.000</preformat>
    <p>The adjusted <inline-formula><alternatives>
    <tex-math><![CDATA[p]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula>-value
    is reported as zero at the simulation resolution used here; this is
    a Monte Carlo estimate, not an assertion that the probability is
    exactly zero. The example illustrates both the different responses
    of individual test statistics and the use of the adjusted
    <inline-formula><alternatives>
    <tex-math><![CDATA[p]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula>-value
    routine. A substantive assessment of multivariate normality in these
    measurements is not the purpose of this example.</p>
  </sec>
  <sec id="goals-in-the-english-premier-league">
    <title>Goals in the English Premier League</title>
    <p>For an illustration with discrete bivariate data, we compare the
    joint frequencies of goals scored by home and away teams in the
    English Premier League in 2020–21 and in the available portion of
    2025–26. The original match results were obtained from
    Football-Data.co.uk (Football-Data.co.uk, 2026). The latter season
    was incomplete when the data were collected, so the comparison is
    intended only as a demonstration of the software, not as an
    assessment of changes in football tactics or scoring patterns.</p>
    <p>For simplicity, the example uses the categories 0 through 4 goals
    for each team. Matches in which either team scored five or more
    goals are excluded, so the analysis applies only to the retained
    matches. To make the results independent of future changes to the
    source website, the 25-row frequency table is included directly in
    the replication material. It has columns
    <monospace>vals_x</monospace> and <monospace>vals_y</monospace> for
    home and away goals, and <monospace>x</monospace> and
    <monospace>y</monospace> for the corresponding frequencies in the
    two seasons.</p>
    <preformat>goals_premier_league &lt;- cbind(
  vals_x = rep(0:4, times = 5),
  vals_y = rep(0:4, each = 5),
  x = c(30,33,26,14,6, 38,40,27,13,4,
        23,33,7,7,3, 14,18,7,6,2, 3,4,3,2,0),
  y = c(27,22,29,27,2, 31,47,37,20,6,
        15,27,26,11,3, 10,9,10,3,2, 2,4,1,2,1)
)</preformat>
    <p>We apply the eight tests available by default for these discrete
    data:</p>
    <preformat>MD2sample::twosample_test(goals_premier_league,
                          B = 1000, seed = 1234)</preformat>
    <preformat>MD2sample two-sample tests
Data: discrete  | n.x = 363  | n.y = 374  | dimension = 2  | B = 1000

    method statistic p.value
        KS    0.1314  0.0040
         K    0.1827  0.0020
       CvM    0.4884  0.0410
        AD    2.3511  0.0530
        NN    3.0350  0.0400
        AZ    0.2111  0.0040
        BF    0.3149  0.0040
 ChiSquare   33.1600  0.0445</preformat>
    <p>To illustrate simultaneous inference using the complete
    collection of eight discrete-data methods, we specify
    <monospace>doMethods = &quot;all&quot;</monospace> in
    <monospace>twosample_test_adjusted_pvalue</monospace>. Without this
    option, the routine uses four methods by default: Chi-square,
    Kolmogorov–Smirnov, Aslan–Zech, and Cramér–von Mises.</p>
    <preformat>MD2sample::twosample_test_adjusted_pvalue(
    goals_premier_league, B = 1000, seed = 1234,
    doMethods = &quot;all&quot;)</preformat>
    <preformat>p values of individual tests:
KS: 0.004
K: 0.002
CvM: 0.041
AD: 0.053
NN: 0.04
AZ: 0.004
BF: 0.004
ChiSquare: 0.0445
adjusted p value of combined tests: 0.013</preformat>
    <p>The adjusted <inline-formula><alternatives>
    <tex-math><![CDATA[p]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>p</mml:mi></mml:math></alternatives></inline-formula>-value
    for these eight tests is 0.013. The example demonstrates the use of
    the discrete two-sample procedures and their combined calibration.
    Because the seasons have different coverage and the frequency table
    excludes high-scoring matches, no substantive conclusion about
    changes in Premier League goal-scoring patterns is drawn.</p>
  </sec>
</sec>
<sec id="conclusion">
  <title>Discussion</title>
  <p>Because the relative power of the procedures depends on the null
  distribution, the alternative, the dimension, and the sample size, the
  benchmark results should not be interpreted as general rankings. The
  simulation facilities provided by the packages allow users to compare
  procedures under scenarios relevant to their applications.</p>
  <p>Multivariate goodness-of-fit and two-sample testing present a
  computational comparison problem as much as an implementation problem.
  The large number of available procedures reflects the fact that
  sensitivity to departures from the null varies with the geometry of
  the alternative, dimension, sample size, and treatment of nuisance
  parameters. Consequently, providing another isolated implementation of
  a test does not by itself solve the practical problem faced by
  analysts or the evaluation problem faced by researchers developing new
  methodology.</p>
  <p>The contribution of
  <named-content content-type="sans-serif">MDgof</named-content> and
  <named-content content-type="sans-serif">MD2sample</named-content> is
  a common computational environment in which heterogeneous procedures
  can be applied, calibrated, compared, and benchmarked. Built-in
  statistics cover several methodological families and both continuous
  and discrete data. More importantly, user-defined statistics can enter
  the same testing, Monte Carlo power, simultaneous-inference, and
  benchmarking workflows. The deliberately parallel interfaces of the
  two packages make the computational structure of goodness-of-fit and
  two-sample studies similar from the user’s perspective even though
  their null-generation mechanisms differ.</p>
  <p>The benchmark collections are not intended to identify a
  universally best test. Rather, they provide reproducible scenarios in
  which the strengths and weaknesses of competing statistics can be
  studied under common conditions. This is especially useful when a new
  statistic is proposed: the researcher can compare it with established
  procedures without writing a separate simulation infrastructure for
  every competitor.</p>
  <p>There are also limitations. Some multivariate
  empirical-distribution-function statistics require computational
  approximations, and the cost of resampling-based calibration can be
  substantial for large samples or extensive benchmark grids. The
  framework therefore uses compiled code and parallel processing where
  appropriate, but computational burden remains method dependent. Future
  development can extend the collection of benchmark alternatives,
  incorporate additional testing families, and improve computational
  strategies for large or high-dimensional data.</p>
  <p>In this sense,
  <named-content content-type="sans-serif">MDgof</named-content> and
  <named-content content-type="sans-serif">MD2sample</named-content>
  provide infrastructure for reproducible methodological comparison.
  They provide a common environment in which established and newly
  proposed multivariate goodness-of-fit and two-sample procedures can be
  implemented, evaluated, and compared under controlled simulation
  conditions.</p>
</sec>
<sec id="statements-and-declarations">
  <title>Statements and Declarations</title>
  <p><bold>Funding.</bold> No funds, grants, or other support was
  received.</p>
  <p><bold>Competing interests.</bold> The author has no relevant
  financial or non-financial interests to disclose.</p>
  <p><bold>Generative AI use.</bold> OpenAI ChatGPT (GPT-5.6 Sol) was
  used during manuscript preparation for language and organizational
  assistance, consistency checking, and software coding and debugging
  assistance. All resulting text, code, numerical results, and
  references were reviewed and verified by the author, who takes full
  responsibility for the content of the manuscript.</p>
</sec>
<sec id="data-and-code-availability" sec-type="data-availability">
  <title>Data and Code Availability</title>
  <p><bold>Data availability.</bold> The Fisher iris data are included
  with <named-content content-type="sans-serif">R</named-content>. The
  English Premier League data used in Section 9.2 are publicly available
  from Football-Data.co.uk. The remaining numerical examples and
  simulation studies use data generated by the code and the
  <named-content content-type="sans-serif">MDgof</named-content> and
  <named-content content-type="sans-serif">MD2sample</named-content>
  packages described in the article.</p>
  <p><bold>Code availability.</bold> The
  <named-content content-type="sans-serif">MDgof</named-content> and
  <named-content content-type="sans-serif">MD2sample</named-content>
  packages are publicly available from CRAN. Code needed to reproduce
  the numerical examples is given in the article, and the
  benchmark-generating routines and case studies are included in the
  packages.</p>
</sec>
</body>
<back><ref-list><ref id="ref1"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Aldor-Noiman</surname><given-names>Sivan</given-names></name><name><surname>Brown</surname><given-names>Lawrence D.</given-names></name><name><surname>Buja</surname><given-names>Andreas</given-names></name><name><surname>Rolke</surname><given-names>Wolfgang</given-names></name><name><surname>Stine</surname><given-names>Robert A.</given-names></name></person-group><article-title>The Power to See: A New Graphical Test of Normality</article-title><source>The American Statistician</source><year>2013</year><volume>67</volume><issue>4</issue><fpage>249</fpage><lpage>260</lpage><publisher-name>Informa UK Limited</publisher-name><pub-id pub-id-type="doi">10.1080/00031305.2013.847865</pub-id></element-citation></ref><ref id="ref2"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Anderson</surname><given-names>T. W.</given-names></name></person-group><article-title>On the Distribution of the Two-Sample Cramer-von Mises Criterion</article-title><source>The Annals of Mathematical Statistics</source><year>1962</year><volume>33</volume><issue>3</issue><fpage>1148</fpage><lpage>1159</lpage><publisher-name>Institute of Mathematical Statistics</publisher-name><pub-id pub-id-type="doi">10.1214/aoms/1177704477</pub-id></element-citation></ref><ref id="ref3"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Anderson</surname><given-names>T. W.</given-names></name><name><surname>Darling</surname><given-names>D. A.</given-names></name></person-group><article-title>Asymptotic Theory of Certain &quot;Goodness of Fit&quot; Criteria Based on Stochastic Processes</article-title><source>The Annals of Mathematical Statistics</source><year>1952</year><volume>23</volume><issue>2</issue><fpage>193</fpage><lpage>212</lpage><publisher-name>Institute of Mathematical Statistics</publisher-name><pub-id pub-id-type="doi">10.1214/aoms/1177729437</pub-id></element-citation></ref><ref id="ref4"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Aslan</surname><given-names>B.</given-names></name><name><surname>Zech</surname><given-names>G.</given-names></name></person-group><article-title>New test for the multivariate two-sample problem based on the concept of minimum energy</article-title><source>Journal of Statistical Computation and Simulation</source><year>2005</year><volume>75</volume><issue>2</issue><fpage>109</fpage><lpage>119</lpage><publisher-name>Informa UK Limited</publisher-name><pub-id pub-id-type="doi">10.1080/00949650410001661440</pub-id></element-citation></ref><ref id="ref5"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Bakshaev</surname><given-names>Aleksej</given-names></name><name><surname>Rudzkis</surname><given-names>Rimantas</given-names></name></person-group><article-title>Multivariate goodness-of-fit tests based on kernel density estimators</article-title><source>Nonlinear Analysis: Modelling and Control</source><year>2015</year><volume>20</volume><issue>4</issue><fpage>585</fpage><lpage>602</lpage><publisher-name>Vilnius University Press</publisher-name><pub-id pub-id-type="doi">10.15388/na.2015.4.9</pub-id></element-citation></ref><ref id="ref6"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Baringhaus</surname><given-names>L.</given-names></name><name><surname>Franz</surname><given-names>C.</given-names></name></person-group><article-title>On a new multivariate two-sample test</article-title><source>Journal of Multivariate Analysis</source><year>2004</year><volume>88</volume><issue>1</issue><fpage>190</fpage><lpage>206</lpage><publisher-name>Elsevier BV</publisher-name><pub-id pub-id-type="doi">10.1016/s0047-259x(03)00079-4</pub-id></element-citation></ref><ref id="ref7"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Bickel</surname><given-names>Peter J.</given-names></name><name><surname>Breiman</surname><given-names>Leo</given-names></name></person-group><article-title>Sums of Functions of Nearest Neighbor Distances, Moment Bounds, Limit Theorems and a Goodness of Fit Test</article-title><source>The Annals of Probability</source><year>1983</year><volume>11</volume><issue>1</issue><fpage>185</fpage><lpage>214</lpage><publisher-name>Institute of Mathematical Statistics</publisher-name><pub-id pub-id-type="doi">10.1214/aop/1176993668</pub-id></element-citation></ref><ref id="ref8"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Biswas</surname><given-names>Munmun</given-names></name><name><surname>Ghosh</surname><given-names>Anil K.</given-names></name></person-group><article-title>A nonparametric two-sample test applicable to high dimensional data</article-title><source>Journal of Multivariate Analysis</source><year>2014</year><volume>123</volume><fpage>160</fpage><lpage>171</lpage><publisher-name>Elsevier BV</publisher-name><pub-id pub-id-type="doi">10.1016/j.jmva.2013.09.004</pub-id></element-citation></ref><ref id="ref9"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Chen</surname><given-names>Hao</given-names></name><name><surname>Friedman</surname><given-names>Jerome H.</given-names></name></person-group><article-title>A New Graph-Based Two-Sample Test for Multivariate and Object Data</article-title><source>Journal of the American Statistical Association</source><year>2017</year><volume>112</volume><issue>517</issue><fpage>397</fpage><lpage>409</lpage><publisher-name>Informa UK Limited</publisher-name><pub-id pub-id-type="doi">10.1080/01621459.2016.1147356</pub-id></element-citation></ref><ref id="ref10"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Cramér</surname><given-names>Harald</given-names></name></person-group><article-title>On the composition of elementary errors: First paper: Mathematical deductions</article-title><source>Scandinavian Actuarial Journal</source><year>1928</year><volume>1928</volume><issue>1</issue><fpage>13</fpage><lpage>74</lpage><publisher-name>Informa UK Limited</publisher-name><pub-id pub-id-type="doi">10.1080/03461238.1928.10416862</pub-id></element-citation></ref><ref id="ref11"><mixed-citation>Eddelbuettel, D., François, R., Allaire, J., Ushey, K., Kou, Q., Russell, N., Ucar, I., Bates, D., &amp; Chambers, J. (2024). Rcpp: Seamless r and c++ integration [R package version 1.1.1-1.1]. https://CRAN.R-project.org/package=Rcpp</mixed-citation></ref><ref id="ref12"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Fasano</surname><given-names>G.</given-names></name><name><surname>Franceschini</surname><given-names>A.</given-names></name></person-group><article-title>A multidimensional version of the Kolmogorov–Smirnov test</article-title><source>Monthly Notices of the Royal Astronomical Society</source><year>1987</year><volume>225</volume><issue>1</issue><fpage>155</fpage><lpage>170</lpage><publisher-name>Oxford University Press (OUP)</publisher-name><pub-id pub-id-type="doi">10.1093/mnras/225.1.155</pub-id></element-citation></ref><ref id="ref13"><mixed-citation>Fisher, R. A. (1936). The use of multiple measurements in taxonomic problems. Annals of Eugenics, 7(2), 179–188. https://doi.org/10.1111/j.1469-1809.1936.tb02137.x</mixed-citation></ref><ref id="ref14"><mixed-citation>Football-Data.co.uk. (2026). Historical football match results data archive.</mixed-citation></ref><ref id="ref15"><mixed-citation>Franz, C. (2024). Cramer: Multivariate nonparametric cramer-test for the two-sample-problem [R package version 0.9-4]. https://CRAN.R-project.org/package=cramer</mixed-citation></ref><ref id="ref16"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Friedman</surname><given-names>Jerome H.</given-names></name><name><surname>Rafsky</surname><given-names>Lawrence C.</given-names></name></person-group><article-title>Multivariate Generalizations of the Wald-Wolfowitz and Smirnov Two-Sample Tests</article-title><source>The Annals of Statistics</source><year>1979</year><volume>7</volume><issue>4</issue><fpage>697</fpage><lpage>717</lpage><publisher-name>Institute of Mathematical Statistics</publisher-name><pub-id pub-id-type="doi">10.1214/aos/1176344722</pub-id></element-citation></ref><ref id="ref17"><mixed-citation>Gretton, A., Sejdinovic, D., Strathmann, H., Balakrishnan, S., Pontil, M., Fukumizu, K., &amp; Sriperumbudur, B. K. (2012). Optimal kernel choice for large scale two sample tests. Advances in Neural Information Processing Systems (NIPS), 1205–1213.</mixed-citation></ref><ref id="ref18"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Karatzoglou</surname><given-names>Alexandros</given-names></name><name><surname>Smola</surname><given-names>Alex</given-names></name><name><surname>Hornik</surname><given-names>Kurt</given-names></name><name><surname>Zeileis</surname><given-names>Achim</given-names></name></person-group><article-title>kernlab
                    - An
                    &lt;i&gt;S4&lt;/i&gt;
                    Package for Kernel Methods in
                    &lt;i&gt;R&lt;/i&gt;</article-title><source>Journal of Statistical Software</source><year>2004</year><volume>11</volume><issue>9</issue><publisher-name>Foundation for Open Access Statistic</publisher-name><pub-id pub-id-type="doi">10.18637/jss.v011.i09</pub-id></element-citation></ref><ref id="ref19"><mixed-citation>Kolmogorov, A. N. (1933). Sulla determinazione empirica di una legge di distribuzione. Giornale Dell’Instituto Italiano Degli Attuari, 4, 83–91.</mixed-citation></ref><ref id="ref20"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Kuiper</surname><given-names>Nicolaas H.</given-names></name></person-group><article-title>Tests concerning random points on a circle</article-title><source>Indagationes Mathematicae (Proceedings)</source><year>1960</year><volume>63</volume><fpage>38</fpage><lpage>47</lpage><publisher-name>Elsevier BV</publisher-name><pub-id pub-id-type="doi">10.1016/s1385-7258(60)50006-0</pub-id></element-citation></ref><ref id="ref21"><element-citation publication-type="book"><person-group person-group-type="author"><name><surname>von Mises</surname><given-names>Richard</given-names></name></person-group><article-title>Wahrscheinlichkeit Statistik und Wahrheit</article-title><year>1928</year><publisher-name>Springer Berlin Heidelberg</publisher-name><pub-id pub-id-type="doi">10.1007/978-3-662-36230-3</pub-id></element-citation></ref><ref id="ref22"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Pan</surname><given-names>Wenliang</given-names></name><name><surname>Tian</surname><given-names>Yuan</given-names></name><name><surname>Wang</surname><given-names>Xueqin</given-names></name><name><surname>Zhang</surname><given-names>Heping</given-names></name></person-group><article-title>Ball Divergence: Nonparametric two sample test</article-title><source>The Annals of Statistics</source><year>2018</year><volume>46</volume><issue>3</issue><fpage>1109</fpage><lpage>1137</lpage><publisher-name>Institute of Mathematical Statistics</publisher-name><pub-id pub-id-type="doi">10.1214/17-AOS1579</pub-id></element-citation></ref><ref id="ref23"><mixed-citation>Pettitt, A. N. (1976). A two-sample anderson-darling rank statistic. Biometrika, 63(1), 161–168.</mixed-citation></ref><ref id="ref24"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Puritz</surname><given-names>Connor</given-names></name><name><surname>Ness-Cohn</surname><given-names>Elan</given-names></name><name><surname>Braun</surname><given-names>Rosemary</given-names></name></person-group><article-title>fasano.franceschini.test: An Implementation of a Multivariate KS Test in R</article-title><source>The R Journal</source><year>2023</year><volume>15</volume><issue>3</issue><fpage>159</fpage><lpage>171</lpage><publisher-name>The R Foundation</publisher-name><pub-id pub-id-type="doi">10.32614/RJ-2023-067</pub-id></element-citation></ref><ref id="ref25"><mixed-citation>Rayner, J. C. W., Thas, O., &amp; Best, D. J. (2009). Smooth tests of goodness of fit. Wiley.</mixed-citation></ref><ref id="ref26"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Ripley</surname><given-names>B. D.</given-names></name></person-group><article-title>The second-order analysis of stationary point processes</article-title><source>Journal of Applied Probability</source><year>1976</year><volume>13</volume><issue>2</issue><fpage>255</fpage><lpage>266</lpage><publisher-name>Cambridge University Press (CUP)</publisher-name><pub-id pub-id-type="doi">10.2307/3212829</pub-id></element-citation></ref><ref id="ref27"><mixed-citation>Rizzo, M. L., &amp; Székely, G. J. (2024). Energy: E-statistics: Multivariate inference via the energy of data [R package version 1.7-12]. https://CRAN.R-project.org/package=energy</mixed-citation></ref><ref id="ref28"><element-citation publication-type="journal"><person-group person-group-type="author"><name><surname>Rolke</surname><given-names>Wolfgang</given-names></name></person-group><article-title>Rgof and R2sample: Testing and Benchmarking for the Univariate Goodness-of-Fit and Two-Sample Problems</article-title><source>The R Journal</source><year>2025</year><volume>17</volume><issue>3</issue><fpage>138</fpage><lpage>161</lpage><publisher-name>The R Foundation</publisher-name><pub-id pub-id-type="doi">10.32614/rj-2025-027</pub-id></element-citation></ref><ref id="ref29"><mixed-citation>Rolke, W. (2026a). MD2sample: Various methods for the two-sample problem in D&gt;1D &gt; 1 dimensions [R package version 1.4.2]. https://doi.org/10.32614/CRAN.package.MD2sample</mixed-citation></ref><ref id="ref30"><mixed-citation>Rolke, W. (2026b). MDgof: Various methods for the goodness-of-fit problem in D&gt;1D &gt; 1 dimensions [R package version 1.2.1]. https://doi.org/10.32614/CRAN.package.MDgof</mixed-citation></ref><ref id="ref31"><mixed-citation>Smirnov, N. V. (1939). Estimate of deviation between empirical distribution functions in two independent samples. Bulletin of Moscow University, 2, 3–16.</mixed-citation></ref><ref id="ref32"><mixed-citation>Thas, O. (2010). Comparing distributions. Springer.</mixed-citation></ref><ref id="ref33"><mixed-citation>Westfall, P. H., &amp; Young, S. S. (1993). Resampling-based multiple testing: Examples and methods for p-value adjustment. John Wiley &amp; Sons.</mixed-citation></ref></ref-list>
<ref-list>
  <title>References</title>
  <ref id="ref-aldor2013">
    <mixed-citation>Aldor-Noiman, S., Brown, L. D., Buja, A., Rolke, W.,
    &amp; Stine, R. A. (2013). The power to see: A new graphical test of
    normality. <italic>The American Statistician</italic>,
    <italic>67</italic>(4), 249–260.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1080/00031305.2013.847865">https://doi.org/10.1080/00031305.2013.847865</ext-link></mixed-citation>
  </ref>
  <ref id="ref-Anderson1962">
    <mixed-citation>Anderson, T. W. (1962). On the distribution of the
    two-sample cramer–von mises criterion. <italic>The Annals of
    Mathematical Statistics</italic>, <italic>33</italic>(3),
    1148–1159.</mixed-citation>
  </ref>
  <ref id="ref-anderson1952">
    <mixed-citation>Anderson, T. W., &amp; Darling, D. A. (1952).
    Asymptotic theory of certain goodness-of-fit criteria based on
    stochastic processes. <italic>The Annals of Mathematical
    Statistics</italic>, <italic>23</italic>(2),
    193–212.</mixed-citation>
  </ref>
  <ref id="ref-aslanzech2005">
    <mixed-citation>Aslan, B., &amp; Zech, G. (2005). New test for the
    multivariate two-sample problem based on the concept of minimum
    energy. <italic>Journal of Statistical Computation and
    Simulation</italic>, <italic>75</italic>(2), 109–119.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1080/00949650410001661440">https://doi.org/10.1080/00949650410001661440</ext-link></mixed-citation>
  </ref>
  <ref id="ref-bakshaev2015">
    <mixed-citation>Bakshaev, A., &amp; Rudzkis, R. (2015). Multivariate
    goodness-of-fit tests based on kernel density estimators.
    <italic>Nonlinear Analysis: Modelling and Control</italic>,
    <italic>20</italic>(4), 585–602.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.15388/na.2015.4.9">https://doi.org/10.15388/na.2015.4.9</ext-link></mixed-citation>
  </ref>
  <ref id="ref-baringhaus2004">
    <mixed-citation>Baringhaus, L., &amp; Franz, C. (2004). On a new
    multivariate two-sample test. <italic>Journal of Multivariate
    Analysis</italic>, <italic>88</italic>(1), 190–206.</mixed-citation>
  </ref>
  <ref id="ref-bickel1983">
    <mixed-citation>Bickel, P. J., &amp; Breiman, L. (1983). Sums of
    functions of nearest neighbor distances, moment bounds, limit
    theorems and a goodness of fit test. <italic>The Annals of
    Probability</italic>, <italic>11</italic>(1), 185–214.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1214/aop/1176993668">https://doi.org/10.1214/aop/1176993668</ext-link></mixed-citation>
  </ref>
  <ref id="ref-biswas2014">
    <mixed-citation>Biswas, M., &amp; Ghosh, A. (2014). A nonparametric
    two-sample test applicable to high-dimensional data. <italic>Journal
    of Multivariate Analysis</italic>, <italic>123</italic>,
    160–171.</mixed-citation>
  </ref>
  <ref id="ref-chen2017">
    <mixed-citation>Chen, H., &amp; Friedman, J. H. (2017). A new
    graph-based two-sample test for multivariate and object data.
    <italic>Journal of the American Statistical Association</italic>,
    <italic>112</italic>(517), 397–409.</mixed-citation>
  </ref>
  <ref id="ref-cramer1928">
    <mixed-citation>Cramér, H. (1928). On the composition of elementary
    errors. <italic>Scandinavian Actuarial Journal</italic>,
    <italic>1928</italic>(1), 13–74.</mixed-citation>
  </ref>
  <ref id="ref-rcpp2024">
    <mixed-citation>Eddelbuettel, D., François, R., Allaire, J., Ushey,
    K., Kou, Q., Russell, N., Ucar, I., Bates, D., &amp; Chambers, J.
    (2024). <italic>Rcpp: Seamless r and c++ integration</italic> [R
    package version 1.1.1-1.1].
    <ext-link ext-link-type="uri" xlink:href="https://CRAN.R-project.org/package=Rcpp">https://CRAN.R-project.org/package=Rcpp</ext-link></mixed-citation>
  </ref>
  <ref id="ref-Fasano1987">
    <mixed-citation>Fasano, G., &amp; Franceschini, A. (1987). A
    multidimensional version of the kolmogorov–smirnov test.
    <italic>Monthly Notices of the Royal Astronomical Society</italic>,
    <italic>225</italic>(1), 155–170.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1093/mnras/225.1.155">https://doi.org/10.1093/mnras/225.1.155</ext-link></mixed-citation>
  </ref>
  <ref id="ref-fisher1936">
    <mixed-citation>Fisher, R. A. (1936). The use of multiple
    measurements in taxonomic problems. <italic>Annals of
    Eugenics</italic>, <italic>7</italic>(2), 179–188.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1111/j.1469-1809.1936.tb02137.x">https://doi.org/10.1111/j.1469-1809.1936.tb02137.x</ext-link></mixed-citation>
  </ref>
  <ref id="ref-footballdata">
    <mixed-citation>Football-Data.co.uk. (2026). <italic>Historical
    football match results data archive</italic>.</mixed-citation>
  </ref>
  <ref id="ref-cramerPackage">
    <mixed-citation>Franz, C. (2024). <italic>Cramer: Multivariate
    nonparametric cramer-test for the two-sample-problem</italic> [R
    package version 0.9-4].
    <ext-link ext-link-type="uri" xlink:href="https://CRAN.R-project.org/package=cramer">https://CRAN.R-project.org/package=cramer</ext-link></mixed-citation>
  </ref>
  <ref id="ref-friedman1979">
    <mixed-citation>Friedman, J. H., &amp; Rafsky, L. C. (1979).
    Multivariate generalizations of the wald–wolfowitz and smirnov
    two-sample tests. <italic>The Annals of Statistics</italic>,
    <italic>7</italic>(4), 697–717.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1214/aos/1176344722">https://doi.org/10.1214/aos/1176344722</ext-link></mixed-citation>
  </ref>
  <ref id="ref-gretton2012B">
    <mixed-citation>Gretton, A., Sejdinovic, D., Strathmann, H.,
    Balakrishnan, S., Pontil, M., Fukumizu, K., &amp; Sriperumbudur, B.
    K. (2012). Optimal kernel choice for large scale two sample tests.
    <italic>Advances in Neural Information Processing Systems
    (NIPS)</italic>, 1205–1213.</mixed-citation>
  </ref>
  <ref id="ref-kernlabPackage">
    <mixed-citation>Karatzoglou, A., Smola, A., Hornik, K., &amp;
    Zeileis, A. (2004). Kernlab – an S4 package for kernel methods in r.
    <italic>Journal of Statistical Software</italic>,
    <italic>11</italic>(9), 1–20.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.18637/jss.v011.i09">https://doi.org/10.18637/jss.v011.i09</ext-link></mixed-citation>
  </ref>
  <ref id="ref-Kolmogorov1933">
    <mixed-citation>Kolmogorov, A. N. (1933). Sulla determinazione
    empirica di una legge di distribuzione. <italic>Giornale
    Dell’Instituto Italiano Degli Attuari</italic>, <italic>4</italic>,
    83–91.</mixed-citation>
  </ref>
  <ref id="ref-Kuiper1960">
    <mixed-citation>Kuiper, N. H. (1960). Tests concerning random points
    on a circle. <italic>Proceedings of the Koninklijke Nederlandse
    Akademie van Wetenschappen</italic>, <italic>63</italic>,
    38–47.</mixed-citation>
  </ref>
  <ref id="ref-mises1928">
    <mixed-citation>Mises, R. E. von. (1928).
    <italic>Wahrscheinlichkeit, statistik und wahrheit</italic>.
    Springer.</mixed-citation>
  </ref>
  <ref id="ref-ball2018">
    <mixed-citation>Pan, W., Tian, Y., Wang, X., &amp; Zhang, H. (2018).
    Ball divergence: Nonparametric two-sample test. <italic>The Annals
    of Statistics</italic>, <italic>46</italic>(3), 1109–1137.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.1214/17-AOS1579">https://doi.org/10.1214/17-AOS1579</ext-link></mixed-citation>
  </ref>
  <ref id="ref-pettitt1976">
    <mixed-citation>Pettitt, A. N. (1976). A two-sample anderson-darling
    rank statistic. <italic>Biometrika</italic>, <italic>63</italic>(1),
    161–168.</mixed-citation>
  </ref>
  <ref id="ref-fasanoPackage">
    <mixed-citation>Puritz, C., Ness-Cohn, E., &amp; Braun, R. (2023).
    Fasano.franceschini.test: An implementation of a multivariate KS
    test in r. <italic>The R Journal</italic>, <italic>15</italic>(3),
    159–171.
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.32614/RJ-2023-067">https://doi.org/10.32614/RJ-2023-067</ext-link></mixed-citation>
  </ref>
  <ref id="ref-raynor2009">
    <mixed-citation>Rayner, J. C. W., Thas, O., &amp; Best, D. J.
    (2009). <italic>Smooth tests of goodness of fit</italic>.
    Wiley.</mixed-citation>
  </ref>
  <ref id="ref-ripley1976">
    <mixed-citation>Ripley, B. D. (1976). The second-order analysis of
    stationary point processes. <italic>Journal of Applied
    Probability</italic>, <italic>13</italic>(2),
    255–266.</mixed-citation>
  </ref>
  <ref id="ref-energyPackage">
    <mixed-citation>Rizzo, M. L., &amp; Székely, G. J. (2024).
    <italic>Energy: E-statistics: Multivariate inference via the energy
    of data</italic> [R package version 1.7-12].
    <ext-link ext-link-type="uri" xlink:href="https://CRAN.R-project.org/package=energy">https://CRAN.R-project.org/package=energy</ext-link></mixed-citation>
  </ref>
  <ref id="ref-rolke2025">
    <mixed-citation>Rolke, W. (2025). Rgof and R2sample: Testing and
    benchmarking for the univariate goodness-of-fit and two-sample
    problems. <italic>The R Journal</italic>, <italic>17</italic>(3),
    138–161.
    <ext-link ext-link-type="uri" xlink:href="https://journal.r-project.org/articles/RJ-2025-027/">https://journal.r-project.org/articles/RJ-2025-027/</ext-link></mixed-citation>
  </ref>
  <ref id="ref-MD2sample">
    <mixed-citation>Rolke, W. (2026a). <italic>MD2sample: Various
    methods for the two-sample problem in <inline-formula><alternatives>
    <tex-math><![CDATA[D > 1]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>D</mml:mi><mml:mo>&gt;</mml:mo><mml:mn>1</mml:mn></mml:mrow></mml:math></alternatives></inline-formula>
    dimensions</italic> [R package version 1.4.2].
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.32614/CRAN.package.MD2sample">https://doi.org/10.32614/CRAN.package.MD2sample</ext-link></mixed-citation>
  </ref>
  <ref id="ref-MDgof">
    <mixed-citation>Rolke, W. (2026b). <italic>MDgof: Various methods
    for the goodness-of-fit problem in <inline-formula><alternatives>
    <tex-math><![CDATA[D > 1]]></tex-math>
    <mml:math display="inline" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>D</mml:mi><mml:mo>&gt;</mml:mo><mml:mn>1</mml:mn></mml:mrow></mml:math></alternatives></inline-formula>
    dimensions</italic> [R package version 1.2.1].
    <ext-link ext-link-type="uri" xlink:href="https://doi.org/10.32614/CRAN.package.MDgof">https://doi.org/10.32614/CRAN.package.MDgof</ext-link></mixed-citation>
  </ref>
  <ref id="ref-Smirnov1939">
    <mixed-citation>Smirnov, N. V. (1939). Estimate of deviation between
    empirical distribution functions in two independent samples.
    <italic>Bulletin of Moscow University</italic>, <italic>2</italic>,
    3–16.</mixed-citation>
  </ref>
  <ref id="ref-thas2010">
    <mixed-citation>Thas, O. (2010). <italic>Comparing
    distributions</italic>. Springer.</mixed-citation>
  </ref>
  <ref id="ref-westfall1993">
    <mixed-citation>Westfall, P. H., &amp; Young, S. S. (1993).
    <italic>Resampling-based multiple testing: Examples and methods for
    p-value adjustment</italic>. John Wiley &amp; Sons.</mixed-citation>
  </ref>
</ref-list>
</back>
</article>
