I have run a chain and would like to now run another (off the same posterior mode) then create diagnostics. I think the following procedure would work
- create another subfolder, saving the posterior mode, and the dynare file into it.
- Run a chain of the same length (using the saved mode file rather than reestimating it) Then rename the resulting _mh0.mat file as _mh0_blck2.mat.
- Add the original chain into the directory as _mh0_blck1.mat
- Run again with the load_mh_file option, mh_nblocks=2, with a minimal number of additional replications requested
I have made this work (computationally) and it seems valid to me but if anyone can see any issues please let me know.
It’s not a good idea… The problem is that if we run only one Markov chain, dynare chooses the same initial condition: the posterior mode. So if you follow these steps you will have two Markov chains with the same initial conditons (and if a seed is set somewhere we will have exactly the same chains) and this is not a good thing if you want to use Gelman et al. convergence diagnostics implemented in dynare (the initial conditions have to be different enough).
A trick would be to perturb xparam1 in the new *_mode.mat file with a zero mean gaussian noise. You may follow the following steps:
scale = options_.mh_init_scale;
load <ModFileName>_mode.mat ;
xparam1 = xparam1 + scale*chol(inv(hh))'*randn(length(xparam1),1);
save <ModFileName>_mode xparam1 hh;
xparam1 is a vector holding the values of the estimated parameters at the mode. hh is the hessian matrix (of the posterior density) at the mode. Then you just have to use the updated *_mode file. The new Markov chain will start from the new xparam1. You may still have a problem: here we did not check if B&K conditons are satisfied with the new xparam1 and we did not check if this vector is inside the support of the prior distribution. So you have to be lucky
Why don’t you start a new metropolis with 2 (or more) chains? It’s not so long…
Thank you very much Stephane! Those are important traps I would have fallen into.
I am working with a large model (I seem to achieve about 800 MH replications an hour).
I plan to tune my experiment a little more without running chains (just finding posterior mode). Then, I would like to leave it for a week to run MH replications.
For this, I thought I might run 2 chains of around 60,000. As a safety against network or power failures, I might issue 7 successive estimation commands in the dynare file (each for say 9,000 replications, using load_mh_file in each, except the first). This seemed to me like a useful way to ensure results are usable even if there is a crash. But please let me know if this is a bad idea!
Hi David, I don’t if it is possible to call several times the estimation command in the same mod file (I never tried). I have wrote (for dynare v4) some code to recover a crashed metropolis, but I did not test it for a while so I suggest you to test it before. If for some reason your mh crashes in the middle of a chain, you just have to add:
options_.mh_recover = 1;
before the estimation command (I don’t remember if dynare’s parser understand this option and if we can write mh_recover as an option in the estimation command). With this option dynare tries to see how many simulations and chains were already done (the state of the mcmc before the crash) and the metropolis will be resumed from this state.
If you want to see how this works you can read file metropolis.m from line 239.