Hypergeometric Distribution

DESCRIPTION:
Density, cumulative probability, quantiles and random generation for the Hypergeometric discrete distribution.

USAGE:
dhyper(q, m, n, k)
phyper(q, m, n, k)
qhyper(p, m, n, k)
rhyper(nn, m, n, k)

REQUIRED ARGUMENTS:
q:
vector of values of a random variable representing the number of red balls out of a sample of size k drawn from an urn containing m red balls and n black ones.
p:
vector of probabilities. Missing values (NAs) are allowed. Its values must be between 0 and 1.
nn:
sample size, nn random hypergeometrically distributed numbers are returned unless length(nn) is larger than 1, in which case length(nn) random numbers are returned.
m:
number of red balls in the urn. This could be a vector with non-negative integer elements.
n:
number of black balls in the urn. This could also be a vector with non-negative integer elements.
k:
number of balls drawn from an urn with m red and n black balls. This can be a vector like m and n.

VALUE:
dhyper returns discrete probability values. Other functions return vectors of cumulative probabilities (phyper), quantiles (qhyper), or random samples (rhyper) for the Hypergeometric distribution.

SIDE EFFECTS:
The function rhyper causes creation of the dataset .Random.seed if it does not already exist, otherwise its value is updated.

DETAILS:
Missing values (NAs) and +-Infs are allowed as components of q, p or nn, but not in the vectors of parameters. If q, m, n, or k are vectors of different lengths, m, n, and k will be made to conform the length of q by replicating their values cyclically. The values of q, m, n, and k are rounded to the nearest integer value before any calculations are made.

BACKGROUND:
The Hypergeometric distribution can be described by an Urn Model with m red and n black balls. Any sequence of k drawings resulting in k-q black and q red balls has the same probability. It is similar to the Binomial distribution but sampled from a finite population without replacement.

REFERENCES:
Hoel, P., Port, S. and Stone, C. (1971). Introduction to Probability Theory. Houghton-Mifflin, Boston, MA.

Johnson, N. L. and Kotz, S. (1970). Discrete Univariate Distributions, vol. 2. Houghton-Mifflin, Boston, MA.


SEE ALSO:
set.seed , Binomial .

EXAMPLES:
cumsum(dhyper(0:5,4,6,7))   # cumulative distribution function
phyper(0:5,4,6,7            # samething

rhyper(10,4,6,7) # 10 random samples dhyper(rep(3,3), m=c(5,8,12), n=4, k=4)