全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 winbugs及其他软件专版
1828 0
2014-06-16
I try to use WinBUGS from R via BRugs and R2WinBUGS, the code is followinig:

require(R2WinBUGS)
require(BRugs)
model<-function(){
  for(i in 1:N){
    y <- x + w
    w ~ dnorm(0, sigma.y)
    x <- a - b*5 + v
    v ~ dnorm(0, sigma.x)
  }
a ~ dunif(0, 1)
b ~ dunif(-1, 1)
sigma.y ~ dgamma(0.1, 0.1)
sigma.x ~ dgamma(0.1, 0.1)
}

write.model(model, con = "model.bug")
modelCheck("model.bug")
# model is syntactically correct

N = 10
y = rnorm(100)
data = list(N = N, y = y)
inits = function(){
  list(a = runif(1, 0, 1), b = runif(1, -1, 1), sigma.x= rgamma(1, 0.1, 0.1),
       sigma.y = rgamma(1, 0.1, 0.1))
}
parameters = c("a", "b", "sigma.x", "sigma.y")

result.sim <- bugs(data, inits, parameters, "model.bug",
                n.chains = 1, n.iter = 1000,
                program= "winbugs",
                working.directory = NULL,
                debug = T)
The result didn't come out, and I find out part of the log.txt of WinBUGS:

display(log)
check(C:/Users/ADMINI~1.PC-/AppData/Local/Temp/RtmpkrnOoc/model.bug.txt)
model is syntactically correct
data(C:/Users/ADMINI~1.PC-/AppData/Local/Temp/RtmpkrnOoc/data.txt)
data loaded
compile(1)
multiple definitions of node y[1]
inits(1,C:/Users/ADMINI~1.PC-/AppData/Local/Temp/RtmpkrnOoc/inits1.txt)
command #Bugs:inits cannot be executed (is greyed out)
gen.inits()
command #Bugs:gen.inits cannot be executed (is greyed out)
thin.updater(1)
update(500)
command #Bugs:update cannot be executed (is greyed out)
set(a)
it is obvious that the error is multiple definitions of node y[1], but what does it mean? I don't think y[1] has multiple definitions since I use y but not y in the loop.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群