[SciPy-User] gamma distribution fitting: newbie question

Bala subramanian bala.biophysics at gmail.com
Sun May 3 13:12:42 EDT 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150503/7711e992/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.dat
Type: application/x-ns-proxy-autoconfig
Size: 98368 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150503/7711e992/attachment.dat>


More information about the SciPy-User mailing list