Winbugs 中个体变异性内具有相关性和复杂性的随机截距和斜率模型
Random intercept and slope model with correlation and complex within individual variability in Winbugs
我正在尝试在 WinBUGS 中实现具有复杂误差可变性的随机截距和斜率。我得到“预期的多元节点”。这是带有错误消息的示例代码。任何帮助将非常感激。如果需要进一步说明,请告诉我。
model {
for (i in 1:N) {
y[i,1:2] ~ dnorm(mu[i,1:2],prec[i,1:2])
mu[i,1] <- alpha[1] + beta[1]*(wave[i]-1) + b[id[i],1] + u[id[i],1]*(wave[i]-1)
mu[i,2] <- alpha[2] + beta[2]*(wave[i]-1) + b[id[i],2] + u[id[i],2]*(wave[i]-1)
prec[i,1] <- 1 / exp(delta1[1] + delta2[1] * (wave[i]-1) + b[id[i], 3])
prec[i,2] <- 1 / exp(delta1[2] + delta2[2] * (wave[i]-1) + b[id[i], 4])
}
alpha[1] ~ dnorm(0,0.000001)
alpha[2] ~ dnorm(0,0.000001)
beta[1] ~ dnorm(0,0.000001)
beta[2] ~ dnorm(0,0.000001)
delta1[1] ~ dnorm(0,0.000001)
delta1[2] ~ dnorm(0,0.000001)
delta2[1] ~ dnorm(0,0.000001)
delta2[2] ~ dnorm(0,0.000001)
for (i in 1:Nid) {
b[i,1:4] ~ dmnorm(m1[1:4], prec1[1:4,1:4])
u[i,1:2] ~ dmnorm(m2[1:2], prec2[1:2,1:2])
}
# Priors for random terms
prec1[1:4,1:4] ~ dwish(R1[1:4,1:4], 4)
sigma1[1:4,1:4] <- inverse(prec1[1:4,1:4])
R1[1,1] <- 0.00001
R1[2,2] <- 0.00001
R1[3,3] <- 0.00001
R1[4,4] <- 0.00001
R1[1,2] <- 0
R1[1,3] <- 0
R1[1,4] <- 0
R1[2,3] <- 0
R1[2,4] <- 0
R1[3,4] <- 0
S1[1:4,1:4] <- inverse(prec1[1:4,1:4])
prec2[1:2,1:2] ~ dwish(R1[1:2,1:2], 2)
sigma2[1:2,1:2] <- inverse(prec2[1:2,1:2])
R2[1,1] <- 0.0001
R2[2,2] <- 0.0001
R2[1,2] <- 0
R2[2,1] <- 0
S2[1:2,1:2] <- inverse(prec2[1:2,1:2])
}
}}
我认为问题实际上出在第一个 for()
循环的第一行:
y[i,1:2] ~ dnorm(mu[i,1:2],prec[i,1:2])
你在这里说 y
的第 i
行的前两列有一个分布。分布必须具有与值一样多的维度,因此 WinBUGS 正在此处寻找双变量节点 (~dmnorm(mu[i,1:2], prec[1:2,1:2])
)。或者,您可以将它们分开:
y[i,1] ~ dnorm(mu[i,1], prec[i,1])
y[i,2] ~ dnorm(mu[i,2], prec[i,2])
我正在尝试在 WinBUGS 中实现具有复杂误差可变性的随机截距和斜率。我得到“预期的多元节点”。这是带有错误消息的示例代码。任何帮助将非常感激。如果需要进一步说明,请告诉我。
model {
for (i in 1:N) {
y[i,1:2] ~ dnorm(mu[i,1:2],prec[i,1:2])
mu[i,1] <- alpha[1] + beta[1]*(wave[i]-1) + b[id[i],1] + u[id[i],1]*(wave[i]-1)
mu[i,2] <- alpha[2] + beta[2]*(wave[i]-1) + b[id[i],2] + u[id[i],2]*(wave[i]-1)
prec[i,1] <- 1 / exp(delta1[1] + delta2[1] * (wave[i]-1) + b[id[i], 3])
prec[i,2] <- 1 / exp(delta1[2] + delta2[2] * (wave[i]-1) + b[id[i], 4])
}
alpha[1] ~ dnorm(0,0.000001)
alpha[2] ~ dnorm(0,0.000001)
beta[1] ~ dnorm(0,0.000001)
beta[2] ~ dnorm(0,0.000001)
delta1[1] ~ dnorm(0,0.000001)
delta1[2] ~ dnorm(0,0.000001)
delta2[1] ~ dnorm(0,0.000001)
delta2[2] ~ dnorm(0,0.000001)
for (i in 1:Nid) {
b[i,1:4] ~ dmnorm(m1[1:4], prec1[1:4,1:4])
u[i,1:2] ~ dmnorm(m2[1:2], prec2[1:2,1:2])
}
# Priors for random terms
prec1[1:4,1:4] ~ dwish(R1[1:4,1:4], 4)
sigma1[1:4,1:4] <- inverse(prec1[1:4,1:4])
R1[1,1] <- 0.00001
R1[2,2] <- 0.00001
R1[3,3] <- 0.00001
R1[4,4] <- 0.00001
R1[1,2] <- 0
R1[1,3] <- 0
R1[1,4] <- 0
R1[2,3] <- 0
R1[2,4] <- 0
R1[3,4] <- 0
S1[1:4,1:4] <- inverse(prec1[1:4,1:4])
prec2[1:2,1:2] ~ dwish(R1[1:2,1:2], 2)
sigma2[1:2,1:2] <- inverse(prec2[1:2,1:2])
R2[1,1] <- 0.0001
R2[2,2] <- 0.0001
R2[1,2] <- 0
R2[2,1] <- 0
S2[1:2,1:2] <- inverse(prec2[1:2,1:2])
}
}}
我认为问题实际上出在第一个 for()
循环的第一行:
y[i,1:2] ~ dnorm(mu[i,1:2],prec[i,1:2])
你在这里说 y
的第 i
行的前两列有一个分布。分布必须具有与值一样多的维度,因此 WinBUGS 正在此处寻找双变量节点 (~dmnorm(mu[i,1:2], prec[1:2,1:2])
)。或者,您可以将它们分开:
y[i,1] ~ dnorm(mu[i,1], prec[i,1])
y[i,2] ~ dnorm(mu[i,2], prec[i,2])