It seems PyMC3 calculates the Mean and Standard Deviation (SD) of Lognormal distribution in a different way which is not the same as found in a standard textbook. Can somebody please explain what Mean and SD should I use in PyMC3 while fitting a Lognormal Distribution?
As shown in the figure, I have obtained Negative values of lambda and epsilon (the fitting parameters of Lognormal as given in Wikipedia).
I have used the above relationship to obtain lambda and epsilon for pm.Lognormal() method.
Under the assumptions from the PyMC3 code and this wikipedia page, if X \sim N(\mu, \sigma^2), then the random variable Z=\exp(X) has a lognormal distribution. Note that the parameters used in PyMC3 donβt correspond to \mu=E(Z) or \sigma^2=E(Z^2)-E(Z)^2. Instead, \mu=E(X) and \sigma^2=E(X^2)-E(X)^2. Does that clear things up?
1 Like
Thank you for clearing my doubt. So basically my code will be:
with pm.Model():
x = pm.Lognormal(βxβ, mu= E(X), sigma=E(X^2)βE(X)^2)
Not quite - to make it consistent with what I wrote, it would instead look like:
z = pm.Lognormal(βZβ, mu= E(X) , sigma=E(X^2)βE(X)^2)
1 Like