title: How do I calculate the AIC for a distribution in scipy?
body: <p>I have:</p>
  
  <pre><code>from scipy import stats
  data = stats.gamma.rvs(2, loc=1.5, scale=2, size=100000)
  </code></pre>
  
  <p>so I do a fit on that</p>
  
  <pre><code>fitted_params = scipy.stats.gamma.fit(data)
  </code></pre>
  
  <p>how do I calculate the AIC from that?
  <code>AIC = 2*k - 2*ln(L)</code> where k is the number of parameters fitted and L is the maximum log likelihood function</p>
  
  <pre><code>k = len(fitted_params)
  aic = 2*k - 2*(logLik)
  </code></pre>
  
  <p><code>logLik</code> would be ? </p>
  
  <p>I found this snippet:</p>
  
  <pre><code>logLik = -np.sum( stats.norm.logpdf(data, loc=yPred, scale=sd) ) 
  </code></pre>
  
  <p>from <a href="https://stackoverflow.com/questions/7718034/maximum-likelihood-estimate-pseudocode">Maximum Likelihood Estimate</a></p>
  
  <p>so is my function going to be:</p>
  
  <pre><code># calc SD of fitted distribution
  sd = std(loc=fitted_params[1], scale=fitted_params[2])
  
  # sample values from fitted dist same length as original data array
  yPred = rvs(fitted_params[0], loc=fitted_params[1], scale=fitted_params[2], size=len(data), random_state=None)
  
  # calc the log likelihood 
  logLik = -np.sum( stats.gamma.logpdf(data, loc=yPred, scale=sd) ) 
  </code></pre>