Fitting a BUGS model can be frustrating. Sometimes it takes thousands of iterations to get a model converged. Reparametrize your parameters can speed up the converging. Professor Andrew Gelman has a paper talking about this issue.
I am lucky enough to have both training on fitting BUGS models using R2WinBUGS and WinBUGS/OpenBUGS. I like to use R2WinBUGS when the model is easy to converge. I have the summary statistics and convergency statistics ready to use when using R2WinBUGS.
However, if the model converges slowly (and you don't want to do the reparametrization), R2WinBUGS is not a good choice. Because R2WinBUGS does not save the last state of the MCMC chains. The last.values slot saves the last values of the saved parameters. The parameter-to-save is not necessarily the parameters that needs initial values for priors. So this mean when you figure out the model does not covergerged, you might have to re-run the MCMC chains from the low density area again based on the newly genereated priors. On the other hands, you can always stop and check and start again when you fit BUGS models using WinBUGS/OpenBUGS. But the checking procedure is time-consuming.
One alternative is to fit BUGS models using BRugs. BRugs is an R package that links to OpenBUGS. BRugs can save the last state of the parameters that needs priors. After you fit a
OpenBUGS model, just type:
You will have inital values saved as the txt files in your working directory. The other nice feature of BRugs is that if you find the model does not converged, you just type:
You can restart the BUGS model from the last state and update for another 1000 iterations.
But...But...But...You still need to save the coda files:
Read in the code files. The file name has to be save as "CODAchain1.txt" and "CODAindex.txt".
output <- read.openbugs(stem=working.directory)
And do the convergence check.
This is annoying and time-consuming. So I wrote a function that fits BUGS models using BRugs and checks the converegence. If the model does not converged, it will update another 1000 (default) iterations. The loop of fitting and updating will stop only when either the model is converged or n.sims: (how many updating) is reached. The function uses codes from openbugs() in R2WinBUGS and modelUpdate() in BRugs. I uses Gelman and Rubin convergence statistics: Rhat to decide whether the model is converged or not.
The function is here.
Last words: If the model converges slowly, you might want to think about doing reparametrization first!!
2 hours ago