{"id":1109,"date":"2013-05-02T09:22:03","date_gmt":"2013-05-02T01:22:03","guid":{"rendered":"http:\/\/www.hzaumycology.com\/chenlianfu_blog\/?p=1109"},"modified":"2013-05-02T09:34:18","modified_gmt":"2013-05-02T01:34:18","slug":"the-hypergeometric-distribution","status":"publish","type":"post","link":"http:\/\/www.chenlianfu.com\/?p=1109","title":{"rendered":"The Hypergeometric Distribution"},"content":{"rendered":"<p>Reference: <a href=\"http:\/\/stat.ethz.ch\/R-manual\/R-patched\/library\/stats\/html\/Hypergeometric.html\" target=\"_blank\">The Hypergeometric Distribution<\/a><\/p>\n<h2>Description<\/h2>\n<p>Density, distribution function, quantile function and random generation for the hypergeometric distribution.<\/p>\n<h2>Usage<\/h2>\n<p>dhyper(x, m, n, k, log = FALSE)<br \/>\nphyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE)<br \/>\nqhyper(p, m, n, k, lower.tail = TRUE, log.p = FALSE)<br \/>\nrhyper(nn, m, n, k)<\/p>\n<pre>\r\ndhper    \u8ba1\u7b97\u67d0\u4e00\u4e2a\u70b9\u7684p\u503c\r\nphyper   \u8ba1\u7b97\u4e00\u4e2a\u5206\u5e03\u7684p\u503c\uff0c\u9ed8\u8ba4\u4e0b\u8ba1\u7b97P(X<=x)\r\nqhyper   \u8ba1\u7b97\u67d0\u4e00\u4e2ap\u503c\u5bf9\u5e94\u7684\u5206\u4f4d\u6570\r\nrhyper   \u6309\u8d85\u51e0\u4f55\u5206\u5e03\u7ed9\u51fann\u7684\u53ef\u80fd\u7684\u6a21\u62df\u7ed3\u679c\u503c\r\n<\/pre>\n<h2>Arguments<\/h2>\n<p><span style=\"color: #ff00ff;\">x, q<\/span> vector of quantiles representing the number of white balls drawn without replacement from an urn which contains both black and white balls.<\/p>\n<p><span style=\"color: #ff00ff;\">m<\/span> the number of white balls in the urn.<\/p>\n<p><span style=\"color: #ff00ff;\">n<\/span> the number of black balls in the urn.<\/p>\n<p><span style=\"color: #ff00ff;\">k<\/span> the number of balls drawn from the urn.<\/p>\n<p><span style=\"color: #ff00ff;\">p<\/span> probability, it must be between 0 and 1.<\/p>\n<p><span style=\"color: #ff00ff;\">nn<\/span> number of observations. If length(nn) &gt; 1, the length is taken to be the number required.<\/p>\n<p><span style=\"color: #ff00ff;\">log, log.p<\/span> logical; if TRUE, probabilities p are given as log(p).<\/p>\n<p><span style=\"color: #ff00ff;\">lower.tail<\/span> logical; if TRUE (default), probabilities are P[X \u2264 x], otherwise, P[X &gt; x].<\/p>\n<h2>Details<\/h2>\n<p>The hypergeometric distribution is used for sampling without replacement. The density of this distribution with parameters m, n and k (named Np, N-Np, and n, respectively in the reference below) is given by<\/p>\n<pre>p(x) = choose(m, x) choose(n, k-x) \/ choose(m+n, k)\r\nfor x = 0, \u2026, k.<\/pre>\n<p>The quantile is defined as the smallest value x such that F(x) \u2265 p, where F is the distribution function.<\/p>\n<h2>Value<\/h2>\n<p>dhyper gives the density, phyper gives the distribution function, qhyper gives the quantile function, and rhyper generates random deviates.<\/p>\n<p>Invalid arguments will result in return value NaN, with a warning.<\/p>\n<p>The length of the result is determined by n for rhyper, and is the maximum of the lengths of the numerical parameters for the other functions.<\/p>\n<p>The numerical parameters other than n are recycled to the length of the result. Only the first elements of the logical parameters are used.<\/p>\n<h2>Source<\/h2>\n<p>dhyper computes via binomial probabilities, using code contributed by Catherine Loader (see <a href=\"http:\/\/stat.ethz.ch\/R-manual\/R-patched\/library\/stats\/html\/Binomial.html\" target=\"_blank\">dbinom<\/a>).<\/p>\n<p>phyper is based on calculating dhyper and phyper(...)\/dhyper(...) (as a summation), based on ideas of Ian Smith and Morten Welinder.<\/p>\n<p>qhyper is based on inversion.<\/p>\n<p>rhyper is based on a corrected version of<\/p>\n<p>Kachitvichyanukul, V. and Schmeiser, B. (1985). Computer generation of hypergeometric random variates. Journal of Statistical Computation and Simulation, 22, 127\u2013145.<\/p>\n<h2>References<\/h2>\n<p>Johnson, N. L., Kotz, S., and Kemp, A. W. (1992) Univariate Discrete Distributions, Second Edition. New York: Wiley.<br \/>\nSee Also<br \/>\n<a href=\"http:\/\/stat.ethz.ch\/R-manual\/R-patched\/library\/stats\/html\/Distributions.html\" target=\"_blank\">Distributions<\/a> for other standard distributions.<\/p>\n<h2>Examples<\/h2>\n<p>m x rbind(phyper(x, m, n, k), dhyper(x, m, n, k))<br \/>\nall(phyper(x, m, n, k) == cumsum(dhyper(x, m, n, k))) # FALSE<br \/>\n## but error is very small:<br \/>\nsignif(phyper(x, m, n, k) - cumsum(dhyper(x, m, n, k)), digits = 3)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reference: The Hypergeometric Distributi &hellip; <a href=\"http:\/\/www.chenlianfu.com\/?p=1109\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts\/1109"}],"collection":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1109"}],"version-history":[{"count":11,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts\/1109\/revisions"}],"predecessor-version":[{"id":1120,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts\/1109\/revisions\/1120"}],"wp:attachment":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1109"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}