2

我正在尝试使用在 Windows 7 中运行的 R 和 R2WinBUGS 在 WinBUGS 中运行一些模拟。

在我准备好所有文件 a 并启动函数 bugs() 后,WinBUGS 窗口会打开,但不会启动模拟。旧版本的 R 和 OpenBUGS 也会发生同样的情况。是Windows的问题吗?

这是代码:

N <- 1000 #Number of simulations

S <- 100 #Number of sites

Phi <- .4 # Occupancy probability

Occ <- array(NA, dim=c(N, S))

for (n in 1:N){
    Occ[n,] <- rbinom(S, 1, Phi)
}

# Model
sink("W.txt") 
cat("
model {
# priors
psi ~ dunif(0, 5)

#Model
for (i in 1:nsite) {

    #Ocupation model
    Z[i] ~ dbern(psi)
}

}# end of model
",fill = TRUE)
sink()

library(R2WinBUGS)

# MCMC settings
ni <- 1000
nt <- 5
nb <- 500
nc <- 5

# Parameters monitored
params <- c("psi")

#Bundle data
data <- list(Z=Occ[1,])

#Initial values
inits <- function(){list(psi =runif(1, 0, 5))}

#Lunch WinBUGS
Bugs <- bugs(data, inits, params, "W.txt", n.chains = nc, n.thin = nt, n.iter = ni, n.burnin = nb, debug=T, working.directory = getwd(), save.history=T)

print(Bugs, dig=3)

任何帮助,将不胜感激!干杯马里奥

4

1 回答 1

0

I've already found whats was causing the error.

My working directory was:

"E:\\Sim's"

It seems that WinBUGS doesn't work with addresses with apostrophe. I have changed it to:

"E:\\Sims"

And it worked perfectly.

Thanks.

Cheers! Mário

于 2014-10-15T10:39:51.670 回答