我正在尝试使用 R 中的“R2OpenBUGS”包运行简单的线性回归分析。当我运行“bugs”命令时,我遇到了错误。
在命令行中添加“debug = T”后,我在 OpenBUGS 中收到此错误:
预期的右括号错误 pos 130
这是我在 R 中的代码:
library(R2OpenBUGS)
library(coda)
MODEL <- function() {
for (i in 1:N) {
y[i] ~ dnorm(mu[i], s2)
mu[i] <- b0+b1*(x[i])
}
b0 ~ dnorm(0, 1/9)
b1 ~ dnorm(0, 1/9)
s2 ~ dgamma(3, 1)
s2 <- 1/s2
}
write.model (model,"MODEL.txt")
INIT <- function() {
list(b0 = runif(1,-9, 9),
b1 = runif(1,-9, 9),
s2 = rexp(1,1/3))
}
DATA=list(y=c(15,33,26,21,39,40,14,38,20,32),
x=c(3,7,6,3,9,9,2,9,5,6),N=10)
BUGS=bugs(data = DATA, inits = INIT,
parameters.to.save = c("b0", "b1", "s2"),
model.file = "MODEL.txt", n.chains = 1,
n.iter = 10000, n.burnin = 100, codaPkg=TRUE, debug = T)