EVOLUTION-MANAGER
Edit File: Hypergeometric.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: The Hypergeometric Distribution</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for Hypergeometric {stats}"><tr><td>Hypergeometric {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>The Hypergeometric Distribution</h2> <h3>Description</h3> <p>Density, distribution function, quantile function and random generation for the hypergeometric distribution. </p> <h3>Usage</h3> <pre> dhyper(x, m, n, k, log = FALSE) phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE) qhyper(p, m, n, k, lower.tail = TRUE, log.p = FALSE) rhyper(nn, m, n, k) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, q</code></td> <td> <p>vector of quantiles representing the number of white balls drawn without replacement from an urn which contains both black and white balls.</p> </td></tr> <tr valign="top"><td><code>m</code></td> <td> <p>the number of white balls in the urn.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>the number of black balls in the urn.</p> </td></tr> <tr valign="top"><td><code>k</code></td> <td> <p>the number of balls drawn from the urn.</p> </td></tr> <tr valign="top"><td><code>p</code></td> <td> <p>probability, it must be between 0 and 1.</p> </td></tr> <tr valign="top"><td><code>nn</code></td> <td> <p>number of observations. If <code>length(nn) > 1</code>, the length is taken to be the number required.</p> </td></tr> <tr valign="top"><td><code>log, log.p</code></td> <td> <p>logical; if TRUE, probabilities p are given as log(p).</p> </td></tr> <tr valign="top"><td><code>lower.tail</code></td> <td> <p>logical; if TRUE (default), probabilities are <i>P[X ≤ x]</i>, otherwise, <i>P[X > x]</i>.</p> </td></tr> </table> <h3>Details</h3> <p>The hypergeometric distribution is used for sampling <em>without</em> replacement. The density of this distribution with parameters <code>m</code>, <code>n</code> and <code>k</code> (named <i>Np</i>, <i>N-Np</i>, and <i>n</i>, respectively in the reference below) is given by </p> <p style="text-align: center;"><i>p(x) = choose(m, x) choose(n, k-x) / choose(m+n, k)</i></p> <p>for <i>x = 0, …, k</i>. </p> <p>Note that <i>p(x)</i> is non-zero only for <i>max(0, k-n) <= x <= min(k, m)</i>. </p> <p>With <i>p := m/(m+n)</i> (hence <i>Np = N \times p</i> in the reference's notation), the first two moments are mean </p> <p style="text-align: center;"><i>E[X] = μ = k p</i></p> <p> and variance </p> <p style="text-align: center;"><i> Var(X) = k p (1 - p) * (m+n-k)/(m+n-1),</i></p> <p>which shows the closeness to the Binomial<i>(k,p)</i> (where the hypergeometric has smaller variance unless <i>k = 1</i>). </p> <p>The quantile is defined as the smallest value <i>x</i> such that <i>F(x) ≥ p</i>, where <i>F</i> is the distribution function. </p> <p>If one of <i>m, n, k</i>, exceeds <code><a href="../../base/html/zMachine.html">.Machine</a>$integer.max</code>, currently the equivalent of <code>qhyper(runif(nn), m,n,k)</code> is used, when a binomial approximation may be considerably more efficient. </p> <h3>Value</h3> <p><code>dhyper</code> gives the density, <code>phyper</code> gives the distribution function, <code>qhyper</code> gives the quantile function, and <code>rhyper</code> generates random deviates. </p> <p>Invalid arguments will result in return value <code>NaN</code>, with a warning. </p> <p>The length of the result is determined by <code>n</code> for <code>rhyper</code>, and is the maximum of the lengths of the numerical arguments for the other functions. </p> <p>The numerical arguments other than <code>n</code> are recycled to the length of the result. Only the first elements of the logical arguments are used. </p> <h3>Source</h3> <p><code>dhyper</code> computes via binomial probabilities, using code contributed by Catherine Loader (see <code><a href="Binomial.html">dbinom</a></code>). </p> <p><code>phyper</code> is based on calculating <code>dhyper</code> and <code>phyper(...)/dhyper(...)</code> (as a summation), based on ideas of Ian Smith and Morten Welinder. </p> <p><code>qhyper</code> is based on inversion. </p> <p><code>rhyper</code> is based on a corrected version of </p> <p>Kachitvichyanukul, V. and Schmeiser, B. (1985). Computer generation of hypergeometric random variates. <em>Journal of Statistical Computation and Simulation</em>, <b>22</b>, 127–145. </p> <h3>References</h3> <p>Johnson, N. L., Kotz, S., and Kemp, A. W. (1992) <em>Univariate Discrete Distributions</em>, Second Edition. New York: Wiley. </p> <h3>See Also</h3> <p><a href="Distributions.html">Distributions</a> for other standard distributions. </p> <h3>Examples</h3> <pre> m <- 10; n <- 7; k <- 8 x <- 0:(k+1) rbind(phyper(x, m, n, k), dhyper(x, m, n, k)) all(phyper(x, m, n, k) == cumsum(dhyper(x, m, n, k))) # FALSE ## but error is very small: signif(phyper(x, m, n, k) - cumsum(dhyper(x, m, n, k)), digits = 3) </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>