Learn R Programming

Runuran (version 0.40)

urhyper: UNU.RAN Hypergeometric random variate generator

Description

UNU.RAN random variate generator for the Hypergeometric distribution. It also allows sampling from the truncated distribution.

[Special Generator] -- Sampling Function: Hypergeometric.

Usage

urhyper(nn, m, n, k, lb=max(0,k-n), ub=min(k,m))

Arguments

nn

number of observations.

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.

lb

lower bound of (truncated) distribution.

ub

upper bound of (truncated) distribution.

Author

Josef Leydold and Wolfgang H\"ormann unuran@statmath.wu.ac.at.

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\).

The generation algorithm uses guide table based inversion. The parameters lb and ub can be used to generate variates from the Hypergeometric distribution truncated to the interval (lb,ub).

References

W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg

See Also

runif and .Random.seed about random number generation, unuran for the UNU.RAN class, and rhyper for the R built-in generator.

Examples

Run this code
## Create a sample of size 1000
x <- urhyper(nn=20,m=15,n=5,k=7)

Run the code above in your browser using DataLab