计算 R 编程中的负二项式密度 – dnbinom()函数
R语言中的dnbinom()
函数用于计算负二项式密度的值。它还创建了负二项式密度图。
Syntax: dnbinom(vec, size, prob)
Parameters:
vec: x-values for binomial density
size: Number of trials
prob: Probability
示例 1:
# R program to compute
# Negative Binomial Density
# Vector of x-values
x <- seq(0, 10, by = 1)
# Calling dnbinom() Function
y <- dnbinom(x, size = 10, prob = 0.5)
y
输出:
[1] 0.0009765625 0.0048828125 0.0134277344 0.0268554688 0.0436401367
[6] 0.0610961914 0.0763702393 0.0872802734 0.0927352905 0.0927352905
[11] 0.0880985260
示例 2:
# R program to compute
# Negative Binomial Density
# Vector of x-values
x <- seq(0, 100, by = 1)
# Calling dnbinom() Function
y <- dnbinom(x, size = 10, prob = 0.5)
# Plot a graph
plot(y)
输出: