We provide effective and economically affordable online training courses for R and Python, click here for more details and course registration !

Negative binomial distribution is used to model the particular probability of k-th success occurring at x-th Bernoulli trial, which is equivalent to say that it has experienced x-1 trial and the last trial is a success. A Bernoulli trial is a trial with binary result, success and failure, with a constant success rate in each trial. Function dnbinom(x = f, size = r, prob = p) in R can be used to calculate the probability of such circumstance, where

x here is for how many failure occurs, namely x-k;

size is for how many success occur, namely k;

and prob is for constant probability in each trial.

Next example shows the probability of shooting 10 times in which 3 times hitting the target, and the last shooting is a success too. And the long run of hitting rate is 0.1 for each shooting.

#3 times hitting and last shooting also hitting
r = 3
#probability of long run , hitting rate
p = 0.10
#times of not hitting target
n = 10 - r
# probability of negative binomial
dnbinom(x = n, size = r, prob = p)
#result
0.01721869

For getting more knowledge of R and a preview of our training course, you can watch R tutorial videos on our YouTube channel !