0
$\begingroup$

I'm trying to construct a hierarchical model using JAGS, but I'm running into issues converting between normal/lognormal distributions and the more I stare at my problem, the more confused I get.

Some of the parameters I'm trying to estimate are a series of $M$ values - I know that $M$ is lognormally distributed. In order to estimate the mean of $M$ (the hierarchy), I want to use the normal distribution because I have prior information that the mean is likely around $0.2$.

I know that the following equations hold for when you 'switch' between inputting your values from a normal distribution (let's call it $X$) and a lognormal ($Y$, where $Y=\ln(X)$):

$\mu_Y = \ln(\mu_X) - 0.5\ln(1 + \frac{\sigma_X^2}{\mu^2_X}) = \ln (\mu_X) -0.5\sigma_Y^2$

$\sigma_Y^2 = \ln(1 + \frac{\sigma_X^2}{\mu^2_X})$

However, I'm having issues implementing these in my JAGS model code. Here's the relevant piece of code:

meanM ~ dnorm(0.2, 0.1)
precM ~ dgamma(0.001, 0.001)
varM <- 1 / precM
logvarM <- log(1 + (varM / (meanM * meanM)))
logprecM <- 1 / logvarM
logmeanM <- log(meanM) - (0.5 * logvarM)

for (k in 1:4){
  M[k] ~ dlnorm(logmeanM, logprecM)
}

I get an error from JAGS here that says that logmeanM has an invalid parent value, and when I try to debug it using OpenBUGS it says that something went wrong in procedure Ln in module Math. Am I completely wrong in my math or my code? The more I try to figure it out, the more confused about normal/lognormal I get, so apologies if that is reflected in this question.

$\endgroup$
1
$\begingroup$

meanM is apparently intended to be the mean of a lognormal random variable. The mean of a lognormal distribution cannot be negative. Therefore, you cannot put a normal prior on meanM since a normal distribution puts positive probability on negative values.

$\endgroup$
  • $\begingroup$ I thought of that, but I tried setting up something like meanM ~ dnorm(5, 10), which has little probability of having a negative value, and I still got the same error. $\endgroup$ – Peter Apr 22 '16 at 19:28
  • 1
    $\begingroup$ Even if the probability is small, it might happen once in a long simulation. Once is enough ... The message something went wrong in procedure Ln in module Math should be clear enough ... $\endgroup$ – kjetil b halvorsen Mar 16 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.