Unable to convert updated rjags object to mcmc object

Help
2014-04-09
2014-04-10
  • Hello,

    I recognize that this isn't a JAGS issue per se, but thought that it might be close enough that those of you watching this site would be the most helpful. My apologies if there is a better venue for this question.

    I've been working with a fairly basic model in JAGS through the jags() function in the package R2Jags. I'm generally able to convert the resulting rjags objects to mcmc objects for use with the diagnostics functions in the coda package using as.mcmc(). However, if I use the autojags() or update() functions to update the model, and then try to convert the updated model to an mcmc object, I get the following error:

    Error in data[1:nobs, , drop = FALSE] :
    only 0's may be mixed with negative subscripts

    There seems to be no problem with the updating functions, because I can use the output directly (i.e. without converting to an mcmc object) and everything is fine. As far as I can tell, the objects that jags() puts out and the objects that autojags() or update() puts out are identical, and yet the error happens always with objects resulting from autojags()/update(), and never with objects resulting from jags().

    To be fair, I haven't tried the jags.model function as an alternative to jags(), and perhaps the problem doesn't exist there. Since this question is really about the difference between the updating functions and the standard jags function interfacing with coda, I haven't included the model and code, but I could if that would be helpful.

    Versions: R 3.0.2; JAGS 3.3.0; coda 0.16-1; R2Jags 0.03-12; rjags 3-12.

    I appreciate any thoughts.
    Philip

     
    • Corey Sparks
      Corey Sparks
      2014-04-09

      I can use the coda diagnostics after fitting the model using jags.model(), then update() then coda.samples() in the rjags package

      Corey Sparks
      Assistant Professor
      Department of Demography
      College of Public Policy
      501 West Cesar E Chavez Blvd
      Monterrey Building 2.270C
      San Antonio, TX 78207
      corey.sparks 'at' utsa.eduhttp://utsa.edu/
      210 458 3166
      coreysparks.weebly.comhttp://coreysparks.weebly.com

      On Apr 9, 2014, at 4:59 PM, Philip Halteman phalteman@users.sf.net<mailto:phalteman@users.sf.net> wrote:

      Hello,

      I recognize that this isn't a JAGS issue per se, but thought that it might be close enough that those of you watching this site would be the most helpful. My apologies if there is a better venue for this question.

      I've been working with a fairly basic model in JAGS through the jags() function in the package R2Jags. I'm generally able to convert the resulting rjags objects to mcmc objects for use with the diagnostics functions in the coda package using as.mcmc(). However, if I use the autojags() or update() functions to update the model, and then try to convert the updated model to an mcmc object, I get the following error:

      Error in data[1:nobs, , drop = FALSE] :
      only 0's may be mixed with negative subscripts

      There seems to be no problem with the updating functions, because I can use the output directly (i.e. without converting to an mcmc object) and everything is fine. As far as I can tell, the objects that jags() puts out and the objects that autojags() or update() puts out are identical, and yet the error happens always with objects resulting from autojags()/update(), and never with objects resulting from jags().

      To be fair, I haven't tried the jags.model function as an alternative to jags(), and perhaps the problem doesn't exist there. Since this question is really about the difference between the updating functions and the standard jags function interfacing with coda, I haven't included the model and code, but I could if that would be helpful.

      Versions: R 3.0.2; JAGS 3.3.0; coda 0.16-1; R2Jags 0.03-12; rjags 3-12.

      I appreciate any thoughts.
      Philip


      Unable to convert updated rjags object to mcmc objecthttps://sourceforge.net/p/mcmc-jags/discussion/610037/thread/b7b35aad/?limit=25#804e


      Sent from sourceforge.nethttp://sourceforge.net because you indicated interest in https://sourceforge.net/p/mcmc-jags/discussion/610037/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       
      Attachments
  • Corey Sparks
    Corey Sparks
    2014-04-09

    I can use the coda diagnostics after fitting the model using jags.model(), then update() then coda.samples() in the rjags package. e.g.
    jags2<-jags.model(textConnection(model1), data=dat2, inits=init2, n.chains=3, n.adapt=1000)
    update(jags2, 5000)
    samps2<-coda.samples(jags2,variable.names=c("a0","b1"), 1000, thin=10)
    gelman.diag(samps2, multivariate=F)

    Potential scale reduction factors:

        Point est. Upper C.I.
    

    a0 1.000 1.012
    b1 1.002 1.019

    Cheers, Corey

     
  • Martyn Plummer
    Martyn Plummer
    2014-04-10

    This looks like a bug in the R2jags package. Try following Corey's example using the rjags package. If this works, then send a reproducible example to Yu-Sung Su, the maintainer of the R2jags package.

     
  • Thanks for the thoughts. I followed Corey's method above and it worked fine, so it seems likely that it's a bug in R2jags. I'll follow your advice, Martyn, and send an example to Yu-Sung Su.

    Thanks again,
    Philip