My question is how would I model the same if I were to use Lognormal priors and the likelihood for the above expression? What changes will be there in the above expression?
I’m having a hard time making sense of how your model code is connected to the equation in your image. I’m not clear on what parameters are meant to correspond to c, \sigma, and v. In terms of your code, your sigma appears to be undefined. It would be helpful if you could provide more info.
If your question is specifically about a lognormal distribution, it has its own class in pymc3. I.e. pm.Lognormal() (Continuous — PyMC3 3.10.0 documentation)
The above formulation is based on this linear relationship: τf = c + σv + ε
In my code, apha is c, beta is v, sigma is sε (which is constant in my case).
For the normal distribution, mean = c + σv and variance = s^2ε
I did go through the documentation for pm.Lognormal but I couldn’t figure out how to model the same considering my problem statement.
I think if you just replace every occurrence of pm.Normal by pm.Lognormal you get what you need (but note that sd is called sigma). Or am I misunderstanding you?
If I’m understanding you correctly, yes, the above lines of code should stay the same, except you’d replace pm.Normal() with pm.Lognormal as @harcel suggested, as in:
If this still doesn’t clear things up for you, perhaps you could provide some plots of your data or some more context to help us understand what the problem is.
What would be mu_param, sig_param for alpha, beta and Y_obs considering the Lognormal equation that you wrote? The mu_param, sig_param for the Normally distributed priors, and the Likelihood have been mentioned in my question.
They are exactly the same as the arguments for all three of your pm.Normal lines. Literally, replace every instance of the word “Normal” with “Lognormal” in your code. That’s all.
Have you tried prior predictive checks? I.e.: sample from your priors and plot the models on top of the data, to see if the priors are chosen well (the one on beta has a very small sigma)?
No, I haven’t tried that. Let me post my original question so that everything is clear to you all.
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 Wikipedia relationship to obtain lambda and epsilon for pm.Lognormal() method. Initially, I used the above fitting parameters to fit a lognormal. But that didn’t work out.
I don’t have any data except the mean and sd of Normally distributed priors.
I’m afraid I’m not fully understanding you. First of all: you have no data? Then how did you obtain the lognormal parameters in your table?
As far as I know, the definitions of the mean and sd of lognormal in PyMC3 is very standard. What are your lambda and epsilon? Typically, we speak about mu and sd (or sigma, it alternatively tau) to specify a lognormal. I’m guessing your epsilon is something like an error?
When you say you don’t have data, I’m confused as to what you are after. Do you maybe have a full notebook (or script) that I can look at?
The mu and sigma of the Lognormal are very straightforward, it’s the mu and sigma of a normal in log space before exponentiation. These are equivalent ways of modelling x as being Lognormally distributed:
import pymc3 as pm
import arviz as az
with pm.Model() as manual:
x_log = pm.Normal('x_log', mu=2, sigma=0.25)
x = pm.Deterministic('x', pm.math.exp(x_log))
trace_manual = pm.sample()
print(az.summary(trace_manual))
with pm.Model() as auto:
x = pm.Lognormal('x', mu=2, sigma=0.25)
trace_auto = pm.sample()
print(az.summary(trace_auto))
I have assumed the data to be normally distributed. Assumptions are such that mu’ ± 3sd’ are within tolerable limits (physics of the problem). Thus, mu’ and sd’ are the assumed means and standard deviations for 5 different cases which are within their limits. Here, lambda and epsilon are the lognormal parameters as obtained from the below expression (Wikipedia).
I was thinking of using lambda and epsilon in pm. Lognormal for the priors which don’t seem to be the case with PyMC3. II have shared the part of the code that is necessary. I hope my question is clear now.
However, my case is just the reverse. I know mean and sd of x (let’s say 7.677 and 1.983 respectively). Now, how do I determine mu =2 and sigma = 0.25 to fit pm.Lognormal on x?