How can I test if my sample set follows the hypergeometric distribution An hypergeometric sampling algorithm samples from an interval following the hypergeometric distribution. This paper describes one method called HRUA: https://link.springer.com/chapter/10.1007%2F978-1-4757-3552-9_8
I implemented this method but I have no way of testing if it really works. For small numbers, I could compare the frequencies to the hypergeometric distribution, but I need the algorithm working for large values.
Is there an algorithm that I can test if a really large sample follows the hypergeometric distribution?
 A: You can easily estimate the probability mass function (PMF) or the cumulative distribution function (CDF) from the samples you generate using your algorithm. You can then use any "distance" metric for comparing two PMFs or CDFs.
For example, the Kolmogorov-Smirnov test or the Wasserstein distance can be used as these are fairly simple to evaluate. I implemented these in the code below:
from scipy.stats import hypergeom
import matplotlib.pyplot as plt
import numpy as np

M, n, N = 20, 7, 12
rv = hypergeom(M, n, N)
x = np.arange(0, n+1)
true_cdf = rv.cdf(x)

def plot_distance_measures(rv):
    np.random.seed(0)
    nsamples = np.logspace(1, 6, 20)
    distance_ks = np.zeros_like(nsamples)
    distance_wasserstein = np.zeros_like(nsamples)
    for i, nsample in enumerate(nsamples):
        y = rv.rvs(int(nsample))
        est_cdf = np.cumsum(np.bincount(y, minlength=n+1)) / int(nsample)
        distance_ks[i] = np.max(np.abs(true_cdf - est_cdf))
        distance_wasserstein[i] = np.sum(np.abs(true_cdf - est_cdf))
    plt.loglog(nsamples, distance_ks, label="Kolmogorov-Smirnov")
    plt.loglog(nsamples, distance_wasserstein, label="Wasserstein")
    plt.legend()
    plt.xlabel("Number of samples")
    plt.ylabel("Distance measure")
    plt.show()

plot_distance_measures(rv)

This generates the following plot:

By visual inspection, one can argue that the samples are most likely from the true distribution since both metrics seem to converge to zero as more samples are used.
To show what happens if we use another distribution for sampling, consider the following example:
rv_malicious = hypergeom(M, n, N-1)
plot_distance_measures(rv_malicious)


Clearly, both metrics are not converging to zero, so we can conclude that we are sampling from a different distribution.
