[SciPy-User] Need help to use rv_continuous.fit

Paul Kienzle paul.kienzle at nist.gov
Wed Dec 5 11:31:03 EST 2012


On Dec 5, 2012, at 10:11 AM, Sepideh Rastin <sepideh at isc.ac.uk> wrote:

> Hi there,
> I have histograms that will form the likelihood function and need to 
> find the best normal distributions.
> I would like to know if it would be possible to create my input array to 
> rv_continuous.fit using the data of my histograms.

If you have the raw data, you can just use mean() and std() functions.

E.g.,

from pylab import *

n = 1000
mu = 2
sigma = 0.3

def G(x,m,s): return exp(-((x-m)/s)**2/2)/sqrt(2*pi*s**2)

# fake data
s = randn(n)*sigma + mu

# estimates
mu_hat, sigma_hat = mean(s), std(s)

# plot
t = linspace(mu-3*sigma,mu+3*sigma,200)
bins = linspace(t[0],t[-1],21)
step = bins[1]-bins[0]
hist(s,bins=bins)
plot(t,G(t,mu_hat,sigma_hat)*n*step,'g',hold=True)
show()

  - Paul

Paul Kienzle
pkienzle at nist.gov



More information about the SciPy-User mailing list