[SciPy-user] Question about scipy.stats
Jesús Carrete Montaña
kuantiko at escomposlinux.org
Sat May 5 16:55:47 EDT 2007
El Sábado, 5 de Mayo de 2007 22:14, Donald Fredkin escribió:
> Jesús Carrete Montaña wrote:
> > I get the following error when trying to evaluate the
> > probability density function for a Poisson distribution:
> >
> > from scipy import *
> >
> > d2=stats.poisson(loc=1.,scale=2.)
> > x=arange(1,10,1)
> > d2.pdf(x)
>
> What is a probability density function (pdf) for a Poisson
> distribution? and what does scale mean? Both notions are fine for a
> Gaussian distribution, which is continuous, but the Poisson
> distribution is discrete and contains only one parameter.
While your observations are formally correct, the documentation for
scipy.stats states that the pdf() method should exist - I suppose it
should work as the discrete counterpart of a true PDF, returning the
probability of its argument (or raising an exception if it's not an
integer). Similarly, although the Poisson distribution is
uniparametric, the same documentation says that those two arguments
should be accepted by all the constructors (even if they are ignored).
I included them only to make the parallelism between my calls to
poisson() and norm() more evident.
To avoid confusion, let's take an example of a continous, biparametric
distribution such as scipy.stats.beta:
XXXXXXXXXXXXXXXXXXXX--code--XXXXXXXXXXXXXXXXXXX
import scipy.stats
d=scipy.stats.beta(loc=.2,scale=.1)
d.pdf(.3)
---------------------------------------------------------------------------
exceptions.TypeError Traceback (most
recent call last)
/home/kuantiko/latex/2006-2007/lFNyP/memoria/<ipython console>
/usr/lib/python2.4/site-packages/scipy/stats/distributions.py in
pdf(self, x)
104 self.dist = dist
105 def pdf(self,x):
--> 106 return self.dist.pdf(x,*self.args,**self.kwds)
107 def cdf(self,x):
108 return self.dist.cdf(x,*self.args,**self.kwds)
/usr/lib/python2.4/site-packages/scipy/stats/distributions.py in
pdf(self, x, *args, **kwds)
466 goodargs = argsreduce(cond, *((x,)+args+(scale,)))
467 scale, goodargs = goodargs[-1], goodargs[:-1]
--> 468 place(output,cond,self._pdf(*goodargs) / scale)
469 return output
470
TypeError: _pdf() takes exactly 4 arguments (2 given)
XXXXXXXXXXXXXXXXXXXX--code--XXXXXXXXXXXXXXXXXXX
The exact same code, but changing 'beta' to 'norm', works as expected. I
suppose I am doing something wrong (given the lack of answers to my
original message, probably something very elementary) but I still
haven't been able to find the solution. I'm using the functions from
Rpy in the meantime: great software, but IMHO terribly slow. I would
prefer to use only scipy and would e very grateful if someone pointed
me to the answer.
Thanks,
Jesús.
More information about the SciPy-User
mailing list