← Latest papers
📊 statistics

Hash-augmented adaptive multilevel splitting Monte Carlo algorithm for accurate estimation of two-sample permutation test p-values

This paper introduces a hash-augmented adaptive multilevel splitting Monte Carlo algorithm, implemented in the Python package `hamstest`, to accurately estimate arbitrarily small p-values for two-sample permutation tests with complex statistics while addressing challenges related to distribution discreteness and ensuring valid confidence intervals.

Original authors: Nikita Golikov, Vladimir Sukhov, Gennady Korotkevich, Alexey Sergushichev

Published 2026-07-15
📖 5 min read🧠 Deep dive

Original authors: Nikita Golikov, Vladimir Sukhov, Gennady Korotkevich, Alexey Sergushichev

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are a detective trying to catch a very rare criminal in a city of millions. You have a list of suspects (your data), and you want to know: "How likely is it that this specific pattern of clues happened just by pure luck?" In the world of statistics, this is called a permutation test. You shuffle the clues around millions of times to see how often a "lucky" pattern appears.

Usually, if the pattern is common, you can just count the lucky shuffles. But what if the pattern is so rare that it only happens once in a trillion tries? That's like looking for a single specific grain of sand on a beach the size of a planet. If you try to find it by randomly picking grains one by one (the old Monte Carlo method), you might spend your whole life picking sand and still never find that one grain. You'd need to pick 101010^{10} grains just to get a decent guess for a tiny probability like 101010^{-10}, which is totally impractical.

The Problem: The "Stuck" Elevator

The authors of this paper realized that standard methods hit a wall when dealing with these tiny probabilities, especially because the "sand grains" (the data combinations) aren't all unique. Sometimes, thousands of different shuffles result in the exact same score. It's like an elevator that only stops on floors 1, 10, and 100, but skips 2 through 99. If you are trying to get to floor 99, the elevator just can't stop there because it doesn't exist. This "discreteness" causes the math to get stuck, making it impossible to estimate how rare an event really is.

The Solution: The "Hash" Tag and the Splitting Ladder

The team, led by Nikita Golikov and colleagues, built a new tool called hamstest. Their secret sauce is a clever trick called hash-augmented adaptive multilevel splitting.

Here is how it works, using a fun analogy:

  1. The Ladder (Multilevel Splitting): Instead of trying to jump straight to the top of the mountain (the rare event), they build a ladder. They start at the bottom and ask, "How many people can reach the first rung?" Then, "How many of those people can reach the second rung?" They keep splitting the group into smaller and smaller groups as they climb higher. This turns one impossible jump into a series of easy, manageable steps.
  2. The "Hash" Tag (The Fix for Stuck Elevators): The big problem was that many people were standing on the same rung (the same score), making it impossible to split the group further. To fix this, the authors gave every single person a unique, invisible hash tag (a random number). Even if two people have the exact same score, their hash tags are different. This allows the algorithm to say, "Okay, we can't split by score, but we can split by hash tag." It turns a flat, stuck floor into a smooth, continuous staircase where the algorithm can always find the next step.

What They Found (and What They Didn't)

The authors tested this new method on two classic statistical tests: the Kolmogorov–Smirnov test and the Mann–Whitney U test.

  • The Results: In their simulations, the new method was incredibly accurate. When they tried to estimate probabilities as tiny as 1024310^{-243} (that's a 1 followed by 243 zeros!), the method's estimates landed right on the true value. They also calculated confidence intervals (a range where the true answer is likely hiding), and in about 95% of their test runs, the true answer was inside that range.
  • The "Full Resampling" Rule: They tried a few different ways to run the simulation. They found that a method called "full resampling" (where they shuffle all the samples at every step) was the most reliable and robust. They suggest using a specific setting called α=1\alpha = 1 as the default because it worked best in their tests.
  • What They Ruled Out: They explicitly showed that the old way of doing things (just using the score without the hash tag) fails when the data has "large jumps" or many ties. They proved that without the hash tag, the algorithm can get stuck and give wrong answers. They also noted that while their method works great for one-sided tests (looking for a pattern in one direction), the two-sided version of the Kolmogorov–Smirnov test is tricky because the "elevator" can get disconnected at the very top, requiring special handling.

How Fast Is It?

The team measured how long the algorithm took on a modern computer (an Apple M3 Pro). They found that the time it takes depends mostly on how rare the event is. If you are looking for something extremely rare (like a p-value of 1010010^{-100}), it takes longer because you have to climb more rungs on the ladder. However, for the Mann–Whitney U test, the time didn't depend much on the size of the data set because the math for that specific test is very efficient to update.

The Bottom Line

The authors haven't "solved" every statistical problem in the universe, but they have built a very powerful, flexible tool that works for any custom test statistic a scientist might invent. They packaged this tool into a free Python library called hamstest.

They suggest that for most people, using the full resampling method with α=1\alpha = 1 is the best bet. They also point out that while their method is fast, the exact time it takes depends on the specific math of the test you are running. If you are a researcher dealing with tiny probabilities and messy data, this tool suggests a way to get accurate answers without waiting for the heat death of the universe.

In short: They turned a broken, stuck elevator into a smooth, high-speed escalator that can take you to the very top of the statistical mountain, even when the path is full of potholes.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →