The negative binomial distribution

The negative binomial distribution is used for independent Bernoulli trials and measures the number of tries (X=k) that are needed before a specified number of successes (r) occur. An example would be the number of coin tosses it would take to obtain five heads. The PMF is given as follows:

The expectation and variance are given respectively by the following expressions:

 
 

We can see that the negative binomial is a generalization of the geometric distribution, with the geometric distribution being a special case of the negative binomial, where r=1.

The code and plot are shown as follows:

    In [189]: from scipy.stats import nbinom
           from matplotlib import colors
        clrs = matplotlib.rcParams['axes.color_cycle']
        x = np.arange(0,11)
        n_vals = [0.1,1,3,6]
        p=0.5
              for n, clr in zip(n_vals, clrs):
                  rv = nbinom(n,p)
                  plt.plot(x,rv.pmf(x), label="$n$=" + str(n), color=clr)
                  plt.legend()
              plt.title("Negative Binomial Distribution PMF")
              plt.ylabel("PMF at $x$")
              plt.xlabel("$x$")

The following is the output:

Negative binomial distribution
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset