[SciPy-user] Fitting a distribution to some data

Travis Oliphant oliphant.travis at ieee.org
Wed Sep 6 14:29:45 CDT 2006


Jose Luis Gomez Dans wrote:
> Hi,
> I am trying to fit a distribution to some data points (actually, I want to test which distribution is best to model the data). Moreover, I want to estimate the distributions parameters. I am sure that the stats module has many functions to help me with this, but I am not sure I understand how to use them. 
>
> As a test, I create some RVs using say y=stats.distributions.norm.rvs ( size=100).
>  I can then find the mean and standard deviation using 
> (mu,sigma)=stats.distributions.norm.fit(y)
> which works fine. However, some methods do not work. For example, the pdf(self,x..) method returns an array of 0s, and similarly for the cdf() method. 
Are you using these functions correctly?  They seem to work for me.   
For example, you don't pass in "self" as the first argument.

Here is a usage

x = r_[-10:10:100j]
y = stats.distribution.norm.pdf(x, loc=0.3, scale=2.0)

> Also, is there some example of how to use kstest? it might be related, but if I try to test the previous data, I get the following error:
> stats.kstest(y,'norm',args=(mu,sigma))
>   

Hmm..  This works for me.

y=stats.distributions.norm.rvs(size=100)    
mu,sigma = stats.distributions.norm.fit(y)
stats.kstest(y,'norm',args=(mu,sigma))

I am running scipy 0.5.1, but I don't know if that should matter in this 
case.

-Travis



More information about the SciPy-user mailing list