Hi,
I am fitting the built-in SkewedGaussianModel to some data. The fit seems to be working well but when I print the parameters of the fitted model the values seems to be off. Looking at the attached plot I expect the amplitude to be around 30, the center around 6, sigma around 2, I guess. When I print the parameters I get
{'amplitude': 152.51586530547021, 'center': 4.95450125813345, 'sigma': 3.5260258280394083, 'gamma': 3.074519008172669}
What am I missing?
The code used to make this plot:
#-----
import numpy as np
import matplotlib.pyplot as plt
from lmfit.models import SkewedGaussianModel
np.random.seed(42)
bins = np.linspace(0, 15, 101)
# Generate something like a skewed Gaussian distribution
mult_x = np.linspace(1, 2, 1000)
data_y = (np.random.randn(1000) + 5) * mult_x
# Make the histogram
vals, bins = np.histogram(data_y, bins=bins)
x = (bins[1:]+bins[:-1])/2
# Fit a model
model = SkewedGaussianModel()
params = model.make_params(amplitude=np.max(vals),\
center=x[np.argmax(vals)],\
sigma=1,\
gamma=2)
Dgau = model.fit(vals, params=params, x=x)
# Get the fitted values
fitted_values = Dgau.eval(x=x)
# Plot
plt.plot(x, vals)
plt.plot(x,fitted_values)
plt.axvline(x=Dgau.values['center'], color='black', lw=0.5)
plt.show()
print(Dgau.values)
#-----
Cheers,
Boris