[SciPy-user] Gamma distribution questions

Jinsheng you youjins_scipy at hotmail.com
Sat Sep 10 15:15:29 CDT 2005

Dear.  Robert Kern,

I greatly appreciate your help.  I will try this and also read the 
documentation before any further question.

Jinsheng You

>From: Robert Kern <rkern at ucsd.edu>
>Reply-To: SciPy Users List <scipy-user at scipy.net>
>To: SciPy Users List <scipy-user at scipy.net>
>Subject: Re: [SciPy-user] Gamma distribution questions
>Date: Thu, 08 Sep 2005 15:07:57 -0700
>Jinsheng you wrote:
> > I have some projects related to the gamma distribution.   would you
> > please help me with these:
>First, please read the documentation in Lib/stats/continuous.pdf in the
>source distribution. The following probably won't make sense otherwise.
> > 1) Assuming that I have a gamma distribution dataset, how can I estimate
> > parameters such as alpha, beta from the dataset.
>I assume for the rest of this post that alpha is the shape parameter and
>beta is the scale parameter.
>Currently, the fit() method of distributions is broken. There's a
>problem with the way it passes arguments to the nnlf() method; that
>problem seems to apply to all distributions. There is also a problem
>with distributions like Gamma which are intrinsically positive; all of
>the distribution objects take a loc parameter. For intrinsically
>positive variates like Gamma, this really should be fixed to 0 all of
>the time.
>So you are going to have to do a little bit of this manually.
>from scipy import *
>def f(params, data):
>     return -sum(log(stats.gamma.pdf(data, params[0], scale=params[1]))
>And then you can use one of the minimizers in scipy.optimize to minimize
>f(). That's called the "maximum likelihood method," which may or may not
>be appropriate for what you want to do.
> > 2) assuming that I know the alpha and beta of the distribution, how can
> > I get the value for a given probability.
>Probability of what?
> > 3) assuming that I know the alpha and beta of the distribution, how can
> > I get the probability for a given x.
>By definition, the probability for any given point value is 0. You can
>get the value of the probability *density function* by using the pdf()
>method of scipy.stats.gamma . If you want the probability of getting a
>value <= x, then the cdf() method will give you that. If you want the
>probability of getting a value >= x, then 1-cdf().
>Robert Kern
>rkern at ucsd.edu
>"In the fields of hell where the grass grows high
>  Are the graves of dreams allowed to die."
>   -- Richard Harter
>SciPy-user mailing list
>SciPy-user at scipy.net

Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

More information about the SciPy-user mailing list