Hi all,
         I've been trying to run a model using R2winBUGS, and recurrently I
get the message:

"Error in FUN(X[[3L]], ...) :
  invalid to change the storage mode of a factor"

My model is the following:


sink("GLMM_Poisson.txt")
cat("
model{
mu~dnorm(0,0.01)
beta1~dnorm(-1,1)

for(j in 1:nsite){
  alpha[j]~dnorm(mu.alpha,tau.alpha)
}
mu.alpha~dnorm(0,0.01)
tau.alpha<-1/(sd.alpha*sd.alpha)
sd.alpha~dunif(0,5)

#Likelihood
for (i in 1:n){
  for(j in 1:nsite)
C[i,j]~dpois(lambda[i,j])
log(lambda[i,j])<-mu+beta1*HABITAT[i,j]+alpha[j]
} #J
}#i
}
",fill=TRUE)
sink()

win.data<-list(C=Veg_cover$COLONY.SIZE,n=length(Veg_cover$COLONY.SIZE),
               nsite=Veg_cover$SITE,HABITAT=Veg_cover$HABITAT)

inits<-function()list(mu=runif(1,0,4),beta1=runif(1,-1,1),alpha=runif(5,-2,2))
params<-c("mu","beta1","alpha")

ni<-6000
nt<-5
nb<-1000
nc<-3


out1<-bugs(win.data,inits,params,"GLMM_Poisson.txt",n.chains=nc,n.thin=nt,n.iter=ni,n.burnin=nb,
           debug=TRUE,bugs.directory=bugs.dir,working.directory=getwd())

and this is the data;


win.data
$C
 [1] 6 5 2 5 4 6 3 4 2 5 3 5 2 4 3 2 4 5 6 2 5 1 6 3 1 2 2 2 1 2 1 3 3 2 3
8 3 5 5 4 2 1 3

$n
[1] 43

$nsite
 [1] Sara      Sara      Sara      Sara      Sara      Sara      Sara
 Sara      Sara
[10] Sara      Sara      Sara      Cullen    Cullen    Cullen    Sara
 Sara      Sara
[19] Sara      Sara      Harberton Harberton Harberton Harberton Tristen
Tristen   Harberton
[28] Harberton Tristen   Tristen   Tristen   Harberton Harberton Harberton
Submarino Submarino
[37] Submarino Submarino Submarino Submarino Submarino Submarino Harberton
Levels: Cullen Harberton Sara Submarino Tristen

$HABITAT
 [1] Steppe Steppe Steppe Steppe Steppe Steppe Steppe Steppe Steppe Steppe
Steppe Steppe Steppe Steppe
[15] Steppe Steppe Steppe Steppe Steppe Steppe Forest Forest Forest Forest
Forest Forest Forest Forest
[29] Forest Forest Forest Forest Forest Forest Forest Forest Forest Forest
Forest Forest Forest Forest
[43] Forest
Levels: Forest Steppe


I guess this is related to the mode of my categorical variable habitat, and
although I coerced it as a factor, I keep getting the same error message
when I'm trying to link R to winBUGS.

I'm beginning to use winBUGS and any clarification will be appreciated!


Alejandro

	[[alternative HTML version deleted]]

