gpt4 book ai didi

r - 这个 WinBUGS 模型有什么问题

转载 作者:行者123 更新时间:2023-12-01 02:47:01 25 4
gpt4 key购买 nike

我用过 Winbugs来自 R通过 R2WinBUGSBRugs包,我写了模型,尝试运行,结果没出来,看了WinBUGS日志,似乎没有出错。
这是模型:

require(BRugs)
require(R2WinBUGS)
# MCMC mosel
model<-function(){
for(i in 1:M){
y[i] ~ dnorm(x[i], sigma.y)
}
x[1] ~ dnorm(theta[1], sigma.x)
theta[1] <- 0
for(j in 2:M){
x[j] ~ dnorm(theta[j], sigma.x)
theta[j] <- a + b*x[j-1]
}
a ~ dunif(0, 1)
b ~ dunif(-1, 1)
tau.y ~ dgamma(0.1, 0.1)
tau.x ~ dgamma(0.1, 0.1)
sigma.y <- 1/sqrt(tau.y)
sigma.x <- 1/sqrt(tau.x)
}

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

data=list(M = 90, y = rnorm(90)

inits = function(){
list(tau.x = rgamma(1, 0.1, 0.1), tau.y = rgamma(1, 0.1, 0.1), a = runif(0, 1), b = runif(-1, 1))
}
parameters=c("a", "b", "x")

ret.sim <- bugs(data, inits, parameters, "model.bug",
n.chains = 1, n.iter = 1000,
n.sims = 500,
program= "winbugs",
working.directory = NULL,
debug = T)

模型检查通过,日志 WinBUGS在这儿:
display(log)
check(C:/Users/ADMINI~1.PC-/AppData/Local/Temp/Rtmp2LfZTu/model.bug.txt)
model is syntactically correct
data(C:/Users/ADMINI~1.PC-/AppData/Local/Temp/Rtmp2LfZTu/data.txt)
data loaded
compile(1)
model compiled
inits(1,C:/Users/ADMINI~1.PC-/AppData/Local/Temp/Rtmp2LfZTu/inits1.txt)
this chain contains uninitialized variables
gen.inits()
initial values generated, model initialized
thin.updater(1)
update(500)
WinBUGS没有继续,也没有显示错误消息,所以我找不到任何错误。

最佳答案

此错误消息显然是关于初始值的。
尝试运行 runif(-1, 1)在 R 控制台上,您会看到 :-) 您的意思是 runif(1, -1, 1) (还有 runif(1, 0, 1) 用于前一个。

祝你好运!

关于r - 这个 WinBUGS 模型有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16205053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com