I have some function that according to literature should approximate a log normal distribution. To fit it, I am using a hacky (yet legitimate) approach to fit pre binned data:
from scipy import stats
counts, bin_centers = np.array(distr), np.linspace(0, len(distr)+0, len(distr)) # where bins are bin edges on x axis
restore data from hist: count multiplied bin centers
restored = [[d]*int(counts[n]) for n,d in enumerate(bin_centers)]
flatten result
restored = np.hstack(np.array(restored))
dist = stats.lognorm(*stats.lognorm.fit(restored))
x = np.arange(0,max(bin_centers))
y = dist.pdf(x)
PDF is normalized, so scale it to match hist
y= y/y.max()
y = y*counts.max()
This almost works, in that modeled fit seems to be off. Is this a consequence of my data potentially not being actually log normal to begin with? Or some better approach is possible?
