“多元正态Y [1,1]的均值必须与Y [1,1]的分量数相同”-WinBUGS中的错误

时间:2018-12-11 11:41:30

标签: bayesian winbugs winbugs14

如何处理这样的编译错误:“多元正态Y [1,1]的均值必须与Y [1,1]的分量数相同”?

这是我在WinBugs中的代码和数据:

model{
for (i in 1:10){
    Y[i, 1:8] ~ dmnorm(mu[,], Omega[ , ]) 

    mu[i,1]<-a[1]+a[2]*ExitsCount_Dens[i,1]+a[3]*LanesCount[i,1]

    mu[i,2]<-b[1]+b[2]*ExitsCount_Dens[i,2]+b[3]*LanesCount[i,2]

    mu[i,3]<-c[1]+c[2]*ExitsCount_Dens[i,3]+c[3]*LanesCount[i,3]

    mu[i,4]<-d[1]+d[2]*ExitsCount_Dens[i,4]+d[3]*LanesCount[i,4]

    mu[i,5]<-e[1]+e[2]*ExitsCount_Dens[i,5]+e[3]*LanesCount[i,5]

    mu[i,6]<-f[1]+f[2]*ExitsCount_Dens[i,6]+f[3]*LanesCount[i,6]

    mu[i,7]<-g[1]+g[2]*ExitsCount_Dens[i,7]+g[3]*LanesCount[i,7]

    mu[i,8]<-h[1]+h[2]*ExitsCount_Dens[i,8]+h[3]*LanesCount[i,8]
    }
    Omega[1 : 8 , 1 : 8]  ~ dwish(R[ , ], 8)
    Sigma[1 : 8 , 1 : 8] <- inverse(Omega[ , ])

#priors:
for (k in 1:3) {a[k] ~dnorm(0.0, 1.0E-5)}
for (l in 1:3) {b[l] ~dnorm(0.0, 1.0E-5)}
for (m in 1:3) {c[m] ~dnorm(0.0, 1.0E-5)}
for (n in 1:3) {d[n] ~dnorm(0.0, 1.0E-5)}
for (o in 1:3) {e[o] ~dnorm(0.0, 1.0E-5)}
for (p in 1:3) {f[p] ~dnorm(0.0, 1.0E-5)}
for (q in 1:3) {g[q] ~dnorm(0.0, 1.0E-5)}
for (r in 1:3) {h[r] ~dnorm(0.0, 1.0E-5)}
#priors:
for (t in 1:8) {R[t,t]<-1}
}

数据:

list(
Y=structure(.Data=c(
19.848,20.054,21.209,21.777,17.038,16.54,16.335,17.694,
3.742,14.1375,24.533,14.2415,3.95,27.179,28.515,29.851,
27.964,28.133,28.887,30.721,29.609,27.005,27.497,28.925,
10.829,10.515,11.213,11.82,7.935,8.323,7.102,8.034,
21.169,21.025,22.795,21.98,19.414,18.975,18.02,21.142,
28.263,27.163,19.495,23.436,29.234,30.363,28.305,23.896,
14.141,17.957,20.248,21.678,21.411,21.125,18.633,19.594,
24.485,23.817,25.554,25.251,19.599,24.184,18.141,22.705,
12.89,15.456,18.661,19.931,18.758,19.15,17.978,19.828,
14.557,15.134,25.8,20.574,12.168,38.655,14.36,7.093
),.Dim=c(10,8)),
LanesCount = structure(.Data = c(
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
5,5,5,5,5,5,5,5,
2,2,2,2,2,2,2,2,
5,5,5,5,5,5,5,5,
2,2,2,2,2,2,2,2,
5,5,5,5,5,5,5,5,
4,4,4,4,4,4,4,4,
2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3
),.Dim = c(10,8)),
ExitsCount_Dens = structure(.Data = c(
2.215,2.215,2.215,2.215,2.215,2.215,2.215,2.215,
2.703,2.703,2.703,2.703,2.703,2.703,2.703,2.703,
2.703,2.703,2.703,2.703,2.703,2.703,2.703,2.703,
2.761,2.761,2.761,2.761,2.761,2.761,2.761,2.761,
2.761,2.761,2.761,2.761,2.761,2.761,2.761,2.761,
2.747,2.747,2.747,2.747,2.747,2.747,2.747,2.747,
2.747,2.747,2.747,2.747,2.747,2.747,2.747,2.747,
4.757,4.757,4.757,4.757,4.757,4.757,4.757,4.757,
4.757,4.757,4.757,4.757,4.757,4.757,4.757,4.757,
4.757,4.757,4.757,4.757,4.757,4.757,4.757,4.757
),.Dim = c(10,8)))

#initials:
list(
a=c(1,1,1),
b=c(1,1,1),
c=c(1,1,1),
d=c(1,1,1),
e=c(1,1,1),
f=c(1,1,1),
g=c(1,1,1),
h=c(1,1,1)
)

1 个答案:

答案 0 :(得分:1)

多元正态函数dmnorm()期望平均值为 N 的向量和 NxN 协方差矩阵。当前,您正在使用mu传递mu[,]值的完整10x8矩阵,但是您只想传递mu对应于{{ 1}}次迭代,即

i