Learn R Programming

tolerance (version 3.0.0)

NegHypergeometric: The Negative Hypergeometric Distribution

Description

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

Usage

dnhyper(x, m, n, k, log = FALSE)
pnhyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE)
qnhyper(p, m, n, k, lower.tail = TRUE, log.p = FALSE)
rnhyper(nn, m, n, k)

Value

dnhyper gives the density, pnhyper gives the distribution function, qnhyper gives the quantile function, and rnhyper generates random deviates.

Invalid arguments will return value NaN, with a warning.

Arguments

x,q

Vector of quantiles representing the number of trials until k successes have occurred (e.g., until k white balls have been drawn from an urn without replacement).

m

The number of successes in the population (e.g., the number of white balls in the urn).

n

The population size (e.g., the total number of balls in the urn).

k

The number of successes (e.g., white balls) to achieve with the sample.

p

Vector of probabilities, which must be between 0 and 1.

nn

The number of observations. If length>1, then the length is taken to be the number required.

log,log.p

Logical vectors. If TRUE, then probabilities are given as log(p).

lower.tail

Logical vector. If TRUE, then probabilities are \(P[X\le x]\), else \(P[X>x]\).

Details

A negative hypergeometric distribution (sometimes called the inverse hypergeometric distribution) models the total number of trials until k successes occur. Compare this to the negative binomial distribution, which models the number of failures that occur until a specified number of successes has been reached. The negative hypergeometric distribution has density $$p(x) = \frac{{x-1 \choose k-1}{n-x \choose m-k}}{{n \choose m}}$$ for \(x=k,k+1,...,n-m+k\).

References

Wilks, S. S. (1963), Mathematical Statistics, Wiley.

See Also

runif and .Random.seed about random number generation.

Examples

Run this code
## Randomly generated data from the negative hypergeometric 
## distribution.

set.seed(100)
x <- rnhyper(nn = 1000, m = 15, n = 40, k = 10)
hist(x, main = "Randomly Generated Data", prob = TRUE)

x.1 = sort(x)
y <- dnhyper(x = x.1, m = 15, n = 40, k = 10)
lines(x.1, y, col = 2, lwd = 2)

plot(x.1, pnhyper(q = x.1, m = 15, n = 40, k = 10),             
     type = "l", xlab = "x", ylab = "Cumulative Probabilities")

qnhyper(p = 0.20, m = 15, n = 40, k = 10, lower.tail = FALSE)
qnhyper(p = 0.80, m = 15, n = 40, k = 10)

Run the code above in your browser using DataLab