首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenBUGS误差“期望多元节点”

OpenBUGS误差“期望多元节点”
EN

Stack Overflow用户
提问于 2014-05-31 10:05:40
回答 1查看 2.6K关注 0票数 1

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

代码语言:javascript
复制
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代码。

代码语言:javascript
复制
## 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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-02 08:25:04

OpenBUGS不允许为确定性节点分配矩阵,就像为随机节点分配矩阵一样。例如(暂时忘了模型中的BSIGMADW实际上是什么),

代码语言:javascript
复制
B[1:m, 1:m] ~ dwish(SIGMA[,], 5)

很好,但是

代码语言:javascript
复制
B[1:m, 1:m]  <- SIGMA[,] + DW[,]

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

代码语言:javascript
复制
for(i in 1:m){
  for(i in 1:m){
    B[i, j]  <- SIGMA[i, j] + DW[i, j]
  }
}

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

考虑到这两条规则,如果您重新表示为:

代码语言:javascript
复制
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)  
} 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23968710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档