I am trying to build a log Normal model. Below is an example of the code that I am working on -
a = pm.Normal("a", mu = 10, sd = 1)
b1= pm.Normal("b1", mu = 2, sd = 1)
b2= pm.Normal("b2", mu = 2, sd = 1)
sd = pm.Exponential("sd", 0.5)
y_obs = pm.Lognormal("obs", mu=mu, sigma=sd, observed=df.value)
Since, a,b1,b2 are on the log scale, and I am using pm.LogNormal, the “obs” values in the posterior samples are on the normal scale(not log). But ‘contrib’ is on a log scale in the posterior samples. Is there a way, I can have ‘contrib’ values too on the normal scale(not Log)?
You can exponentiate the values inside the Deterministic with
pm.math.exp if I understand you correctly.
Am I supposed to do an adjustment of pm.math.exp(σ2/2) because here I am trying to exponentiate something which is on a log scale? Please refer to this link where it talks about getting y from log y?
It depends what you want. In the linked post, they are talking about computing the expected value of Y, given the model. In that case the closed form solution comes from the mean of the log-normal distribution. Since you have samples, you can skip the theory and just compute it as the mean of your samples.
On the other hand, if you just want to know the value of
contrib in levels, you can just exp it. The expected value of
exp(contrib) should be different from the expected value of
y_obs due to Jensen’s Inequality, which you could verify by comparison.