【问题标题】:OpenBUGS error "expected multivariate node"OpenBUGS 错误“预期的多变量节点”
【发布时间】:2014-07-21 01:07:09
【问题描述】:

我正在用 R 编写一个使用 R2OpenBUGS 的程序。代码在底部给出。运行时出现以下错误-

model is syntactically correct
data loaded
expected multivariate node
model must have been compiled but not updated to be able to change RN generator
BugsCmds:NoCompileInits
BugsCmds:NoCompileInits
BugsCmds:NoCompileInits
model must be compiled before generating initial values
model must be initialized before updating
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before DIC can be monitored
model must be initialized before updating
model must be initialized before monitors used
DIC monitor not set

请帮我改正代码-

以下是OpenBUGS代码。

## BUGS Model 
model {
# model for joint distribution of nuhat
nuhat[1:m]~dmnorm(mean[], B[,])
for(i in 1:m){
  mean[i]<-mu
}
B[1:m,1:m]<-SIGMA[1:m,1:m]+tau2*inverse(C[1:m,1:m])
C[1:m,1:m]<-DW[1:m,1:m]-rho*W[1:m,1:m]

# priors on parameters
mu~dunif(-5,5)
rho~dunif (-1,1)
tau2~dunif (0, 1000)  
} 

## Data
list(m=5, nuhat=c(-0.228352281,-0.290119586,-0.211553228,-0.252395328,-0.263358489),
SIGMA=structure(.Data=c( 1.451677,0,0,0,0,
                         0,1.578091,0,0,0,
                         0,0,1.386538,0,0,
                         0,0,0,1.484578,0,
                         0,0,0,0,1.500409),  .Dim=c(5,5)), 
DW=structure(.Data=c(2,0,0,0,0,
                     0,2,0,0,0,
                     0,0,3,0,0,
                     0,0,0,2,0,
                     0,0,0,0,1), .Dim=c(5,5)),
W=structure(.Data=c(0,1,1,0,0,
                    1,0,0,1,0,
                    1,0,0,1,1,
                    0,1,1,0,0,
                    0,0,1,0,0), .Dim=c(5,5)))

## Inits
list(mu=-1,tau2=1,rho=0.5)

【问题讨论】:

  • 也许您可以编辑您的问题以仅提供 BUGS 模型、数据(或小型玩具数据集)和初始值?输出表明您的数据格式不正确,但如果没有可重现的示例,就无法帮助您检测到哪里。
  • 很抱歉给您带来不便。给出数据的一个子集。数据的实际维度是54。

标签: winbugs r2winbugs


【解决方案1】:

OpenBUGS 不允许您像分配随机节点一样为确定性节点分配矩阵。例如(暂时忘记模型中的B、SIGMA 和DW 实际是什么)...,

B[1:m, 1:m] ~ dwish(SIGMA[,], 5)

没关系,但是

B[1:m, 1:m]  <- SIGMA[,] + DW[,]

似乎不起作用。相反,您必须创建一个循环来分配矩阵的每个元素,例如

for(i in 1:m){
  for(i in 1:m){
    B[i, j]  <- SIGMA[i, j] + DW[i, j]
  }
}

您的代码中的inverse 转换(这是B 计算的一部分)不能在元素方面进行,因此必须超出任何将值分配给确定性矩阵元素的循环。

考虑到这两个规则,如果您将模型重新表达为:

model {
# model for joint distribution of nuhat
nuhat[1:m]~dmnorm(mean[], B[,])
for(i in 1:m){
  mean[i]<-mu
}
for(i in 1:m){
  for(j in 1:m){
    B[i,j] <- SIGMA[i,j] + tau2*invC[i,j]
    C[i,j] <- DW[i,j] - rho*W[i,j]
  }
}
invC[1:m,1:m]<-inverse(C[1:m,1:m])

# priors on parameters
mu~dunif(-5,5)
rho~dunif (-1,1)
tau2~dunif (0, 1000)  
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 2014-04-25
    • 2017-02-05
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多