I want to fit histograms with a skewed gaussian. I take my data from a text file:
rate, err = loadtxt('hist.dat', unpack = True)
and then plot them as a histogram:
plt.hist(rate, bins= 128)
This histogram has a skewed gaussian shape, that I would like to fit.
I can do it with a simple gaussian, because scipy has the function included, but not with a skewed. How can I proceed?
Possibly, a goodness of fit test returned would be the best.
You might find lmfit (http://lmfit.github.io/lmfit-py/) useful. This has a Skewed Gaussian model built in. Your problem might be as simple as
from lmfit.models import SkewedGaussianModel
xvals, yvals = read_your_histogram()
model = SkewedGaussianModel()
# set initial parameter values
params = model.make_params(amplitude=10, center=0, sigma=1, gamma=0)
# adjust parameters to best fit data.
result = model.fit(yvals, params, x=xvals)
print(result.fit_report())
pylab.plot(xvals, yvals)
pylab.plot(xvals, result.best_fit)
This will report the values and uncertainties for the parameters amplitude, center, sigma (for the normal Gaussian), and gamma, the skewness factor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With