{
  "id": "hypergeometric-distribution",
  "title": "Hypergeometric Distribution",
  "lang": "en",
  "source_lang": "en",
  "summary": "The hypergeometric distribution describes the number of successes in a fixed-size random sample drawn without replacement from a finite population.",
  "category": "mathematics",
  "subcategory": "probability-statistics",
  "type": "concept",
  "aliases": [
    "Hypergeometric probability distribution"
  ],
  "generated_at": "2026-11-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/hypergeometric-distribution/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/hypergeometric-distribution/",
      "json": "https://aiwiki.page/zh/hypergeometric-distribution.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The hypergeometric distribution is a discrete probability distribution for the number of items of a specified type in a fixed-size sample drawn without replacement from a finite population. If a population contains \\(N\\) items, of which \\(K\\) are classified as successes, and every sample of \\(n\\) distinct items is equally likely, then the number of sampled successes has a hypergeometric distribution. Unlike the binomial distribution, it accounts for the dependence introduced when sampled items are not returned to the population."
    },
    {
      "heading": "Definition and probability mass function",
      "text": "Let:\n\n- \\(N\\) be the total population size, with \\(N\\geq 1\\);\n- \\(K\\) be the number of successes in the population, with \\(0\\leq K\\leq N\\);\n- \\(n\\) be the sample size, with \\(0\\leq n\\leq N\\);\n- \\(X\\) be the number of successes in the sample.\n\nAll three parameters are integers. One common notation is\n\n\\[X\\sim\\operatorname{Hypergeometric}(N,K,n),\\]\n\nalthough the order and names of parameters vary among textbooks and software packages.\n\nThe probability mass function is\n\n\\[\\Pr(X=x) = \\frac{\\binom{K}{x}\\binom{N-K}{n-x}} {\\binom{N}{n}},\\]\n\nfor integer values satisfying\n\n\\[\\max(0,n+K-N)\\leq x\\leq \\min(n,K).\\]\n\nIt is zero otherwise.\n\nThe binomial coefficient \\(\\binom{a}{b}\\) counts the ways to choose \\(b\\) items from \\(a\\) distinct items. There are \\(\\binom{N}{n}\\) possible unordered samples. A sample with exactly \\(x\\) successes consists of a choice of \\(x\\) items from the \\(K\\) successes and \\(n-x\\) items from the \\(N-K\\) failures, giving the numerator.\n\nThe lower support bound matters when the sample is too large to consist entirely of failures. For example, if only three failures exist and five items are sampled, at least two successes must be observed.\n\nNormalization follows from Vandermonde’s identity:\n\n\\[\\sum_x \\binom{K}{x}\\binom{N-K}{n-x} = \\binom{N}{n},\\]\n\nwhere the sum extends over the admissible values of \\(x\\).\n\nSampling assumptions\n\nThe defining condition is that all subsets of size \\(n\\) are equally likely. This is the usual model of simple random sampling without replacement.\n\nThe population labels may be fixed rather than random: randomness in the sample selection alone produces the distribution. “Success” is simply a category label and need not denote a desirable outcome.\n\nSampling without replacement is not, by itself, sufficient to justify a hypergeometric model. If some items are more likely to be selected than others, or items are selected together in clusters, the ordinary hypergeometric distribution generally does not apply."
    },
    {
      "heading": "Example",
      "text": "Suppose a shipment contains 20 components, including 7 defective components. Five components are selected uniformly without replacement. If \\(X\\) counts the defective components selected, then\n\n\\[X\\sim\\operatorname{Hypergeometric}(20,7,5).\\]\n\nThe probability of selecting exactly two defective components is\n\n\\[\\Pr(X=2) = \\frac{\\binom{7}{2}\\binom{13}{3}} {\\binom{20}{5}} = \\frac{6006}{15504} \\approx 0.3874.\\]\n\nThe probability of finding at least one defective component is most easily calculated by taking the complement:\n\n\\[\\Pr(X\\geq 1) = 1-\\Pr(X=0) = 1-\\frac{\\binom{13}{5}}{\\binom{20}{5}} \\approx 0.9170.\\]\n\nA binomial model with success probability \\(7/20\\) would not be exact here: removing a defective component changes the composition of the remaining shipment."
    },
    {
      "heading": "Mean, variance, and dependence",
      "text": "Write \\(p=K/N\\). The expected value is\n\n\\[\\operatorname{E}[X]=np=n\\frac{K}{N}.\\]\n\nFor \\(N>1\\), the variance is\n\n\\[\\operatorname{Var}(X) = np(1-p)\\frac{N-n}{N-1}.\\]\n\nThe factor\n\n\\[\\frac{N-n}{N-1}\\]\n\nis the finite-population correction to the binomial variance. It is close to 1 when the sample is small relative to the population, and becomes 0 when the entire population is sampled.\n\nIf \\(n=N\\), the sample contains exactly \\(K\\) successes, so \\(X=K\\) with probability 1. Other degenerate cases include \\(n=0\\), \\(K=0\\), and \\(K=N\\). When \\(N=1\\), the distribution is also degenerate for every permitted sample size; the variance is zero rather than the undefined value suggested by directly substituting into the formula.\n\nWhy the variance is smaller than the binomial variance\n\nImagine drawing the sample sequentially. Let \\(I_j\\) equal 1 if the \\(j\\)-th draw is a success and 0 otherwise. Then\n\n\\[X=\\sum_{j=1}^{n} I_j.\\]\n\nEach indicator has a Bernoulli distribution with success probability \\(p\\), but the indicators do not have statistical independence. For distinct draws \\(i\\) and \\(j\\),\n\n\\[\\operatorname{E}[I_iI_j] = \\frac{K(K-1)}{N(N-1)},\\]\n\nand their covariance is\n\n\\[\\operatorname{Cov}(I_i,I_j) = -\\frac{p(1-p)}{N-1}.\\]\n\nA success on one draw reduces the proportion of successes remaining. Summing the individual variances and pairwise covariances gives the hypergeometric variance.\n\nFor \\(n>0\\), the sample proportion \\(\\widehat p=X/n\\) is an unbiased estimator of the population proportion \\(p\\), with\n\n\\[\\operatorname{Var}(\\widehat p) = \\frac{p(1-p)}{n}\\frac{N-n}{N-1}.\\]\n\nThis expression describes uncertainty due to the sampling design, with the finite population held fixed."
    },
    {
      "heading": "Distribution function and symmetries",
      "text": "Let\n\n\\[a=\\max(0,n+K-N), \\qquad b=\\min(n,K).\\]\n\nThe cumulative distribution function is\n\n\\[F(t) = \\sum_{x=a}^{\\min(\\lfloor t\\rfloor,b)} \\frac{\\binom{K}{x}\\binom{N-K}{n-x}} {\\binom{N}{n}},\\]\n\nwith \\(F(t)=0\\) for \\(t<a\\) and \\(F(t)=1\\) for \\(t\\geq b\\).\n\nSeveral transformations are useful:\n\n- Exchange success and failure labels. If \\(X\\sim\\operatorname{Hypergeometric}(N,K,n)\\), then\n\n\\[n-X\\sim\\operatorname{Hypergeometric}(N,N-K,n).\\]\n- Count successes outside the sample.\n\n\\[K-X\\sim\\operatorname{Hypergeometric}(N,K,N-n).\\]\n- Interchange \\(K\\) and \\(n\\). The distributions\n\n\\[\\operatorname{Hypergeometric}(N,K,n) \\quad\\text{and}\\quad \\operatorname{Hypergeometric}(N,n,K)\\]\n\nare identical.\n\nThe last identity follows from viewing \\(X\\) as the size of the intersection between a fixed subset and a uniformly selected subset."
    },
    {
      "heading": "Relationships and approximations",
      "text": "Conditional binomial representation\n\nLet\n\n\\[Y\\sim\\operatorname{Binomial}(n,q), \\qquad Z\\sim\\operatorname{Binomial}(N-n,q)\\]\n\nbe independent, with \\(0<q<1\\). The conditional distribution of \\(Y\\) given \\(Y+Z=K\\) is\n\n\\[Y\\mid(Y+Z=K) \\sim\\operatorname{Hypergeometric}(N,K,n).\\]\n\nConditioning fixes the total number of successes among all \\(N\\) positions. The common success probability \\(q\\) cancels from the conditional probability.\n\nBinomial approximation\n\nWhen the sample is a small fraction of the population, removing an item changes the success proportion only slightly. Consequently,\n\n\\[X\\approx\\operatorname{Binomial}\\left(n,\\frac KN\\right).\\]\n\nMore formally, for fixed \\(n\\), if \\(N\\) tends to infinity and \\(K/N\\to p\\), the hypergeometric distribution converges to \\(\\operatorname{Binomial}(n,p)\\).\n\nThere is no universal sampling-fraction threshold guaranteeing adequate accuracy for every purpose. Tail probabilities can require greater accuracy than probabilities near the center. The variance ratio\n\n\\[\\frac{\\operatorname{Var}(X)}{np(1-p)} = \\frac{N-n}{N-1}\\]\n\nshows how strongly the binomial approximation neglects finite-population effects.\n\nNormal approximation\n\nWhen the distribution is sufficiently spread out and not strongly affected by its support boundaries, a normal distribution can approximate it:\n\n\\[X\\approx\\mathcal N(\\mu,\\sigma^2),\\]\n\nwhere\n\n\\[\\mu=np, \\qquad \\sigma^2=np(1-p)\\frac{N-n}{N-1}.\\]\n\nA continuity correction gives, for integer \\(x\\),\n\n\\[\\Pr(X\\leq x) \\approx \\Phi\\left(\\frac{x+\\tfrac12-\\mu}{\\sigma}\\right),\\]\n\nwhere \\(\\Phi\\) is the standard normal distribution function.\n\nThe expected counts of successes and failures in both the sampled and unsampled portions help indicate whether this approximation is reasonable. Large sample size alone does not suffice if the distribution remains concentrated near a boundary.\n\nPoisson approximation\n\nIn a rare-success regime, a Poisson distribution may be appropriate. One sufficient asymptotic setting is\n\n\\[n\\to\\infty,\\qquad \\frac KN\\to0,\\qquad n\\frac KN\\to\\lambda,\\qquad \\frac nN\\to0.\\]\n\nThen the limiting distribution is \\(\\operatorname{Poisson}(\\lambda)\\). The negligible sampling fraction is important: rarity alone does not remove the effects of sampling without replacement."
    },
    {
      "heading": "Applications in statistical inference",
      "text": "Fisher’s exact test\n\nThe hypergeometric distribution is the basis of Fisher’s exact test for a \\(2\\times2\\) contingency table. Consider\n\n | Success | Failure | Total\nGroup 1 | \\(x\\) | \\(n-x\\) | \\(n\\)\nGroup 2 | \\(K-x\\) | \\(N-K-n+x\\) | \\(N-n\\)\nTotal | \\(K\\) | \\(N-K\\) | \\(N\\)\n\nUnder the null hypothesis of no association, conditioning on the margins gives a hypergeometric distribution for the upper-left cell.\n\nA one-sided p-value is obtained by summing probabilities in the relevant tail. Two-sided exact p-values require a definition of which tables count as at least as extreme as the observed table. Different conventions can give different results because the distribution is discrete; simply doubling a one-sided probability is not universally equivalent to a probability-ordering calculation.\n\nAcceptance sampling and finite-population inference\n\nIn acceptance sampling, a lot of \\(N\\) items containing \\(K\\) defective items is accepted if a sample contains at most \\(c\\) defectives. Its acceptance probability is\n\n\\[\\Pr(X\\leq c) = \\sum_{x=a}^{\\min(c,b)} \\frac{\\binom{K}{x}\\binom{N-K}{n-x}} {\\binom{N}{n}}.\\]\n\nWhen \\(K\\) is unknown, the same probability model supplies a likelihood function for \\(K\\), with \\(N\\) and \\(n\\) fixed. Inverting exact tests can produce a confidence interval for the population count or proportion. Because the parameter and observations are discrete, nonrandomized exact procedures may have coverage exceeding their nominal level.\n\nOverlap and enrichment analysis\n\nSuppose a universe contains \\(N\\) elements, a designated category contains \\(K\\), and a selected set contains \\(n\\). Under a null model in which the selected set is uniform among all size-\\(n\\) subsets, its overlap with the category is hypergeometric.\n\nUpper-tail probabilities are used to assess overrepresentation, including in analyses of gene-expression results. Interpretation depends on the chosen universe and on whether the selection mechanism supports the uniform-subset null model. Testing many categories also introduces a multiple testing problem."
    },
    {
      "heading": "Extensions and related distributions",
      "text": "Multivariate hypergeometric distribution\n\nIf the population is partitioned into \\(m\\) categories with sizes \\(K_1,\\ldots,K_m\\), where \\(\\sum_iK_i=N\\), the sampled category counts follow a multivariate hypergeometric distribution:\n\n\\[\\Pr(X_1=x_1,\\ldots,X_m=x_m) = \\frac{\\prod_{i=1}^{m}\\binom{K_i}{x_i}} {\\binom{N}{n}},\\]\n\nsubject to \\(\\sum_i x_i=n\\) and \\(0\\leq x_i\\leq K_i\\). The ordinary hypergeometric distribution is the two-category case.\n\nNegative hypergeometric distribution\n\nThe negative hypergeometric distribution arises when sampling without replacement continues until a specified number of successes or failures has been observed. Its random variable usually counts draws, or opposite-category outcomes, before stopping. This differs from the fixed sample size of the ordinary hypergeometric model.\n\nNoncentral hypergeometric distributions\n\nNoncentral hypergeometric distributions model certain forms of unequal selection between categories. Fisher’s and Wallenius’ versions describe different mechanisms: the former arises through conditioning independent binomial counts with unequal odds, while the latter arises from sequential weighted sampling without replacement. They coincide with the ordinary hypergeometric distribution when the category weights are equal, but are not generally interchangeable otherwise."
    },
    {
      "heading": "Numerical computation",
      "text": "Direct evaluation using factorials can overflow even when the final probability is moderate. Implementations commonly use logarithms of binomial coefficients, specialized probability algorithms, or a recurrence relation between neighboring probabilities:\n\n\\[\\frac{\\Pr(X=x+1)}{\\Pr(X=x)} = \\frac{(K-x)(n-x)} {(x+1)(N-K-n+x+1)},\\]\n\nwhenever both values lie in the support.\n\nThis ratio also explains the distribution’s name: its successive probability terms have a rational ratio in the index, connecting them with hypergeometric series.\n\nFor numerical stability, algorithms can start near the mode and generate probabilities outward before normalization. Very small upper-tail probabilities are preferably evaluated directly rather than by subtracting a cumulative probability close to 1, which can lose significant digits."
    }
  ],
  "links": [
    "probability-distribution",
    "binomial-distribution",
    "probability-mass-function",
    "binomial-coefficient",
    "random-sampling",
    "expected-value",
    "variance",
    "bernoulli-distribution",
    "statistical-independence",
    "covariance",
    "estimator",
    "cumulative-distribution-function",
    "conditional-probability",
    "normal-distribution",
    "poisson-distribution",
    "null-hypothesis",
    "p-value",
    "likelihood-function",
    "confidence-interval",
    "gene-expression",
    "multiple-testing",
    "factorial",
    "recurrence-relation",
    "numerical-stability"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}