Learn R Programming

HelpersMG (version 5.1)

rSnbinom: Random generation for the sum of random variable with negative binomial distributions.

Description

Random numbers for the sum of random variable with negative binomial distributions.

Usage

rSnbinom(n = 1, size = NULL, prob = NULL, mu = NULL)

Arguments

n

number of observations.

size

target for number of successful trials, or dispersion parameter (the shape parameter of the gamma mixing distribution). Must be strictly positive, need not be integer.

prob

probability of success in each trial. 0 < prob <= 1.

mu

alternative parametrization via mean.

Value

rSnbinom returns random number

Details

rSnbinom returns random numbers for the sum of random variable with negative binomial distributions

See Also

Other Distribution of sum of random variable with negative binomial distributions: dSnbinom(), pSnbinom(), qSnbinom()

Examples

Run this code
# NOT RUN {
alpha <- c(2.1, 2.05, 2)
mu <- c(10, 30, 20)
rep <- 100000
distEmpirique <- rSnbinom(n=rep, size=alpha, mu=mu)
tabledistEmpirique <- rep(0, 301)
names(tabledistEmpirique) <- as.character(0:300)
tabledistEmpirique[names(table(distEmpirique))] <- table(distEmpirique)/rep

plot(0:300, dSnbinom(0:300, size=alpha, mu=mu), type="h", bty="n", 
   xlab="x", ylab="Density", ylim=c(0,0.02))
plot_add(0:300, tabledistEmpirique, type="l", col="red")
legend(x=200, y=0.02, legend=c("Empirical", "Theoretical"), 
   text.col=c("red", "black"), bty="n")
# }

Run the code above in your browser using DataLab