The gamma distribution can be used to model the size of insurance claims, rainfall, and the distribution of inter-spike intervals in brains. The PDF for the gamma distribution is defined by shape k and scale θ as follows:
There is also a definition that uses an inverse scale parameter (used by SciPy). The mean and variance of the gamma distribution are described by (3.3) and (3.4). As you can see, we can estimate the shape parameter from the mean and variance using simple algebra.
Let's fit aggregates for the rain data for January to the gamma distribution:
Start with the following imports:
from scipy.stats.distributions import gamma import matplotlib.pyplot as plt import dautil as dl import pandas as pd from IPython.display import HTML
Load the data and select aggregates for January:
rain = dl.data.Weather.load()['RAIN'].resample('M').dropna() rain = dl.ts.groupby_month(rain) rain = rain.get_group(1)
Derive a value for k from the...