I am trying to run a Markov model in OpenBUGS to estimate the transitional probabilities. But I am geeting an error "Array index is not an integer" Here is my model code:
model{
p[1,1] ~ dnorm(0,1)
p[2,2] ~ dnorm(0,1)
p[3,3] ~ dnorm(0,1)
p[1,2] ~ dnorm(0,1)
p[2,1] ~ dnorm(0,1)
p[3,1] ~ dnorm(0,1)
p[1,3] <- 1-p[1,1]-p[1,2]
p[2,3] <- 1-p[2,1]-p[2,2]
p[3,2] <- 1-p[3,1]-p[3,3]
for(i in 1:N){
for(t in 2:T){
y[i,t]~dcat(p[y[i,t-1],])
}
}
}
And here is my data with R code:
Data=structure(.Data=c(0.1, 0.2, 0.5, 0.2, 0.2, 0.8, 0.2, 0.4, 0.3, 0.2, 0.1, 0.6, 0.1, 0.5, 0.6), .Dim=c(5,3))
N=nrow(Data)
T=ncol(Data)
y=as.matrix(Data)
#Load the data
sp.data = list(y=y, N=N, T=T)
Sp.sim0<- bugs (sp.data, inits=NULL,
parameters=c('p'),
model.file= "model2.txt",n.chains=2, DIC=TRUE,n.iter=1000, codaPkg=FALSE,debug=TRUE)
print(Sp.sim0)
attach.bugs(Sp.sim0)
Can anyone please kindly help me to solve error?