Probability Distributions and their Stories

Given any module that deals with statistics, one basic skill you must have is to be able to program and create plots of probability distributions typically encountered in the field of data science. This tutorial should remind you of various distributions introduced in this section, but now they are phrased using the scipy.stats module.

Continuous distributions

Inverse Gamma distribution

  • Story. If x is Gamma distributed, then 1/x is Inverse Gamma distributed.
  • Parameters. The number of arrivals, α, and the rate of arrivals, β.
  • Support. The Inverse Gamma distribution is supported on the set of positive real numbers.
  • Probability density function.

    \begin{align}f(y;\alpha, \beta) = \frac{1}{\Gamma(\alpha)}\,\frac{\beta^\alpha}{y^{(\alpha+1)}}\,\mathrm{e}^{-\beta/ y}\end{align}

  • Usage
  • Package Syntax
    NumPy 1 / np.random.gamma(alpha, 1/beta)
    SciPy `scipy.stats.invgamma(alpha, loc=0, scale=beta)
    Stan inv_gamma(alpha, beta)


  • Notes.
    • The Inverse Gamma distribution is useful as a prior for positive parmeters. It imparts a quite heavy tail and keeps probability further from zero than the Gamma distribution.
    • The numpy.random module does not have a function to sample directly from the Inverse Gamma distribution, but it can be achieved by sampling out of a Gamma distribution as shown in the NumPy usage above.

params = [dict(name='α', start=0.01, end=2, value=0.5, step=0.01),
          dict(name='β', start=0.1, end=2, value=1, step=0.01)]
app = distribution_plot_app(x_min=0,
                            x_max=20,
                            scipy_dist=st.invgamma,
                            params=params,
                            transform=lambda alpha, beta: (alpha, 0, beta),
                            x_axis_label='y',
                            title='Inverse Gamma')

bokeh.io.show(app, notebook_url=notebook_url)