HypergeometricDistribution
Represents the hypergeometric distribution, which models the number of successes when drawing without replacement from a finite population.
Consider an urn containing population balls, of which successes are "success" balls (e.g., red) and the rest are "failure" balls (e.g., blue). You draw draws balls without putting any back. The hypergeometric distribution gives the probability of observing exactly k success balls among the drawn items.
Unlike the binomial distribution, the hypergeometric distribution accounts for the changing composition of the population as items are drawn. This makes it the correct model when sampling without replacement, such as quality control inspections from a finite lot, card games (e.g., the probability of being dealt a certain number of aces), or Fisher's exact test in statistics.
The support is {max(0, draws + successes - population), ..., min(draws, successes)}, which reflects the physical constraint that you cannot draw more success balls than exist or more than the total number of draws.
The CDF and survival function are computed using a numerically stable log-sum-exp technique over the PMF values. Sampling uses direct simulation of the drawing process.
Example:
// Urn with 50 balls: 15 red, 35 blue. Draw 10 without replacement.
val dist = HypergeometricDistribution(population = 50, successes = 15, draws = 10)
dist.pmf(3) // 0.2786 (probability of exactly 3 red balls)
dist.cdf(3) // 0.6749 (probability of 3 or fewer red balls)
dist.mean // 3.0 (expected number of red balls)
dist.quantileInt(0.5) // 3 (median)
dist.sample(Random(42)) // a single random drawProperties
The excess kurtosis of this distribution. Returns Double.NaN when population is less than 4 or the distribution is degenerate (single point support).
the total number of items in the population. Must be non-negative.
The skewness of this distribution. Returns Double.NaN when population is less than 3 or the distribution is degenerate (single point support).