Skip to main content

L-Test — Shift-Invariant Two-Sample CvM Variant

Two-sample L-test (shift-invariant Cramér–von Mises variant).

Performs the two-sample L-test. The L-test is a shift-invariant modification of the Cramér–von Mises (CvM) two-sample test [1] that minimizes the integral squared difference between two empirical CDFs (L_2 squared distance), called U, by optimizing a scalar location shift, s, between samples. For independent samples X = {X_i}{i=1..n} and Y = {Y_j}{j=1..m}, the null hypothesis is:

H0: ∃ s ∈ ℝ such that F_X(t) = F_Y(t + s) for all t

i.e., samples X and Y are draws from the same (unspecified) continuous distribution up to a location difference.

It returns a Monte-Carlo p-value, its uncertainty, a shift estimate, its uncertainty, and the minimized statistic.

Motivation

Originally developed for ultra–high-energy cosmic-ray (UHECR) composition work comparing X_max distributions to model predictions, where model means have larger uncertainty than higher moments (such that there is significant CI overlap) [2]. The L-test is useful whenever relative location may be biased (instrument/location/seasonal effects, unknown inter-experiment offsets), and/or shape differences (variance, skew, tails, multimodality) are of primary interest. See Appendix B (“L-test”) of the author’s Ph.D. thesis for background and derivations [3].

Install

#Prerequisets
pip install numpy scipy

#Install ltest from pip
pip install ltest-shift

# or local install from source
pip install -e .

Usage

import numpy as np
from ltest import ltest

rng = np.random.default_rng(0)
x = rng.normal(size=200)
y = rng.normal(loc=0.3, scale=1.2, size=220)

l_p, l_p_err, l_shift, shift_boot, shift_err, l_stat = ltest(
    x, y, B=1000, tol_p=0.05, tol_s=0.05, workers=None, brute=False
)
print(l_p, l_p_err, l_shift, shift_err)

Notes

  • The L statistic equals the minimized version of Eq. (9) in Anderson [6] when including a free location parameter. Minimization is performed numerically (scalar search).
  • The L-shift is generally interpretable as a location offset only when the L-test fails to reject (i.e., shapes appear compatible) or the two parent distributions are symmetrical. Under shape mismatch, it is a nuisance alignment chosen to minimize the ECDF distance and should not be interpreted as a population location difference.
  • Parallel bootstrap with early stopping by relative error on p or on the shift uncertainty.
  • Optional “brute” search of s via rank-change breakpoints (slower).
  • See examples/ for Type I/II power and shift-accuracy experiments.
  • Run tests via tests/test_basic.py. Uses pytest -q.
  • On Windows/macOS, protect the entry point when using multiprocessing:
    if __name__ == "__main__":
        # call ltest(...)
    

This is new code based upon the statistical distribution test proposed in the author's 2017 Ph.D. thesis [3] and was used for the conference paper 'Study of UHECR Composition Using Telescope Array’s Middle Drum Detector and Surface Array in Hybrid Mode', 34th ICRC, 2016. Additionally, the paper The Astrophysical Journal, 858:76 (27pp), 2018 May 10 used a similar principle.

References

[1] https://en.wikipedia.org/wiki/Cramer-von_Mises_criterion
[2] Abbasi, R. U., Thomson, G. B., uncertainty from extrapolation of cosmic ray air shower parameters arXiv:1605.05241
[3] Lundquist, J.P. Energy Anisotropies of Proton-Like Ultra-High Energy Cosmic Rays, Ph.D. Thesis, University of Utah, 2017
[4] Pebay, P.P. (2008) Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments, Sandia National Laboratories Technical Report
[5] Scholz, F. W and Stephens, M. A. (1987), K-Sample Anderson-Darling Tests, Journal of the American Statistical Association, Vol. 82, pp. 918-924
[6] Anderson, T.W., On the distribution of the two-sampleCramer-von-Mises criterion. The Annals of Mathematical Statistics, pp. 1148-1159

Dependencies

  • Python ≥ 3.8
  • NumPy ≥ 1.23
  • SciPy ≥ 1.9

License

This project is licensed under the MIT license.
See the full text in LICENSE.

Release files for ltest-shift 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ltest-shift 0.1.1
File Size Uploaded
ltest_shift-0.1.1.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ltest-shift 0.1.1
File Interpreter ABI Platform
ltest_shift-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.3 kB

Release files / ltest_shift-0.1.1.tar.gz

Download URL ltest_shift-0.1.1.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
552c488f87b6e7571165a2b20bc6f74cc88e7b6253ff6187d280e0b279ece71b
BLAKE2b-256 checksum
How to use checksums
0699f99fb62f77484f6f70ad0b5b7e7f3d50127245965bf4a705cbef54263efc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / ltest_shift-0.1.1-py3-none-any.whl

Download URL ltest_shift-0.1.1-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b49ec7944c5ef564ab72f2a0784f0af593697ebee11f9f03babed3e593b276a1
BLAKE2b-256 checksum
How to use checksums
66289e844466d15c54c6b292ef98ce7747c9580e9ad23f591129aa4852fee61b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page