You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: GenericLikelihoodWrapper for scipy.stats distribution fit #2527
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 12 03:44:40 2015
Author: Josef Perktold
License: BSD-3
"""
import numpy as np
from statsmodels.base.model import GenericLikelihoodModel
from scipy.stats import gamma
shape = 12; loc = 0.71; scale = 0.0166
data = gamma.rvs(shape, loc=loc, scale=scale, size=1000)
params = gamma.fit(data) # params close to but not the same as (shape, loc, scale)
# HOW TO ESTIMATE/GET ERRORS FOR EACH PARAM?
print(params)
print('\n')
class Gamma(GenericLikelihoodModel):
nparams = 3
def loglike(self, params):
return gamma.logpdf(self.endog, *params).sum()
res = Gamma(data).fit(start_params=params)
res.df_model = len(params)
res.df_resid = len(data) - len(params)
print(res.summary())
print('\n')
res.t_test(([1, 0, 0], [10]))
res.t_test('par0=10')
import statsmodels.api as sm
res_glm = sm.GLM(data, exog=np.ones(len(data)),
family=sm.families.Gamma(link=sm.families.links.identity)).fit()
print(res_glm.summary())
print(gamma.mean(*params))
print(gamma.var(*params))
GLM Gamma only has mean parameter and separately estimated scale parameter. Note: Pearson chisquare as scale estimate does not correspond to the variance of endog.
Activity