Solved – Negative Binomial Distribution R

negative-binomial-distributionprobabilityrself-study

This question was given in class and I was wondering how to do this in R:

"Sixty percent of a large lot of old spark plugs are still usable, and they can be individually tested to determine this. Let Y be the number plugs to be tested in order to find 5 usable items."

Find the probability P[Y<=10]

I wish to apply the Negative Binomial distribution. I know the answer to be 0.834. This is the R code that I was working on. This returns the wrong answer.

sum(dnbinom(x=0:10,size=10,prob=0.6))
[1] 0.8724788

This set of parameters seem to return the correct answer, but I don't know why it is correct.

sum(dnbinom(x=0:5,size=5,prob=0.6))
[1] 0.8337614

Best Answer

sum(dnbinom(x=0:10,size=10,prob=0.6)) is unlikely to be correct as it does not use the $5$ in the question.

The help page says "This represents the number of failures which occur in a sequence of Bernoulli trials before a target number of successes is reached" and "size target for number of successful trials", so to get $5$ successes in up to to $10$ trials, you can afford $0$ through to $5$ failures. So either of these will work (the second uses the cumulative distribution function):

sum(dnbinom(x=0:(10-5), size=5, prob=0.6))
pnbinom(x=10-5, size=5, prob=0.6)

You could reformulate the question using a binomial distribution: you want at least $5$ successes in $10$ attempts. So any of these work too:

sum(dbinom(x=5:10, size=10, prob=0.6))
1 - pbinom(q=5-1, size=10, prob=0.6)
pbinom(q=5-1, size=10, prob=0.6, lower.tail=FALSE)
Related Question