我的 mac 系统是 OS X El Capitan 10.11.6。我使用 Winebottler(1.8.6 版)和 Wine 安装了 OpenBUG。
当我尝试使用 R 调用 OpenBUGS 时,出现以下错误:
sh: /opt/local/bin/winepath: No such file or directory
Error in system(paste(WINEPATH, "-w", x), intern = TRUE) : error in running command
这是我的 R 代码:#Load the OpenBUGS Package - 确保 XQuartz 正在运行库(R2OpenBUGS)
#schools data in the R2OpenBUGS library
data(schools)
#define the model
nummodel <- function(){
for (j in 1:J){
y[j] ~ dnorm (theta[j], tau.y[j])
theta[j] ~ dnorm (mu.theta, tau.theta)
tau.y[j] <- pow(sigma.y[j], -2)}
mu.theta ~ dnorm (0.0, 1.0E-6)
tau.theta <- pow(sigma.theta, -2)
sigma.theta ~ dunif (0, 1000)
}
# write the model code out to a file
write.model(nummodel, "nummodel.txt")
model.file1 = paste(getwd(),"nummodel.txt", sep="/")
## and let's take a look:
file.show("nummodel.txt")
#prepare the data for input into OpenBUGS
J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list ("J", "y", "sigma.y")
#initialization of variables
inits <- function(){
list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100),sigma.theta = runif(1, 0, 100))}
#set the WINE working directory and the directory to OpenBUGS - change the OpenBUGS.exe location as necessary
WINE="/opt/local/bin/wine"
WINEPATH="/opt/local/bin/winepath"
OpenBUGS.pgm="/Users/[username]/.wine/drive_c/Program Files/OpenBUGS/OpenBUGS323/OpenBUGS.exe"
#these are the parameters to save
parameters = c("theta", "mu.theta", "sigma.theta")
#run the model
schools.sim <- bugs(data, inits, model.file = model.file1,parameters=parameters,n.chains = 3, n.iter = 1000, OpenBUGS.pgm=OpenBUGS.pgm, WINE=WINE, WINEPATH=WINEPATH,useWINE=T)
#R will pause. When model is complete a prompt will reappear
print(schools.sim)
我认为问题可能在于我如何指定 Wine 和 winepath 工作目录。
有人可以给我一些建议吗?