i have fitting gamma distribution using scipy.stats. able extract shape, loc, , scale params , reasonable data ranges expect.
my question is: there way errors in parameters? output of curve_fit. note: don't use curve fit directly because not working , of time not able compute parameters of gamma distribution. on other hand, scipy.stats.gamma.fit works ok.
this example (no actual data) of doing.
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 not same (shape, loc, scale) # how estimate/get errors each param? thanks in advance
edit warning: following illustrates use of genericlikelihoodmodel following example in question. however, in case of gamma distribution location parameter shifts support of distribution ruled out general assumptions maximum likelihood estimation. more standard usage fix support, floc=0, two-parameter distribution. in case, standard mle theory applies.
statsmodels has generic class maximum likelihood estimation, genericlikelihoodmodel. it's not directly designed case, can used (defining attributes , providing start_params).
import numpy np statsmodels.base.model import genericlikelihoodmodel 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 not same (shape, loc, scale) # how estimate/get errors 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()) this prints following
(10.31888758604304, 0.71645502437403186, 0.018447479022445423) optimization terminated successfully. current function value: -1.439996 iterations: 69 function evaluations: 119 gamma results ============================================================================== dep. variable: y log-likelihood: 1440.0 model: gamma aic: -2872. method: maximum likelihood bic: -2852. date: sun, 12 jul 2015 time: 04:00:05 no. observations: 1000 df residuals: 997 df model: 3 ============================================================================== coef std err z p>|z| [95.0% conf. int.] ------------------------------------------------------------------------------ par0 10.3187 2.242 4.603 0.000 5.925 14.712 par1 0.7165 0.019 37.957 0.000 0.679 0.753 par2 0.0184 0.002 8.183 0.000 0.014 0.023 ============================================================================== other results based on maximum likelihood estimates available, example z-test first parameter 10 can performed either specifying restriction matrix or using string expression equality:
>>> res.t_test(([1, 0, 0], [10])) <class 'statsmodels.stats.contrast.contrastresults'> test constraints ============================================================================== coef std err z p>|z| [95.0% conf. int.] ------------------------------------------------------------------------------ c0 10.3187 2.242 0.142 0.887 5.925 14.712 ============================================================================== >>> res.t_test('par0=10') <class 'statsmodels.stats.contrast.contrastresults'> test constraints ============================================================================== coef std err z p>|z| [95.0% conf. int.] ------------------------------------------------------------------------------ c0 10.3187 2.242 0.142 0.887 5.925 14.712 ==============================================================================
Comments
Post a Comment