Convergence

A common problem when using MCMC is lacking convergence between chains. This will show up as large rhat values (> 1.1 is a common criterion) and non-converging lines in plot_pars(fit).

  • The first thing to try is always to make the model warm up longer to see if it reaches convergence later: mcp(fit, data, adapt = 10000).

  • It can be a sign of a deeper non-identifiability in the model. This will show up as strong correlations in the joint distribution of any pair of implicated parameters: plot_pars(fit, pars = c("int_1", "int_2), type = "hex"). This may give you ideas how to change the model.

  • You can set the initial values for the JAGS sampler using, e.g., mcp(..., inits = list(cp_1 = 20, int_2 = -20, etc.)). This will be passed to jags.fit and you can see more documentation there.

Speed

A lot of data and complicated models will slow down fitting.

  • Run the chains in parallel using, e.g., mcp(..., chains=4, cores=4). The only reason this is not enabled by default is because parallel sampling fails on some systems. Turn it on for the whole session using options(mc.cores = 3) which will override cores (which defaults to 1).

  • More data usually means better identifiability and faster convergence. Lower the adaption period period using, e.g., mcp(..., adapt = 300). This is also sometimes called “burnin”.

Errors or won’t run

Most of these problems should stem from inappropriate priors and such problems may be exacerbated by fragile link functions (e.g., binomial(link = "identity"). The article on priors in mcp may be helpful, but in particular:

  • Errors on “directed cycle” usually stems from using parameters in priors. For example, if you set prior = list(int_1 = "dnorm(int_2, 1)"", int_2 = "dnorm(int_1, 1)") this is an infinite regress.

  • Errors on “incompatible with parent nodes” usually stem from impossible values. For example, if you set prior = list(sigma = "dnorm(0, 1)""), this allows for a negative standard deviation, which is impossible. Think about changing the prior distributions and perhaps truncate them using T(lower, upper).

If you encounter these or other problems, don’t hesitate to raise a Github Issue, asking for help or filing a bug report.