"数组索引小于1" Winbugs的错误

时间:2014-10-12 11:33:07

标签: arrays arraylist indexoutofboundsexception winbugs14

我正在使用WinBUGS包处理多级差异项功能模型。我已经成功构建了更简单的模型,但我也得到了错误"数组索引小于1"。如果你能提供帮助,我会非常高兴。

    # Model
    Model
    {
    for (l in 1:50){
    y[l] ~ dbern(p[l])
    logit(p[l])<- u2[stu[l]] - beta[x[l]] + gamma[tea[l], x[l]]*grp[l] + alpha1[x[l]]*geo[l] +
    alpha2[x[l]]*conf[l] + alpha3[x[l]]*ses[l]
    }
    for (t in 1:10){
    for (i in 1:10){
    gamma[t,i] ~ dnorm(gamma.hat[t,i], tau.gamma[i])
    gamma.hat[t,i]<-pi1[i] + pi2[i]*inq[t]
    }
    }
    # fixed effect prior
    for (i in 1:10){
    beta[i] ~ dnorm(0, .0001)
    alpha1[i] ~ dnorm(0, .0001)
    alpha2[i] ~ dnorm(0, .0001)
    alpha3[i] ~ dnorm(0, .0001)
    pi1[i] ~ dnorm(0, .0001)
    pi2[i] ~ dnorm(0, .0001)
    }
    # Random effect prior
    for (s in 1:5){
    u2[s] ~ dnorm(0,tau.u2)
    }
    tau.u2 <- pow(sigma.u2, -2)
    sigma.u2 ~ dunif (0, 100)
    for (i in 1:10){
    tau.gamma[i] <- pow(sigma.gamma[i],-2)
    sigma.gamma[i] ~ dunif(0,100)
    }
    }

   # Data
   list(y=c(0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0), ses=c(0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1), conf=c(1, 0,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0, 0),    alpha2=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),  alpha3=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), sigma.gamma=(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), u2=c(0, 0, 0, 0, 0), pi0=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), pi1=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), sigma.u2=1, gamma=structure(
.Data=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim=c(10, 10)))

2 个答案:

答案 0 :(得分:1)

x正在发生的事情。它的长度比其他变量短,也许你错过了观察。

答案 1 :(得分:1)

索引从BUGS中的1开始,而不是0。变量stutea用于索引,但它们取值0,1 - 它们应该是1,2。