Skip to content

Methods and checksMethods

How every result is reached and what it was checked against, app by app.

Methods and checks pages

Two-sample Kolmogorov–Smirnov test, two-sided, with the exact null distribution, version 1.0.1

stats-ks-two-sample@1.0.1: this version's equations with their symbols, each constant's value, their sources and whether each was read, a worked example where the record holds one, its level and what it was checked against, the number of cases, and what was not checked. This version's record is not rewritten; a correction is added under Changes.

What this page can and cannot show

Level: Checked against a reference; SciPy 1.18.1 where p ≥ 1e-3, exact rational path counts below; Hodges not read; continuous data only. Reference kind: an outside program, exact path counts and enumeration (Python fractions), 3.13.18; an outside program, SciPy, 1.18.1; a reference program this project wrote itself, second implementation (Python 3.13, standard library), 2026-11-14, double-precision recursion, the corridor test in integers (|i n - j m| >= N); small cases checked by the agent against exact rational enumeration; not an outside program.

Checked by this project, not independently reviewed. Every method on this page has its equations, constants, sources and cases on record, and its cases agree with the stated reference within the stated tolerance. A reader can follow each method's worked example by hand; that shows the stated method gives the stated answer for one set of inputs, and does not test the code. The other cases and their values are not printed, so a reader cannot re-run these checks. No independent scientist has yet reviewed them.

Every version of this method · Every method · What the levels mean

Version 1.0.1

Level: Checked against a reference; SciPy 1.18.1 where p ≥ 1e-3, exact rational path counts below; Hodges not read; continuous data only. Reference kind: an outside program, exact path counts and enumeration (Python fractions), 3.13.18; an outside program, SciPy, 1.18.1; a reference program this project wrote itself, second implementation (Python 3.13, standard library), 2026-11-14, double-precision recursion, the corridor test in integers (|i n - j m| >= N); small cases checked by the agent against exact rational enumeration; not an outside program. stats-ks-two-sample@1.0.1

Built, not hosted. Generated from a snapshot of the library's records taken on 2026-11-25, as committed on 2026-11-25. A later snapshot replaces this one, so these records and this page can change.

Verification statement: Two-sided, exact only: the stabilised lattice-path recursion (Viehmann 2021, arXiv:2102.08037v2, §1, p. 3) in double precision, to 10,000 values per sample; no asymptotic p. Viehmann re-read at source on 14 November 2026. Compared with SciPy 1.18.1 ks_2samp(method="exact") where p ≥ 1e-3 (relative 1e-10), with exact rational path counts and enumeration, and with a second implementation in Python written from the source by a separate agent of the same model family (70 cases, 24 at the edges). p below 1e-300 is withheld as a bound; p is withheld on ties. Hodges 1957/58 not read.

From two independent samples of a continuous measurement in one unit, the Kolmogorov–Smirnov statistic D (the largest gap between the two empirical distribution functions) and its exact two-sided p-value P(D ≥ D_obs) under the null of one continuous distribution, by the stabilised lattice-path recursion in double precision; p withheld unless the values are declared independent replicates, on any tie, and given as a bound below 1e-300.

  • How results are reported: p in full double precision, or withheld; a p above the caller's level means no difference in distribution was shown at these sizes; it never means the samples come from the same distribution
  • Uncertainty: A p-value is reported without an interval; it is exact under the null, computed in double precision.
  • Reference, as its record states it: SciPy 1.18.1 ks_2samp (exact), exact rational path counts and a second implementation in Python
  • Level confirmed by this project's ruling of 14 November 2026

What this page can and cannot show

What was checked

109 cases in 3 files, linked by this exact version.

Run through the tool at build against an outside program, exact path counts and enumeration (Python fractions), 3.13.18; an outside program, SciPy, 1.18.1; a reference program this project wrote itself, second implementation (Python 3.13, standard library), 2026-11-14, double-precision recursion, the corridor test in integers (|i n - j m| >= N); small cases checked by the agent against exact rational enumeration; not an outside program: 90 agree within the tolerance the file states, 19 refuse as the case expects, 0 differ, 0 were not run.

  • File 1, 39 cases

    • Where the expected values came from: an outside program, exact path counts and enumeration (Python fractions) 3.13.18
    • Recorded on: 2026-11-10
    • Reference: exact path counts and enumeration (Python fractions), 3.13.18; licence PSF-2.0
    • Tolerance as the file states it: p relative 1e-10 (absolute 1e-307 below 1e-297; Drybench's B4); D, m, n, the bound, statuses, codes and strings exact
  • File 2, 8 cases

    • Where the expected values came from: an outside program, SciPy 1.18.1
    • Recorded on: 2026-11-10
    • Reference: SciPy, 1.18.1; licence BSD-3-Clause
    • Tolerance as the file states it: p relative 1e-10 (absolute 1e-307 below 1e-297; Drybench's B4); D, m, n, the bound, statuses, codes and strings exact
  • File 3, 62 cases

    • Where the expected values came from: an outside program, second implementation (Python 3.13, standard library) 2026-11-14
    • Recorded on: 2026-11-14
    • Reference: second implementation (Python 3.13, standard library), 2026-11-14; licence BSD-3-Clause
    • Tolerance as the file states it: p relative 1e-10 (absolute 1e-307 below 1e-297); D relative 1e-15 (absolute 1e-315 below 1e-300); m, n, the bound, statuses, codes and strings exact

Apart from the worked example, the cases and their values are not printed here. This shows agreement with this project's recorded cases. It does not show that a method suits your work, and it is not a qualification.

What was not checked

One-sided alternatives; the asymptotic (Smirnov) p, not served in 1.0.0; a conditional (permutation) p for tied data; one-sample tests (not offered; Lilliefors is not in P7 1.0.0, Drybench's P7 plan, red line 1); Hodges 1957/58 and Smirnov's papers are not read (the recursion and the null are taken from Viehmann 2021, a technical report).

Equations

Equation 1

D = max over the pooled values v of |F_m(v) − G_n(v)|, F_m(v) = #{xᵢ ≤ v}/m, G_n(v) = #{yⱼ ≤ v}/n
held exactly as N/(m·n), N = max |i·n − j·m| over the observed path, i and j the numbers of first- and second-sample values at or below each pooled value in ascending order
Symbol Meaning and unit
D statistic
i first-sample values at or below the pooled value
j second-sample values at or below the pooled value
m first sample's size
n second sample's size

Source: Viehmann T. Numerically more stable computation of the p-values for the two-sample Kolmogorov-Smirnov test. MathInf Technical Report 2021-1, arXiv:2102.08037v2 [stat.CO], 23 September 2021, section p. 1: Fm, Gn and D = sup_x |Fm(x) − Gn(x)| (a maximum here), arXiv:2102.08037v2 (the latest version); read in full on 2026-11-10 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning e848bde554d6. Free to read (arXiv non-exclusive licence to distribute), checked 2026-11-11. No erratum found (searched arXiv API listing of 2102.08037: v2 is the latest version), 2026-11-11.

Equation 2

under H0 with all values distinct and the values declared independent replicates (replicates 'independent'
p is withheld for 'technical' or 'unspecified'), each of the C(m+n, m) orderings of the pooled sample is equally likely
each ordering is a lattice path from (0, 0) to (m, n), one step in i for each first-sample value and one in j for each second-sample value in ascending order, and D is the largest |i/m − j/n| it reaches
Symbol Meaning and unit
C(m+n, m) number of orderings
i, j path coordinates: first- and second-sample values taken so far

Source: Viehmann T. Numerically more stable computation of the p-values for the two-sample Kolmogorov-Smirnov test. MathInf Technical Report 2021-1, arXiv:2102.08037v2 [stat.CO], 23 September 2021, section section 1, p. 2: the combinatorial null and the path map, arXiv:2102.08037v2 (the latest version); read in full on 2026-11-10 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning e848bde554d6. Free to read (arXiv non-exclusive licence to distribute), checked 2026-11-11. No erratum found (searched arXiv API listing of 2102.08037: v2 is the latest version), 2026-11-11.

Equation 3

C_{i,j} = 1 if |i·n − j·m| ≥ N
0 if inside and i = 0 or j = 0
otherwise C_{i−1,j}·i/(i+j) + C_{i,j−1}·j/(i+j)
p = C_{m,n} = P(D ≥ D_obs). The boundary is the text's ≥, compared as integers (two source anomalies, neither followed: Listing 1 tests >, and p. 2 says the strict corridor gives "D ≤ d" where it gives D < d)
Symbol Meaning and unit
C proportion of paths to (i, j) leaving the corridor
p two-sided p-value

Source: Viehmann T. Numerically more stable computation of the p-values for the two-sample Kolmogorov-Smirnov test. MathInf Technical Report 2021-1, arXiv:2102.08037v2 [stat.CO], 23 September 2021, section section 1, p. 3: the stabilised recursion for the inside method, derived from Hodges' A recursion (p. 2), which Viehmann attributes to Hodges [2]; Hodges not read, arXiv:2102.08037v2 (the latest version); read in full on 2026-11-10 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning e848bde554d6. Free to read (arXiv non-exclusive licence to distribute), checked 2026-11-11. No erratum found (searched arXiv API listing of 2102.08037: v2 is the latest version), 2026-11-11.

Conventions

What each mode computes:

  • alternative = two-sided: P(D ≥ D_obs) under the null that both samples come from one continuous distribution, with D the largest absolute gap between the two empirical distribution functions.

Constants

Constants: none used.

Worked example

Worked example: one case of stats-ks-two-sample@1.0.1, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

Inputs

  • x.values[0] = 1
  • x.values[1] = 2
  • x.unit = 1
  • y.values[0] = 3
  • y.values[1] = 4
  • y.unit = 1
  • replicates = independent
  • alternative = two-sided

Steps

  1. d = 1, from x, y; by equation 1; gives d.
  2. p = 0.33333333, from d; by equation 3; gives p.

The working, as the case writes it:

D = 1
of the 6 orderings only xxyy and yyxx reach |i/m - j/n| = 1, so P(D >= 1) = 2/6 = 1/3

Answer

  • d = 1
  • p = 0.33333333

Where these values came from: an outside program, exact path counts and enumeration (Python fractions) 3.13.18; exact rational P by Hodges' inside recursion (Viehmann 2021, p. 2); equal to brute-force enumeration of all C(m+n, m) orderings.

At build the tool returned this answer within the tolerance the file states: p relative 1e-10 (absolute 1e-307 below 1e-297; Drybench's B4); D, m, n, the bound, statuses, codes and strings exact.

Who worked this case: not recorded.

Changes

No correction is logged for stats-ks-two-sample@1.0.1.

Tools that use it

Cite this version

Two-sample Kolmogorov–Smirnov test, two-sided, with the exact null distribution. Drybench; stats-ks-two-sample@1.0.1; https://www.drybench.com/methods/m/stats-ks-two-sample/1.0.1 (accessed [date]).