[SciPy-Dev] scipy.stats

josef.pktd at gmail.com josef.pktd at gmail.com
Sat Apr 21 20:41:12 EDT 2012


On Sat, Apr 21, 2012 at 5:58 PM, nicky van foreest <vanforeest at gmail.com> wrote:
> On 21 April 2012 23:45,  <josef.pktd at gmail.com> wrote:
>> On Sat, Apr 21, 2012 at 5:31 PM, nicky van foreest <vanforeest at gmail.com> wrote:
>>>> In [11]: from scipy.stats import uniform
>>>>
>>>> In [12]: U = uniform(loc = 3, scale = 5)
>>>>
>>>> In [13]: U.mean()
>>>> Out[13]: 5.5
>>>>
>>>> In [14]: U.moment(1)
>>>> Out[14]: 0.5
>>>
>>> Might this problem be due to the fact that my ubuntu machine does not
>>> support the latest version of scipy.stats?
>>
>> I'm stil on 0.9 and there is no loc, scale option
>>
>>>>> import scipy
>>>>> scipy.__version__
>> '0.9.0'
>>>>> stats.uniform.moment(loc = 3, scale = 5)
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>> TypeError: moment() got an unexpected keyword argument 'loc'
>>>>> U.moment(1)
>> 0.5
>>>>> stats.uniform.moment(1)
>> 0.5
>>
>> Obviously I'm not up to date in this.
>>
>> can you try the distribution directly instead of the frozen distribution?
>
> I am having the same problems as you, although:
>
> In [9]: ? uniform.moment
> Type:           instancemethod
> Base Class:     <type 'instancemethod'>
> String Form:    <bound method uniform_gen.moment of
> <scipy.stats.distributions.uniform_gen object at 0x2e901d0>>
> Namespace:      Interactive
> File:           /usr/lib/python2.7/dist-packages/scipy/stats/distributions.py
> Definition:     uniform.moment(self, n, *args)
> Docstring:
>    n'th order non-central moment of distribution
>
>    Parameters
>    ----------
>    n: int, n>=1
>        order of moment
>
>    arg1, arg2, arg3,... : array-like
>        The shape parameter(s) for the distribution (see docstring of the
>        instance object for more information)

>>> stats.uniform.moment(1, loc=3, scale=1)
3.5
>>> stats.uniform(loc=3, scale=1).moment(1)
3.5

>>> import scipy
>>> scipy.__version__
'0.10.0b2'


version mismatch with new documentation

In the older versions of scipy, the frozen distributions didn't always
pass on the keywords, loc and scale, so they were just quietly
ignored.

It looks like now moment handles loc and scale

>>> stats.uniform.mean(1, loc=3, scale=5)
5.5
>>> stats.uniform.moment(1, loc=3, scale=5)
5.5

>>> stats.uniform.ppf([0, 1], loc=3, scale=5)
array([ 3.,  8.])
>>> stats.uniform.ppf([0, 1], loc=3, scale=5).mean()
5.5


Josef

>
>
> BTW: all of these points stem from my intention to add some function
> to scipy stats to compute/approximate the convolution of two r.v.s.
> One such method proposes to use moment matching...
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev



More information about the SciPy-Dev mailing list