0

When defining a lognormal function with a mean of 15.1466 and a standard deviation of 0.3738, the result you should get is the following:

enter image description here

However when I run the following code to do it with python the result I get is not the same.

mu, sigma = 15.1466, 0.3738
s = np.random.lognormal(mu, sigma, 10000)
count, bins, ignored = plt.hist(s, 30,
                                density=True, 
                                color='blue')
x = np.linspace(min(bins),
                max(bins), 10000)
  
pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))
       / (x * sigma * np.sqrt(2 * np.pi)))
  
plt.plot(x, pdf, color='black')
plt.grid()
plt.show()

enter image description here

turaran32
  • 83
  • 8
  • The first plot you have shown looks like a *regular* normal distribution with mean 15.1 and standard deviation 0.37 to me. – mkrieger1 Jul 29 '21 at 12:20
  • 1
    mu sigma are not the mean and std of lognormal here. You have to change them. Please go through the above link answer. – Pygirl Jul 29 '21 at 12:21
  • what should i have to do? I check the link above but I don't understand. How should I define the function? – turaran32 Jul 29 '21 at 15:12

1 Answers1

2

Mean and standard deviation are NOT THE SAME as distribution parameters mu and sigma for log-normal

Check wiki

Basically, given mean and std.dev, you compute mean and variance, and then solve system of two equations to find mu and sigma

Only then you feed mu and sigma into routines for sampling, PDF etc

Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64