我一直在試圖運行R代碼來使用OpenBugs。它一直工作到昨天,我不知道我做了什麼,它開始顯示一些錯誤。然後我決定看看一些簡單的例子是否適用。所以我嘗試了R2WinBUGS
vignettes中的學校示例。在R中調用OpenBUGS不起作用
文件schools.txt的模型是
sink("schools.txt")
cat("
model {
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)
}",fill=TRUE)
sink()
用於運行程序的其餘部分的代碼如下:
data(schools)
J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list ("J", "y", "sigma.y")
inits <- function()
{
list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100),sigma.theta = runif(1, 0, 100))
}
schools.sim <- bugs(data, inits, model.file = "schools.txt",parameters = c("theta", "mu.theta", "sigma.theta"),n.chains = 3, n.iter = 1000)
不幸的是,我收到了同樣的錯誤之前。
> schools.sim <- bugs(data, inits, model.file = "schools.txt",parameters = c("theta", "mu.theta", "sigma.theta"),n.chains = 3, n.iter = 1000)
Error in sd(as.vector(ai)) : unused argument(s) (as.vector(ai))
我也曾嘗試指定program=c('OpenBugs')
但是,讓我給另一個奇怪的錯誤OpenBugs是路徑
Error in bugs(data, inits, model.file = "schools.txt", parameters = c("theta", :
unused argument(s) (program = c("OpenBugs"))
編輯
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] abind_1.4-0 rjags_3-9 R2WinBUGS_2.1-18 BRugs_0.8-0 R2OpenBUGS_3.2-2.1
[6] LearnBayes_2.12 coda_0.16-1 lattice_0.20-10
loaded via a namespace (and not attached):
[1] boot_1.3-7 grid_2.15.2 plyr_1.8 stringr_0.6.2 tools_2.15.2
traceback()
給出。 ..
> traceback()
No traceback available
EDIT 2
> getAnywhere("sd")
2 differing objects matching ‘sd’ were found
in the following places
.GlobalEnv
package:stats
namespace:stats
Use [] to view one of them`
我應該如何刪除我定義和坐在.GlobalEnv
的sd
?
EDIT-3
問題解決了。我從工作區刪除了對象sd
,並且一切正常。
您是否嘗試關閉當前R對話開放乾淨的新的會話?確保你不只是重新加載你的舊會話。 –
是的,我試過但結果相同! 'sessionInfo()'的結果是 –
? '回溯()'? –