2

I'm trying to run some simulations in WinBUGS using R and R2WinBUGS running in Windows 7.

After I prepare all the files a and launch the function bugs() the WinBUGS windows opens but doesn't start the simulations. The same happens with older versions of R and with OpenBUGS. Is it a problem of Windows?

Here's the code:

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)

Any help would be appreciated! Cheers Mário

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
mferreira
  • 388
  • 1
  • 8
  • I am getting a `expected right parenthesis` error as you have only one `psi` defined in the prior but then refer to `nsite` `psi`'s in the model. – guyabel Oct 14 '14 at 13:56
  • It was a mistake. But I'm not able to see that message because WinBUGS doesn't lunch the simulations – mferreira Oct 14 '14 at 14:00
  • Perhaps check if where you have BUGS installed matches the default location in the `bugs` function, i.e. `bugs.directory="c:/Program Files/WinBUGS14/"` – guyabel Oct 15 '14 at 08:13

1 Answers1

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

mferreira
  • 388
  • 1
  • 8