[SciPy-User] gamma ppf weirdness
Art Poon
artpoon@gmail....
Wed Nov 25 01:05:31 CST 2009
Excellent, thanks very much.
- Art.
On 2009-11-24, at 11:00 PM, josef.pktd@gmail.com wrote:
> On Wed, Nov 25, 2009 at 1:44 AM, <josef.pktd@gmail.com> wrote:
>> On Wed, Nov 25, 2009 at 1:30 AM, Art Poon <artpoon@gmail.com> wrote:
>>> Hello,
>>> I'm trying to hammer out some quick simulation code and need to calculate a
>>> bunch of inverse CDF values from the gamma distribution. SciPy seems like a
>>> great resource for this. However, I've encountered some strangeness that is
>>> probably my own fault:
>>>>>> g = stats.gamma(1,0,1)
>>>>>> g
>>> <scipy.stats.distributions.rv_frozen object at 0x1b9b2b0>
>>>>>> g.ppf(0.1)
>>> 0.10536051565782635
>>>>>> g.ppf(0.25)
>>> 0.0
>>>>>> g.ppf(0.2500001)
>>> 0.28768220578512327
>>>>>> g.ppf(0.2499999)
>>> 0.28768193911845646
>>>>>> g.ppf(0.25)
>>> 0.0
>>> I'm just dying to know where I've gone wrong here! In the meantime, I'm
>>> coding up a function to compute the inverse CDF from MATLAB code.
>>> I'm using Snow Leopard with Python 2.5.4 (bypassing default system Python
>>> 2.6.1), numpy-1.3.0 and scipy-0.7.1, both compiled from source.
>>> Thanks!
>>> - Art.
>>
>> this has been fixed in trunk, see http://projects.scipy.org/scipy/ticket/975
>>
>>>>> stats.gamma.ppf(0.25, 1.,0.,1)
>> 0.28768207245178096
>>>>> stats.gamma.ppf(0.2500001, 1.,0.,1)
>> 0.28768220578512327
>>>>> stats.gamma.ppf(0.25 -0.00001, 1.,0.,1)
>> 0.28766873920733566
>>>>> stats.gamma.ppf(0.25, 1,0,1)
>> 0.28768207245178096
>>>>> stats.gamma(1,0,1).ppf(0.25)
>> 0.28768207245178096
>>>>> import scipy
>>>>> scipy.version.version
>> '0.8.0.dev6118'
>>
>>
>> Josef
>>
>>>
>
> scipy special also has the function for the gamma.isf (which is
> currently not used in stats.gamma)
>
>>>> special.gammainccinv(1, 1-0.25)
> 0.28768207245178096
>
> You could check whether it is correct on 0.7.0, but I'm not sure
> whether special.gammaincinv(a,q) and special.gammainccinv(1, 1-0.25)
> are really independent implementation.
>
> Josef
>
>
>>>
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>
>>>
>>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list