[SciPy-user] accuracy of stats.gamma.pdf
josef.pktd@gmai...
josef.pktd@gmai...
Thu Jan 29 08:51:40 CST 2009
On Thu, Jan 29, 2009 at 8:40 AM, Nicolas CHOPIN
<nicolas.chopin@bristol.ac.uk> wrote:
> Pauli Virtanen <pav <at> iki.fi> writes:
>
>>
>> Thu, 29 Jan 2009 12:52:37 +0000, Pauli Virtanen wrote:
>> [clip]
>> > It appears that scipy.stats.gamma doesn't have a scale parameter.
>>
>> Oops, obviously it has a scale parameter:
>>
>> In Scipy:
>> >>> scipy.stats.gamma.pdf(5, 2, 0, 1.0/5)
>> 1.7359929831205026e-09
>>
>> In R:
>> > dgamma(5,2,5)
>> [1] 1.735993e-09
>>
>> So, no bugs present, just different order of arguments.
>>
>
>
> oops, many thanks, I managed to misunderstand both R and scipy.stats syntaxes,
> sorry...
> A poor excuse is that in my field Gamma(a,b) distributions refers to Gamma with
> shape a, and scale=1/b, and nobody uses a location parameter.
> Thanks again
>
I'm glad this is cleared up, I appreciate any report on differences
with R, since not all corner cases are properly tested.
Location and scale are keyword arguments for any continuous
distribution and are handled generically, (which currently has the
disadvantage that fit cannot estimate the distribution parameters
while keeping the location fixed).
That's my way of checking a distribution without looking at the source:
>>> stats.gamma.numargs
1
>>> stats.gamma.shapes
'a'
>>> print stats.gamma.extradoc
Gamma distribution
For a = integer, this is the Erlang distribution, and for a=1 it is the
exponential distribution.
gamma.pdf(x,a) = x**(a-1)*exp(-x)/gamma(a)
for x >= 0, a > 0.
>>> stats.gamma.pdf(5.,2.,loc=0,scale=5)
0.07357588823428847
>>> stats.gamma.pdf(5.,2.,loc=5)
0.0
>>> stats.gamma.pdf(5.,2.,loc=0,scale=1/5.)
1.7359929831205026e-009
Josef
More information about the SciPy-user
mailing list