Hypergeometric {base} | R Documentation |
The Hypergeometric Distribution
Description
Density, distribution function, quantile function and random generation for the hypergeometric distribution.
Usage
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)
Arguments
x , q |
vector of quantiles representing the number of white balls drawn without replacement from an urn which contains both black and white balls. |
m |
the number of white balls in the urn. |
n |
the number of black balls in the urn. |
k |
the number of balls drawn from the urn. |
p |
probability, it must be between 0 and 1. |
nn |
number of observations. If |
log , log.p |
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are
|
Details
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(x) = \left. {m \choose x}{n \choose k-x} \right/ {m+n \choose k}%
for x = 0, \ldots, k
.
Value
dhyper
gives the density,
phyper
gives the distribution function,
qhyper
gives the quantile function, and
rhyper
generates random deviates.
References
Johnson, N. L., Kotz, S., and Kemp, A. W. (1992) Univariate Discrete Distributions, Second Edition. New York: Wiley.
Examples
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)), dig=3)