0

I am trying to use Scipy.stats norm.fit() with some modifications to fit data with a log-normal distribution. And I want to verify the result with fitting the data using Scipy.stats lognorm.fit(). The result comes out to be just similar, but it should be the same. (The picture is shown in below link)

https://ibb.co/PxHWSNp

The way I use norm.fit() to fit data with log-normal distribution is that I bring in the log(x) in norm.fit() and divide the pdf by x. The reason for why I do this comes from the below two formulas.(The only difference in log-normal distribution pdf is the ln(x) and 1/x term) Could anybody help me on identifying where I am doing wrong?

  1. log-normal distribution pdf: https://ibb.co/Zd9J17T

  2. normal distribution pdf: https://ibb.co/Mgvpv31

#x is set from the center of the leftmost bar to the center of the rightmost bar
x = np.linspace(left_boundary,right_boundary,1000)

#data1 is the original data
data2 = np.log(data1)

params1 = lognorm.fit(data1,method='MLE',loc=0)
plt.plot(x,lognorm.pdf(x,params1[0],params1[1],params1[2]),label='Log-Normal fitting using lognorm.fit()')

params2 = norm.fit(data2,method='MLE',loc=0)
# Here I bring in the log(x) and divide the pdf by x
plt.plot(x,norm.pdf(np.log(x),params2[0],params2[1])/x,label='Log-Normal fitting using norm.fit()')

The reason why I want to do this is to check if I can copy the same way to derive the log-pearson3 distribution fitting since there's no log-pearson3 I can find in any library. Thank you.

Peter__C
  • 1
  • 2
  • Does this answer your question? [Scipy: lognormal fitting](https://stackoverflow.com/questions/18534562/scipy-lognormal-fitting) – m13op22 Oct 17 '22 at 15:02
  • I think there are some differences. I am directly obtaining parameters from the norm.fit() function by bringing in the log(x) into it, but not setting mu or sigma by myself. – Peter__C Oct 17 '22 at 16:17

0 Answers0