1
$\begingroup$

I have recently started running more complicated Bayesian models in R using the rjags package. As model complexity has increased I have had to run longer chains to reach convergence for some parameters. Generally I will try a run at 20,000 and if this does not converge, use the update function to increase the chain length.

For simple models I can save the model object, and it is small enough to share easily (<50 Mb), however I have a few models that require chains around 800,000 in length to reach convergence which result in objects >100 Mb.

Is there a function or technique to reduce the size of these objects before I save them? I am familiar with the concept of thinning when starting the model, but am interested if there is a technique to "thin" the chains post-hoc.

$\endgroup$
  • 1
    $\begingroup$ This reads like a request for R code which is typically off topic here. You may be able to rephrase this, though, to emphasize the statistical issues here. $\endgroup$ – gung - Reinstate Monica Mar 16 '16 at 14:47
  • 1
    $\begingroup$ I have looked into the coding side of things and have not found a canned answer e.g. "use this function". To me this seems like a question that splits the difference between code and stats. I am hoping that someone may have experience with a valid technique to address this, and I can then find a tool or write a function to use this technique $\endgroup$ – Daniel Bachen Mar 16 '16 at 14:55
3
$\begingroup$

Three thoughts:

  1. That many samples until convergence sounds like there are issues with your model/priors. The diagnosis would require seeing the model -- and also more knowledge than I have. Some models are just hard, sometimes you can use tricks that make them more amenable, and sometimes you have an outright error.

  2. Most MCMC samplers have a thin=n argument that says to only save every nth sample. I couldn't find it for rjags but I assume JAGS supports an option like that.

  3. You might consider switching to rstan (directly, or via rstanarm or brms). Each iteration takes longer, but in general each iteration is less-correlated and of better quality, so it's not unusual to use 3-5K iterations rather than tens-of-thousands. (In particular, Stan is better at ridge-like distributions than other samplers. As an example of someone who switched to Stan and saw a huge improvement: Managing high autocorrelation in MCMC)

    The difference between Stan and JAGS is that JAGS (like BUGS) is a language to describe a model, while Stan is more executable. For example, a JAGS for is not an actual loop, but rather a plate specification, while in Stan a for actually is a for loop.

$\endgroup$
  • $\begingroup$ (+1) thinnin is the thin(g)! $\endgroup$ – Xi'an Mar 16 '16 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.