3

I am trying to run JAGS using a new package runjags, because R2jags has a bug (the full model code is in the question https://stats.stackexchange.com/q/62006/5509):

require("runjags")
out <- run.jags("Poisson.OD.t.test.txt", params, win.data, nc, inits,
      nb*4/5, ni, nb*1/5)
plot(out2, layout = c(4, 2))

It works as a charm, but the drawbacks of this package is that the runjags object returned by the run.jags function is already bundled with prepared charts and outputs and is too big. Just for comparison, the sizes of corresponding .Rdata files (2 chains, each of 500 saved iterations, 1000 iterations in total):

  • runjags object - 1.2 MB
  • R2jags object - 212 kB
  • mcmc.list object - 33 kB

The runjags object is enormous, but I have to store it to be able to use runjags interface on the model later.

Any workaround for this issue?

Community
  • 1
  • 1
Tomas
  • 57,621
  • 49
  • 238
  • 373
  • you could hack the `runjags` object to set some of the bigger elements to `NULL` or `NA` before saving it, or you could hack R2jags to try to resolve the issue that's bothering you ... – Ben Bolker Feb 17 '14 at 20:27
  • @BenBolker :-) exactly that is the conclusion I made :-) I am just trying to figure out if there is some easier and cleaner way :-) Unfortunatelly I don't know of similar package without such quite major issues (major at least for me...). – Tomas Feb 17 '14 at 21:17

1 Answers1

4

Objects of class runjags are pretty big, mostly because they store all the information (model/data/RNG states) required to continue a simulation where they left off. If all you want is the MCMC chains then you can get rid of most of this using:

as.mcmc.list(yourrunjagsobject)

...or to convert to something you can use with the rjags package directly:

as.jags(yourrunjagsobject)

See also ?runjagsclass

Or, if you have print/summary related storage problems and want to retain the model/data/RNG state, try summarise=FALSE and plot=FALSE to run.jags(), which will prevent pre-generation/storage of these during the initial function call.

You could also hack the class object to get rid of big components I guess, but much better to use the conversion methods provided...

ckpepper02
  • 3,297
  • 5
  • 29
  • 43
Matt Denwood
  • 2,537
  • 1
  • 12
  • 16
  • Thank you, great! I tried to set `summarise` and `plot` to `FALSE` and the object is 211kB, even smaller than R2jags'! I can even call `extend.jags` on this object. However, what if I want summaries and plots now? I would like to call something like `runjags.summaries` as you do at the end of `extend.jags` function, but this function seems to be private. And how to generate plots? This is what I meant in my design question - it would be great if you could provide an interface for the user to generate these things ex post, even using the lightweight variant of the runjags object. – Tomas Feb 18 '14 at 21:38
  • I have discovered a simple dirty trick how to get plots and summaries out of the `runjags` object without them - just add two new samples with `extend.jags(out, sample = 2)` and **plots and summaries will be generated!** :-) But for slightly different model though. This is certainly just a dirty hack - clean solution which I ask for in the previous comment would be great! – Tomas Feb 18 '14 at 21:42
  • You can use extend.jags(out, sample=0) to add (or remove for that matter) summary statistics and/or plots to an existing runjags object. This won't call JAGS, so your actual MCMC samples won't be changed (unless you also specify drop.monitors or drop.chains). I guess I could add a more obviously named function wrapper for this, but it wouldn't really be any less of a hack - it would just look better for end users! Note however that everything runjags calculates can be done manually using functions provided by the coda package - and with finer control (particularly plots). – Matt Denwood Feb 28 '14 at 20:16