[SciPy-User] gamma distribution fitting: newbie question

Oleksandr Huziy guziy.sasha at gmail.com
Sun May 3 14:29:54 EDT 2015


Hi:

1) I think your fitting is OK.

2) The bigger the n the better. You get different curves, because you are
not plotting it right. Please see here the corrected example (from your
code):
http://nbviewer.ipython.org/github/guziy/PyNotebooks/blob/master/Gamma_dist.ipynb

3) I do not feel comfortable writing about chi2 or p-value, hopefully
someone more knowledgeable can help.

Cheers







2015-05-03 13:12 GMT-04:00 Bala subramanian <bala.biophysics at gmail.com>:

> Friends,
> I am a newbie to scipy and distribution fitting. I have written following
> code to fit gamma distribution to my data (attached .txt file)
>
> from scipy.stats import gamma
> import matplotlib.pyplot as plt
> *# take the data*
> data = np.loadtxt('test.dat',skiprows=1)
> n, bins, patches = plt.hist(data[:,1],bins=50, normed=1,
> visible=True,color='white')
> col=['red','magenta','green']
>
> *#estimate gamma params*
> param = gamma.fit(data[:,1],floc=0)
>
> i=0
> *for val in [500,800,1000]*:
>     x = np.linspace( np.min(data[:,1]) , np.max(data[:,1]), val)
>     *# create a fitted curve*
>     pdf_fitted = gamma.pdf( x, param[0], scale=param[-1] )
>     plt.plot(pdf_fitted, c=col[i],lw=2)
>     i += 1
>
> plt.show()
>
> q1) I would like to know if i am doing the fitting correctly ?
>
> q2) When i use various sample values (for loop above), i get different
> fitted curves all with the same shapes. I dnt understand how to choose this
> n value.
>
> q3) If i have to estimate the chi2 and p value to see the goodness of fit,
> how can i do it in scipy. Someone please give the code i should use for the
> same. I want to see if my data follows a gamma distribution.
>
> Thanks,
> Bala
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>


-- 
Sasha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150503/9fb05581/attachment.html>


More information about the SciPy-User mailing list