JAGS bayesian MCMC but came into this: Error parsing model file: syntax error on line 5 near "="

263 Views Asked by At

when I run my jags model, I got this error message : module glm loaded Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, :

Error parsing model file: syntax error on line 5 near "="

And here is my code:

install.packages('R2jags')
install.packages('rjags')
library(rjags)
library('R2jags')
library(lattice)
binomial.model.JAGS = function(){
  y ~ dbin(p,n)
  p=lambda*mu+rho*(1-mu)
  lambda ~ dunif(min = 0.2,max = 1.4)
  mu ~ dunif(min = 0,max = 1)
  rho ~ dunif(min = 0.1,max = 1.7)
}
n = 100000
y = 30000
data.JAGS = list(y = y, n = n)

inits.JAGS = list(list(lambda=0.8,mu=0.5,rho=0.9))
para.JAGS = c("p", "lambda", "mu", "rho")
fit.JAGS = jags(
                data=data.JAGS,inits=inits.JAGS,
                parameters.to.save=para.JAGS,
                n.chains=1,
                n.iter=9000,
                n.burnin = 1000,
                model.file = binomial.model.JAGS)

I really don't know where it went wrong. Does anybody could help me please? Thank you a lot!!

1

There are 1 best solutions below

0
On

Just remove all the argument naming in your priors and you should be good to go.

binomial.model.JAGS = function(){
  y ~ dbin(p,n)
  p=lambda*mu+rho*(1-mu)
  lambda ~ dunif(0.2,1.4)
  mu ~ dunif(0,1)
  rho ~ dunif(0.1,1.7)
}
n = 100000
y = 30000
data.JAGS = list(y = y, n = n)

inits.JAGS = list(list(lambda=0.8,mu=0.5,rho=0.9))
para.JAGS = c("p", "lambda", "mu", "rho")
fit.JAGS = jags(
  data=data.JAGS,inits=inits.JAGS,
  parameters.to.save=para.JAGS,
  n.chains=1,
  n.iter=9000,
  n.burnin = 1000,
  model.file = binomial.model.JAGS)

         mu.vect sd.vect   2.5%    25%    50%    75%  97.5%
lambda     0.286   0.025  0.239  0.270  0.287  0.298  0.351
mu         0.936   0.064  0.758  0.930  0.957  0.977  0.996
p          0.300   0.001  0.297  0.299  0.300  0.301  0.303
rho        0.794   0.459  0.114  0.355  0.774  1.166  1.611
deviance  12.799   1.403 11.791 11.883 12.230 13.105 16.491

DIC info (using the rule, pD = var(deviance)/2)
pD = 1.0 and DIC = 13.8
DIC is an estimate of expected predictive error (lower deviance is better).