I have:
from scipy import stats
data = stats.gamma.rvs(2, loc=1.5, scale=2, size=100000)
so I do a fit on that
fitted_params = scipy.stats.gamma.fit(data)
how do I calculate the AIC from that?
AIC = 2*k - 2*ln(L)
where k is the number of parameters fitted and L is the maximum log likelihood function
k = len(fitted_params)
aic = 2*k - 2*(logLik)
logLik
would be ?
I found this snippet:
logLik = -np.sum( stats.norm.logpdf(data, loc=yPred, scale=sd) )
from Maximum Likelihood Estimate
so is my function going to be:
# 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) )