lundi 10 avril 2017

JAGS compilation error in variable

I'm trying to reproduce a code for generate a Normal sample using the Poisson trick with Rjags in Rstudio. I'm starting now with JAGS.

g_Normal<-function(){
    for (i in 1:7) {
      zeros[i] ~ dpois(phi[i])         
      phi[i] <- log(sigma) + 0.5 * pow((x[i] - mu) / sigma, 2)       
    }
  }

x<-c(-1, -0.3, 0.1, 0.2, 0.7, 1.2, 1.7)
sim.dat <- data.frame(x)
mod.inits<-function(){
  list("mu"=0 , "sigma"= 1)
}

mod.params <- c("mu","sigma")

random_Normal <- jags(data = sim.dat, inits = mod.inits,
                      parameters.to.save = mod.params, n.chains = 3, n.iter = 9000,
                      n.burnin = 1000, model.file = g_Normal)

When I tried to run the code I get the following error

Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains,  : 
  RUNTIME ERROR:
Compilation error on line 5.
Unknown variable sigma
Either supply values for this variable with the data
or define it  on the left hand side of a relation.

I don't know how I should define sigma, I'm just trying to follow a example that found here http://ift.tt/2o1whaR




Aucun commentaire:

Enregistrer un commentaire