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.

[1] 0.8724788

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

[1] 0.8337614
  • 4
    $\begingroup$ I find the quoted question confusing. Did you mean to type "in order to find 5 useable items"? $\endgroup$
    – Glen_b
    Nov 25, 2014 at 19:21
  • 2
    $\begingroup$ What do you think dnbinom(x=0:10,size=10,prob=0.6) does -- and how does "5 useable items" come into that calculation? Why sum results from dnbinom rather than simply calling pnbinom? $\endgroup$
    – Glen_b
    Nov 25, 2014 at 19:49
  • $\begingroup$ Fixed the question, yes I meant to type "in order to find 5 useable items"? $\endgroup$ Nov 25, 2014 at 21:13

1 Answer 1


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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.