# NegHyper: Negative hypergeometric distribution In extraDistr: Additional Univariate and Multivariate Distributions

## Description

Probability mass function, distribution function, quantile function and random generation for the negative hypergeometric distribution.

## Usage

 ```1 2 3 4 5 6 7``` ```dnhyper(x, n, m, r, log = FALSE) pnhyper(q, n, m, r, lower.tail = TRUE, log.p = FALSE) qnhyper(p, n, m, r, lower.tail = TRUE, log.p = FALSE) rnhyper(nn, n, m, r) ```

## Arguments

 `x, q` vector of quantiles representing the number of balls drawn without replacement from an urn which contains both black and white balls. `n` the number of black balls in the urn. `m` the number of white balls in the urn. `r` the number of white balls that needs to be drawn for the sampling to be stopped. `log, log.p` logical; if TRUE, probabilities p are given as log(p). `lower.tail` logical; if TRUE (default), probabilities are P[X ≤ x] otherwise, P[X > x]. `p` vector of probabilities. `nn` number of observations. If `length(n) > 1`, the length is taken to be the number required.

## Details

Negative hypergeometric distribution describes number of balls x observed until drawing without replacement to obtain r white balls from the urn containing m white balls and n black balls, and is defined as

f(x) = choose(x-1, r-1)*choose(m+n-x, m-r)/choose(m+n, n)

The algorithm used for calculating probability mass function, cumulative distribution function and quantile function is based on Fortran program NHYPERG created by Berry and Mielke (1996, 1998). Random generation is done by inverse transform sampling.

## References

Berry, K. J., & Mielke, P. W. (1998). The negative hypergeometric probability distribution: Sampling without replacement from a finite population. Perceptual and motor skills, 86(1), 207-210. http://pms.sagepub.com/content/86/1/207.full.pdf

Berry, K. J., & Mielke, P. W. (1996). Exact confidence limits for population proportions based on the negative hypergeometric probability distribution. Perceptual and motor skills, 83(3 suppl), 1216-1218. http://pms.sagepub.com/content/83/3_suppl/1216.full.pdf

Schuster, E. F., & Sype, W. R. (1987). On the negative hypergeometric distribution. International Journal of Mathematical Education in Science and Technology, 18(3), 453-459.

Chae, K. C. (1993). Presenting the negative hypergeometric distribution to the introductory statistics courses. International Journal of Mathematical Education in Science and Technology, 24(4), 523-526.

Jones, S.N. (2013). A Gaming Application of the Negative Hypergeometric Distribution. UNLV Theses, Dissertations, Professional Papers, and Capstones. Paper 1846. http://digitalscholarship.unlv.edu/cgi/viewcontent.cgi?article=2847&context=thesesdissertations

`Hypergeometric`
 ```1 2 3 4 5 6 7 8 9``` ```x <- rnhyper(1e5, 60, 35, 15) xx <- 15:95 plot(prop.table(table(x))) lines(xx, dnhyper(xx, 60, 35, 15), col = "red") hist(pnhyper(x, 60, 35, 15)) xx <- seq(0, 100, by = 0.01) plot(ecdf(x)) lines(xx, pnhyper(xx, 60, 35, 15), col = "red", lwd = 2) ```