Negative binomial distribution: trials until \(r\) successes
The negative binomial distribution extends the geometric waiting-time idea.
Instead of waiting for the first success, you wait until you have observed a fixed number of successes, say \(r\).
Imagine repeating independent trials (like Bernoulli trials) where each trial is a success with probability \(p\) and a failure with probability \(q=1-p\).
Define the random variable \(X\) as the trial number on which the \(r\)-th success occurs.
Then \(X\) takes values \(r,r+1,r+2,\dots\), because you need at least \(r\) trials to collect \(r\) successes.
Why the PMF has a binomial coefficient
To have \(X=k\), the \(k\)-th trial must be a success (it is the \(r\)-th success),
and among the first \(k-1\) trials there must be exactly \(r-1\) successes (so you have only \(r-1\) successes before the last trial).
The number of ways to place \(r-1\) successes among \(k-1\) positions is \(\binom{k-1}{r-1}\).
Each such arrangement has probability \(p^{r-1}q^{(k-1)-(r-1)}=p^{r-1}q^{k-r}\),
and the final trial contributes one more factor of \(p\).
Putting this together gives the negative binomial PMF:
\[
P(X=k)=\binom{k-1}{r-1}p^{r}(1-p)^{k-r},\qquad k\ge r.
\]
Mean and variance (what to expect)
Because each success arrives with probability \(p\), collecting \(r\) successes typically takes about \(r/p\) trials on average:
\[
\mathbb{E}[X]=\frac{r}{p}.
\]
The variability grows when successes are rare. The variance for this “trials until \(r\) successes” version is
\[
\mathrm{Var}(X)=\frac{r(1-p)}{p^{2}}.
\]
When \(p\) is small, both the mean and the variance become large, reflecting a longer and more uncertain waiting time.
Relationship to the geometric distribution
When \(r=1\), the formula reduces to the geometric distribution for trials until the first success:
\[
P(X=k)=\binom{k-1}{0}p(1-p)^{k-1}=p(1-p)^{k-1}.
\]
So the geometric distribution is a special case of the negative binomial distribution.
In more advanced courses, the negative binomial also appears as a sum of independent geometric waiting times
(you can think of the waiting time to get \(r\) successes as the total of the waiting times between consecutive successes).
How to use this tool
Enter \(r\), \(p\), and the trial index \(k\) and click Calculate to compute \(P(X=k)\) with step-by-step work.
The tool also reports the mean and variance, and it draws a PMF bar chart that you can pan and zoom.
The top animation panel shows a sample run of trials and tracks how successes accumulate until the \(r\)-th success.
Press Simulate to generate a random run and see how the stopping time changes from run to run — a good way to build intuition for “hits until goal” problems.