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.
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?