Skip to content

hopkins-statistic

hopkins-statistic is a library for computing the Hopkins statistic to assess clustering tendency (also known as clusterability) by testing for departure from complete spatial randomness (CSR) in point patterns.

This implementation defaults to the Cross and Jain (1982) formulation, raising distances to the power of the data dimension. In two dimensions, this matches the original definition by Hopkins and Skellam (1954). Because the resulting statistic follows a beta distribution under the null hypothesis, p-values can be computed analytically, avoiding the need for Monte Carlo simulations.

Installation

pip install hopkins-statistic
uv add hopkins-statistic
uv pip install hopkins-statistic

Usage

import numpy as np
from hopkins_statistic import hopkins

rng = np.random.default_rng(42)
X = rng.uniform(size=(100, 2))

print(hopkins(X, rng=rng))
0.5137976176502288
import numpy as np
from hopkins_statistic import hopkins_test

rng = np.random.default_rng(42)
X = rng.uniform(size=(100, 2))

print(hopkins_test(X, rng=rng))
HopkinsTestResult(statistic=0.5137976176502288, pvalue=0.45148888266508536)