runjags object is too big

2019-05-14 23:13发布

问题:

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?

回答1:

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...



标签: r jags runjags