我一直在尝试运行 R 代码来使用 OpenBugs。直到昨天它运行良好,我不知道我做了什么,它开始显示一些错误。然后我决定看看一些简单的例子是否有效。所以我尝试了R2WinBUGS
vignettes中的学校示例。
文件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
编辑-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`
我应该如何删除sd
我定义的那个坐在里面.GlobalEnv
?
EDIT-3
问题解决了。sd
我从工作区中删除了对象,一切正常。