A quetion

[This article was first published on Shige's Research Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I posted a question to the R-Mixed-Model mailing list but have not had any responses yet:
—————————————————————————————
Dear All,

I wonder if anybody has tried to make glmmBUGS work with JAGS. My
attempt was not successful.

Here is the simple example I copied from the glmmBUGS Vignettes:

------------------------
library(MASS)
data(bacteria)

bacterianew <- bacteria
bacterianew$yInt = as.integer(bacterianew$y == "y")

levels(bacterianew$trt) <- c("placebo", "drug", "drugplus")

library(glmmBUGS)

bacrag <- glmmBUGS(formula = yInt ~ trt + week, data=bacterianew,
effects = "ID",
                   modelFile="model.bug", family="bernoulli")

names(bacrag$ragged)

source("getInits.R")

startingValues = bacrag$startingValues
------------------------

With WinBUGS, it runs well:

------------------------
library(R2WinBUGS)

bacResult1 = bugs(bacrag$ragged, getInits, model.file="model.bug", n.chain=3,
  n.iter=2000, n.burnin=100, parameters=names(getInits()), n.thin=10)
------------------------

But with JAGS, I got error message "Error in FUN(50L[[1L]], ...) :
invalid first argument"

------------------------
library(R2jags)

jags.parms=names(getInits())

bacResult = jags(data=bacrag$ragged, n.chain=3, n.iter=2000,
model.file=model.bug)
------------------------

I hope somebody can help me figuring out how to make this work. Many thanks.

Best,
Shige
---------------------------------------------------------------------------------------

Here is the answer from Jens Åströ
---------------------------------------------------------------------------------------
Hi!

Not an expert by any means, but I got it to run by doing this:

1) change inprod2 to inprod in the model file (JAGS does not have
inprod2 function)

2) change ~dflat() to other uninformative prior, e.g.
~dnorm(0.0,1.0E-6) (Jags does not have dflat distribution)

3) specify/compile the model with e.g.
bac.jags<-jags.model("model.bug",data=bacrag$ragged,n.chains=4)

4) update it, update(bac.jags,1000)

5) Collect coda samples,
bacResult<-coda.samples(temp,names(getInits()),n.iter=10000,thin=10)

This seemed to converge well, (gelman.diag(bacResult))

Good luck
----------------------------------------------------------------------------------------

It works.

To leave a comment for the author, please follow the link and comment on their blog: Shige's Research Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)