Truncated normal prior?

  • Hello,

    For some reason I can't seem to define a truncated normal prior in JAGS. Apologies if this is a stupid question, but can anyone spot my mistake?


    Simple example with a Poisson GLM. Whether I use T(,) or I(,) I get the same error when trying to define the model function:

    Error: unexpected symbol in:
    alpha ~ dnorm(0,0.001) T"

    model = function() { 
      for(t in 1:T) {
        y1[t] ~ dpois(mu[t])  
        log(mu[t]) <- alpha + beta*x1[t] 
      alpha  ~ dnorm(0,0.001) T(0,1)
      beta  ~ dnorm(0,0.001)
    T = length(x1)
    data = list("y1","x1","T")  
    params = c("alpha","beta","mu") 
    model.example = jags(data=data,param=params,n.chains=2,n.iter=1000,n.burnin=500,model.file=model)
  • Martyn Plummer
    Martyn Plummer

    This is due to a subtle difference between the BUGS and R languages.

    I always put my model description in a separate file. You are representing it in the R language, but the line with the truncated normal is not a valid R expression. You can fool the R interpreter by inserting a semicolon like so

    alpha ~ dnorm(0, 0.001);T(0,1)
  • Thank you so much!