View source: R/betafunctions.R
rcBinom | R Documentation |
Random Number Generation under Lord's Two-Term Approximation to the Compound Binomial Distribution.
rcBinom(n, N, k, p)
n |
Number of draws. |
N |
Number of trials. |
k |
Lord's k (see documentation for the |
p |
Probability of success for each trial. |
For larger values of k
, the distribution can yield negative probabilities. This function handles such occurrences by adding the absolute value of the minimum probability to all observations if there are any negative probabilities and then normalize the distribution so that the total density is equal to 1.
# To draw a sample of 50 values from a Compound-Binomial distribution with
# number of trials = 100, a 50% probability of success for each trial, and
# Lord's k = 1:
set.seed(1234)
rcBinom(n = 50, N = 100, k = 1, p = .5)
# To draw values where the probabilities vary for each draw:
rcBinom(n = 50, N = 100, k = 1, p = runif(50))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.