NegHypergeometric: The Negative Hypergeometric Distribution

Description Usage Arguments Details Value References See Also Examples

Description

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

Usage

1
2
3
4
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)

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≤ 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) = choose(x-1, k-1)choose(n-x, m-k) / choose(n, m)

for x=k,k+1,...,n-m+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.

References

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

See Also

runif and .Random.seed about random number generation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## 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)

tolerance documentation built on Feb. 6, 2020, 5:08 p.m.