Hello,

I am running a GLMM using R2Bugs, but am getting the below error message.  I am including the entire output, although the 2nd and 3rd lines seem to indicate the problem.  Note that I do define N (it is an integer) and send it to a datalist (see the R commands and model below).  Interestingly, when I put all of this into OpenBugs directly, the model runs.  I do have reasons, however, that I would like to do this through R.

model is syntactically correct
expected variable name error pos 341553 (error on line 1)
variable N is not defined
Initializing chain 1: model must be compiled before initial values loaded
Initializing chain 2: model must be compiled before initial values loaded
Initializing chain 3: model must be compiled before initial values loaded
model must be compiled before generating initial values
Sampling has been started...
model must be initialized before updating
model must be initialized before DIC an be monitored
Error in BRugs::samplesSet(parametersToSave) :
  model must be initialized before monitors used

Thanks for your help!
John

R commands

 datalist<-list("r", "N","n","Lev", "Light", "Soil1", "Soil2", "Soil3", "Consp", "Plot", "DConsp", 
                "Spp", "n.plot", "n.sp")

 bugs.data(datalist)

 parmlist<-c("b.lev", "b.light", "b.con", "b.dcon", "b.s1", "b.s2", "b.s3", "sigma.ind", "sigma.plt", "sigma.sp", "sigma.sppl")
 
 initlist<-list(list(b.lev=0.01, b.light=0.01, b.con=0.01, b.s1=0.01, b.s2=0.01, b.s3=0.01, b.dcon=0.01, tau.ind=rep(0,N), 
                tau.plt=rep(0,n.plot), tau.sp=rep(0,n.sp), tau=array(0, c(n.sp, n.plot))),
                list(b.lev=0.01, b.light=0.01, b.con=0.01, b.s1=0.01, b.s2=0.01, b.s3=0.01, b.dcon=0.01, tau.ind=rep(0,N), 
                tau.plt=rep(0,n.plot), tau.sp=rep(0,n.sp), tau=array(0, c(n.sp, n.plot))),
                list(b.lev=0.01, b.light=0.01, b.con=0.01, b.s1=0.01, b.s2=0.01, b.s3=0.01, b.dcon=0.01, tau.ind=rep(0,N), 
                tau.plt=rep(0,n.plot), tau.sp=rep(0,n.sp), tau=array(0, c(n.sp, n.plot))))
 
 modfile<-("GLMM Model.txt")
 GLMMcom1<-bugs(data=datalist, inits=initlist, parameters=parmlist, model.file=modfile,
                n.chains=3, n.iter=2000, DIC=TRUE, n.burnin=500,
                bugs.directory="/Program Files/OpenBUGS", program="openbugs", debug=TRUE)
 


model {      

     for (i in 1:N){  # No. of sect x dist plots
      
     r[i]~dbin(p[i], n[i])
      eps.ind[i]~dnorm(0, tau.ind)
      logit(p[i]) <- b.lev*Lev[i] + b.light*Light[i] + b.con*Consp[i] + b.dcon*DConsp[i] + 
                     b.s1*Soil1[i]  + b.s2*Soil2[i]  + b.s3*Soil3[i]  + 
                     eps.sp[Sp[i]] + eps.plt[Plot[i]] + eps[Sp[i], Plot[i]]  + eps.ind[i]
      }

     for(k in 1:n.sp){for(s in 1:n.plot){eps[k, s] ~ dnorm(0.0,tau)}}
     for(s in 1:n.plot){eps.plt[s] ~ dnorm(0.0, tau.plt)}
     for(k in 1:n.sp){eps.sp[k] ~ dnorm(0.0, tau.sp)}
  

     b.lev~dnorm(0, 0.01)                 
     b.light~dnorm(0, 0.01)
     b.con~dnorm(0,0.01)
     b.s1~dnorm(0, 0.01)
     b.s2~dnorm(0, 0.01)
     b.s3~dnorm(0, 0.01)
     b.dcon~dnorm(0, 0.01)
 
  tau.ind~dunif(0,100)
  sigma.ind<-1/sqrt(tau.ind)
  tau.plt ~ dunif(0,100)
  sigma.plt<-1/sqrt(tau.plt)
  tau.sp ~ dunif(0,100)
  sigma.sp<-1/sqrt(tau.sp)
  tau ~ dunif(0,100)
  sigma.sppl<-1/sqrt(tau)     #sd of species x plot random effect
       }






-----------------------------------------
John Poulsen, PhD
Assistant Scientist
Woods Hole Research Center
149 Woods Hole Road
Falmouth, MA 02540-1644 USA

Tel: 508.540.9900 x168
www.whrc.org






	[[alternative HTML version deleted]]

