0
$\begingroup$

Trying to tabulate the pmf and cdf of a negative binomial distribution. I have a probability of 0.75, and an success of 2, where the number of trials starts at 2 (x = 2, 3, ...).

I am using r (the language) to calculate and I'm aware that the definitions of the negative binomial are different from my x, but is it a case of starting the vector from 2 to make the distributions match or is there something more complicated? Is the code below going to ensure the distributions passed into the dnbinom and pnbinom functions match up with x?

df <- data.frame(X = 2:20, 
           pmf = dnbinom(x = 2:20, size, prob),
           cdf = pnbinom(q = 2:20, size, prob, lower.tail = TRUE))

The PMF that is outputted from this is:

x   2.000 3.000 4.000 5.000 6.000    7
pmf 0.105 0.035 0.011 0.003 0.001    0
$\endgroup$
4
  • $\begingroup$ There are several 'kinds' of negative binomial distribution. Please show the PMF for the one you are using. $\endgroup$
    – BruceET
    Commented Nov 15, 2020 at 18:18
  • $\begingroup$ @BruceET - Thanks for the reply. I'm fairly new to stats, the PMF I am using is the one outputted from the code above (added to the question). The only information I have is that X has a negative binomial distribution with r = 2 and p = 3/4. How would I find out the PMF? $\endgroup$
    – RustyBrain
    Commented Nov 15, 2020 at 21:41
  • 1
    $\begingroup$ Novice or not, you can look at your text for the explanation of the negative binomial distribution: Are you counting Bernoulli trials up to and including the occurrence of the $r$th Success, or are you counting Failures before the $r$th Success? Or counting something else? $\endgroup$
    – BruceET
    Commented Nov 15, 2020 at 21:45
  • $\begingroup$ @BruceET My apologies, I misunderstood. Bernoulli trials up to and including second success. $\endgroup$
    – RustyBrain
    Commented Nov 15, 2020 at 21:54

1 Answer 1

0
$\begingroup$

I solved this by changing the indexing of the vectors passed into the dnbinom and pnbinom functions to start at 0 rather than 2.

df <- data.frame(x = 2:12, 
           pmf = dnbinom(x = 0:10, size, prob),
           cdf = pnbinom(q = 0:10, size, prob, lower.tail = TRUE))

This leads to the expected output:

x   2.000 3.000 4.000 5.000 6.000 7.000 8.000    9
pmf 0.562 0.281 0.105 0.035 0.011 0.003 0.001    0
cdf 0.563 0.844 0.949 0.984 0.995 0.999 1.000    1
$\endgroup$

Your Answer

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

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