2

我正在使用 WinBUGS 包研究多级差异项功能模型。我已经成功构建了更简单的模型,但我也收到了错误“数组索引小于一”。如果您能提供帮助,我将非常高兴。

    # 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, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1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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)))
4

2 回答 2

1

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

于 2014-10-21T13:20:29.060 回答
1

发生了什么事x。它的长度比其他变量短,也许你错过了一个观察。

于 2014-10-13T09:11:01.633 回答