Menu

Truncated normal prior?

Help
KTM
2014-06-05
2019-09-03
  • KTM

    KTM - 2014-06-05

    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?

    Thanks!

    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 - 2014-06-05

    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)
    
     
    • Tanja Proctor

      Tanja Proctor - 2019-09-03

      Hello Martyn,
      I am having the same problem as KTM. But putting the semicolon in, does not work for me. Unfortunately the same error is produced. I wondered if I could put it as this:
      alpha ~ dnorm(0, 0.001)*T(0,1)
      This seems to work but I am not sure if it still means the same.

       
  • KTM

    KTM - 2014-06-05

    Thank you so much!

     

Log in to post a comment.