[SciPy-User] how to fit a given pdf
Wed Aug 11 11:14:05 CDT 2010
On 8/11/10 09:00 , email@example.com wrote:
> Date: Wed, 11 Aug 2010 12:00:22 -0300
> From: Renato Fabbri<firstname.lastname@example.org>
> Subject: [SciPy-User] how to fit a given pdf
> To: Discussion of Numerical Python<email@example.com>,
> Content-Type: text/plain; charset="iso-8859-1"
> Dear All,
> help appreciated, thanks in advance.
> how do you fit a pdf you have with a given pdf (say gamma).
> with the file attached, you can go like:
> data=[int(i) for i in aaa]
> if you do pylab.plot(data); pylab.show()
> The data is something like:
> It is my pdf (probability density function).
> how can i find the right parameters to make that fit with a gamma?
> if i was looking for a normal pdf, for example, i would just find mean
> and std and ask for the pdf.
> i've been playing with scipy.stats.distributions.gamma but i have not
> reached anything.
> we can extend the discussion further, but this is a good starting point.
> any idea?
I am not familiar with the scipy.stats module, and so I do not know what
it can do for you. However, I would just generate a model gamma
distribution from the mean and variance, just as for a normal
distribution. The gamma distribution equation can be written as
p(x) = p0/(b^a*Gamma(a))*x^(a-1)*exp(-x/b)
assuming x starts at zero (x>=0)
(http://en.wikipedia.org/wiki/Gamma_distribution). Then the the
parameters a and b are related to the mean and variance by
a = mean^2/var
b = var/mean
(I did the algebra quickly just now, and so you might want to
double-check). p0 is the area under the distribution and may be simply
1 if your distribution is normalized.
Hope this helps.
More information about the SciPy-User