runjags object is too big

夙愿已清 提交于 2019-12-07 17:55:40

问题


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



来源:https://stackoverflow.com/questions/21837221/runjags-object-is-too-big

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!