Pergunta

I have been trying to run a R code to use OpenBugs. It was working well till yesterday and I do not know what I did that it started showing some error. Then I decided to see if some simple example works well. So I tried the schools example present in R2WinBUGS vignettes.

The model in file schools.txt is

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()

The code for running the rest of the program is as follows:

    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) 

Unfortunately, I am getting the same error as before.

 > 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))

I have also tried specifying program=c('OpenBugs') But that gives me another weird error given that OpenBugs is in the path

     Error in bugs(data, inits, model.file = "schools.txt", parameters = c("theta",  : 
  unused argument(s) (program = c("OpenBugs"))

EDIT

> 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() gives...

> 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` 

How should I remove the sd that I defined and that is sitting in .GlobalEnv?

EDIT-3

Problem solved. I removed the object sd from the workspace and everything worked.

Foi útil?

Solução

I think you've somehow gotten a weird version of sd defined. What are the results of getAnywhere("sd")$where? It should be "package:stats" "namespace:stats". If you did attach(schools) I can see that would create another object named sd in your workspace, but that shouldn't cause problems because it's not a function.

Solution: rm(sd) or rm("sd") (the latter is probably better)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top