7

I'm trying to fit a hierarchical model with rjags for the first time; it looks pretty simple on paper, but I'm getting an "Error parsing model file: syntax error on line 5 near "[" " that I'm totally not able to interpret.

Can you help me and tell me what I'm doing wrong?

data = list('P.hat'=c(0.0032, 0.0045, 0.077), 'R'=c(34580, 37932, 46724), 'N'=c(10028321, 15674923, 21426662), 's.over.rootn'=c(0.02, 0.006, 0.017), 'n'=1, 'tmax'=3)

cat('model{
## likelihoods ##
for(i in 1:n){
    for(j in 1:tmax){
        P.hat[i,j]  ~  dnorm(pi[j], (1/pow(s.over.rootn,2))[j])   
        R[i,j]      ~  dbin(theta[j], N[j])
}}
## daterministic relations ##
        gam         <- m*vs+(1-m)*va
for(j in 1:tmax){   
        theta[j]    <- (pi[j]*beta*gam)/(gam*dt+(1-gam)*du)
}
## priors ##
for(j in 1:tmax){
        pi[j]       ~  dbeta(1, 1)
}
        beta        ~  dbeta(1, 1)
        m           ~  dbeta(1, 1)                   
        vs          ~  dbeta(1, 1)                   
        va          ~  dbeta(1, 1)                   
        dt          ~  dnorm(0.3, 2)I(0,5) 
        du          ~  dnorm(1.25, 2)I(0,5)
}',
        file='model1.bug')

## data & initial values
inits1 <- list('pi'=rep(0.5,data$tmax),'beta'=0.5,   'm'=0.5,'vs'=0.5,'va'=0.5,'dt'=1,'du'=1)
jags_mod <- jags.model('model1.bug', data=data, inits=inits1, n.chains=1, n.adapt=5000)}

1 Answers1

2

Your fifth line of code is this:

 P.hat[i,j]  ~  dnorm(pi[j], (1/pow(s.over.rootn,2))[j])   

I believe that it needs to be changed to this in order to properly index s.over.rootn:

 P.hat[i,j]  ~  dnorm(pi[j], (1/pow(s.over.rootn[j],2)))   
mfidino
  • 3,030
  • 1
  • 9
  • 13