4
$\begingroup$

I have run into an error associated with truncating a distribution in JAGS.

In my minimum reproducible example, I have data for 9 observations and would like to find a posterior predictive distribution for the 10th observation. To do this, I include the 10th observation as an NA and estimate its posterior predictive distribution as the variable pi10.

jagsdata <- data.frame(Y = c(47, 126, 68, 43, 67, 80, 61, 9, 26, NA))

model.string <- "
model{
 for (k in 1:10){
    Y[k]  ~ dlnorm(Z[k], tau.sp[k])
    tau.sp[k] ~ dgamma(0.01,0.01)
    Z[k] <- beta.o + beta.sp[k]
 }
  for (g in 1:10) {
    beta.sp[g] ~ dnorm(0, 0.0001)
  }
  beta.o    ~ dgamma (2, 0.04)
  pi10   <- Y[10]
}
"
writeLines(model.string, con = 'jagstest.bug')

library(rjags)
j.model  <- jags.model(file = "jagstest.bug", 
                       data = jagsdata, 
                       n.adapt = 500, 
                       n.chains = 4)
mcmc.object <- coda.samples(model = j.model,
                            variable.names = c('pi10'),
                            n.iter = 5000)

This works, but I would like to truncated the distribution of Y, for example by using the T(1,200). However replacing line 4 above with

    Y[k]  ~ dlnorm(Z[k], tau.sp[k])T(1,200)

gives the error:

Unobserved node inconsistent with unobserved parents at initialization

Although Y with a normal distribution does not give an error.

    Y[k]  ~ dnorm(Z[k], tau.sp[k])T(1,200)

I have read through the JAGS manual section 7 and some examples online, but it is not clear to me how to implement this or why I am getting this error.

Suggestions appreciated.

$\endgroup$
3
  • $\begingroup$ I believe it is due to the way you sample $Z[k]$. $\endgroup$
    – teucer
    Commented Nov 12, 2011 at 0:26
  • $\begingroup$ @teucer can you be more specific? Am I making an error in model specification? $\endgroup$ Commented Nov 14, 2011 at 19:04
  • $\begingroup$ @jbowman Any chance you have a literature source you reference for posterior pruning? I have a similar problem as that presented here and I used the solution you suggested (thank you!) but I would really like to read up more about it and provide a justification with a reference in my write up. Thank you for your time and assistance. "You can avoid this problem altogether by sampling from the untruncated distribution of Y[k], then (in R) discarding all samples for which Y[k] doesn't lie within the constraint bounds. This is a perfectly valid operation, however, if you have few posterior observa $\endgroup$ Commented Jul 1, 2021 at 23:05

1 Answer 1

4
$\begingroup$

You can avoid this problem altogether by sampling from the untruncated distribution of Y[k], then (in R) discarding all samples for which Y[k] doesn't lie within the constraint bounds. This is a perfectly valid operation, however, if you have few posterior observations in the feasible region, you'll naturally have a large simulation error associated with your posterior distribution(s).

As a side note, you might want to avoid the Gamma(0.01,0.01) prior on the variance; see for example this presentation by Andrew Gelman and this paper, also by Gelman, for reasons why and alternative suggestions.

$\endgroup$
3
  • $\begingroup$ Hi jbowman ; do you happen to remember which paper your second link refers to (as its now dead) - long shot I know, but thanks $\endgroup$ Commented Jun 13, 2018 at 14:44
  • 1
    $\begingroup$ Oh, sure, let me dig it up and post the name as well as the link. $\endgroup$
    – jbowman
    Commented Jun 13, 2018 at 14:44
  • 1
    $\begingroup$ stat.columbia.edu/~gelman/research/published/taumain.pdf, "Prior distributions for variance parameters in hierarchical models" in Bayesian Analysis (2006) 1, No. 3, p. 515-533. $\endgroup$
    – jbowman
    Commented Jun 13, 2018 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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