它描述了由有限个(m+n)物件中抽出k个物件,成功抽出指定种类的物件的次数(不归还)。
超几何分布是统计学上一种离散概率分布。它描述了从有限N个物件(其中包含M个指定种类的物件)中抽出n个物件,成功抽出该指定种类的物件的次数(不放回)。称为超几何分布,是因为其形式与“超几何函数”的级数展式的系数有关。 [1]
超几何分布中的参数是N,n,M,上述超几何分布记作X~H(N,n,M)。
The Hypergeometric Distribution
Description
Density, distribution function, quantile function and random generation for the hypergeometric distribution.
Usage
dhyper(x, m, n, k, log = FALSE) phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE) qhyper(p, m, n, k, lower.tail = TRUE, log.p = FALSE) rhyper(nn, m, n, k)
Arguments
x, q | vector of quantiles representing the number of white balls drawn without replacement from an urn which contains both black and white balls. |
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, hence must be in 0,1,…, m+n. |
p | probability, it must be between 0 and 1. |
nn | number of observations. If |
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]. |
####超几何分布
# 1.超几何分布中抽样函数rhyper
nn <- 100
m=100
n=200
k=30
rhyper(nn, m,n,k)
# 2.超几何分布概率密度函数
x <- seq(1,100)
y <- dhyper(x,m,n,k=50)
plot(x,y)
# 3.超几何分布累积概率
# P[X ≤ x]
phyper(10,m,n,k)
# P[X > x]
phyper(10,m,n,k,lower.tail = FALSE)
# probabilities p are given as log(p).
phyper(10,m,n,k,log.p = TRUE)
# 4.qhyper函数(phyper的反函数)
# 累积概率为0.95时的x值
# x <- seq(1,100)
# plot(x,phyper(x, m,n,k))
qhyper(0.95,m,n,k)
qhyper(0.995,m,n,k)