各位朋友:
我采用R中的JAGS包重要一本书的数据分析(用WINGBUGS进行分析没有问题),但提示“Index out of range taking subset of y”,请高手指正。
代码如下:
set.seed(123)
library(R2jags)
cat("model{
for (i in 1:r){
for(j in n+1:n[i+1])
{
y[j,1:mminus1+1] ~ dmulti(p[j,], ni[j])
p[j,1] <- Q[j,1]
for (k in 2:mminus1) {
p[j,k] <- Q[j,k] - Q[j,k-1] }
p[j,mminus1+1]<- 1 - Q[j,mminus1]
for (k in 1:mminus1) {
logit(Q[j,k]) <- a[i,k] + gamma1*x[j] }
}
gamma1 ~ dnorm(beta1, t)
a[i,1] ~ dnorm(0,1.0E-4)I(, a[i,2])
a[i,2] ~ dnorm(0,1.0E-4)I(a[i,1], a[i,3])
a[i,3] ~ dnorm(0,1.0E-4)I(a[i,2], a[i,4])
a[i,4] ~ dnorm(0,1.0E-4)I(a[i,3], ) }
beta1 ~ dnorm(0,1.0E-4)
t ~ dgamma(0.001,0.001)
tau.sq <- 1/t
}",file="ordermodel.txt")
##data
data=list(r=5,mminus1 = 4, n = c(0,2,4,6,8,10),
x=c(1,0,1,0,1,0,1,0,1,0),
y=structure(.Data=c(4,2,14,1,13,7,21,8,3,2,
23,22,119,22,20,16,106,24,14,13,
45,54,180,35,24,17,175,73,19,18,
22,29,54,11,10,10,62,52,3,7,
2,3,6,3,1,3,17,10,0,1),.Dim=c(10,5)),
ni=c(96,110,373,72,68,53,381,170,39,41))
#fitting model
paras=c("beta1","tau.sq")
res=jags(data=data,inits=NULL,paras,model.file = "ordermodel.txt")
summary(res)
##结果
module glm loaded
Compiling model graph
Resolving undeclared variables
Deleting model
Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, :
RUNTIME ERROR:
Compilation error on line 6.
Index out of range taking subset of y
查了半天,知道哪里的问题,请各位高手指点一下,多谢!