Probability Distribution Function and Shape
> restart;
> with(plots):
>
The Negative Binomial Distribution
Consider observing independent Bernoulli trials having success probability p until r successes
have been observed. For example, flipping a coin until r heads are observed is
such an exercise. If we define a random variable X as the number of trials required to observe
the first r successes then X is said to have the Negative Binomial ( r, p ) distribution.
If X is a random variable having the Negative Binomial ( r , p ) distribution, then the probability
distribution function for X is
f ( k ) = P( X = k ) = , k = r , r +1, r +2, ...
The form of this function can be seen by way of the following argument. The probability of any
fixed sequence of r successes and k-r failures has probability . How many such
sequences of r successes and k-r failures have a success on the k th trial? Namely,
binomial( k -1, r -1), as we are free to assign the first r -1 successes among the first k -1 trials.
The following code will draw a probability histogram for the Negative Binomial ( r , p ) distribution
for your choice of r and p .
> r:=4;
> p:=0.5;
> ProbHist(NegBinomialPDF(r,p,x),1..20,20);
>
To see the effect of p on the shape of the Negative Binomial ( r , p ) distribution, the following
animation will draw a series of probability histograms as p varies from 0.05 to 0.5 by
increments of 0.05, assuming a fixed value of r .
> r:=4:
> for n from 0 to 9 do
> num:=convert(evalf(0.05+n*0.05), string):
> tracker[n]:=textplot([30,0.12,`p is `.num],color=blue):
> H[n]:=ProbHist(NegBinomialPDF(r,0.05+n*0.05,x),1..40,40):
> P[n]:=display({H[n],tracker[n]}):
> od:
> display(seq(P[n],n=0..9), insequence=true,title="r is fixed, p is increasing");
>
To see the effect of r on the shape of the Negative Binomial ( r , p ) distribution, the following
animation will draw a series of probability histograms as r varies from 1 to 20, assuming a
fixed value of p .
> p:=0.5:
> for r from 1 to 20 do
> num:=convert(evalf(r), string):
> tracker[r]:=textplot([60,0.25,`r is `.num],color=blue):
> H[r]:=ProbHist(NegBinomialPDF(r,p,x),1..80,80):
> P[r]:=display({H[r],tracker[r]}):
> od:
> display([seq(P[r], r=1..20)], insequence=true,title="p is fixed, r is increasing");
>
>
>