R语言 计算随机抽取的负二项式密度 – rnbinom()函数
R语言中的 rnbinom() 函数用于计算负二项分布的随机密度。
语法: rnbinom(N, size, prob)
参数:
N: 样本大小
size: 试验次数
prob: 概率
例1:
# R program to compute random
# Negative Binomial Density
# Setting seed for
# random number generation
set.seed(1000)
# Set sample size
N <- 20
# Calling rnbinom() Function
y <- rnbinom(N, size = 10, prob = 0.5)
y
输出:
[1] 9 12 8 4 10 3 9 19 3 14 11 11 6 15 14 12 6 5 5 4
例2:
# R program to compute random
# Negative Binomial Density
# Setting seed for
# random number generation
set.seed(1000)
# Set sample size
N <- 100
# Calling rnbinom() Function
y <- rnbinom(N, size = 50, prob = 0.5)
# Plot a graph
plot(y)
输出: