Joint posterior density

Hi all,

Running MCMC Metropolis Hastings, we can obtain the marginal posterior density for each estimate parameter from “oo_.posterior_density”. Is it possible to retrieve the joint posterior density for all estimated parameters in Dynare after MCMC estimation?

Thanks in advance!

Best wishes!

Hi Andy_zhao.

The point is that the MH algorithm will generate draws from the joint posterior.
But from the point of view of a single parameter (integrating all other parameters out) the joint draws are also draws from the marginal distributions.

So you already have what you want. The reason why you obtain the plots of the marginal posteriors and not the joint posterior is simply for graphical reasons.

Best wishes.

Dear Max1,

Thanks a lot for your help. I understand your point that posterior density of a single parameter is the marginal distributions that integrating all other parameters out from the joint posterior distribution.

In dynare, “oo_.posterior_density” produce two column vectors that capture the marginal posterior density of a single parameter. I am looking for the dynare code for exporting the joint posterior, which should be the stationary distribution of the Markovian Chain.

Could you offer further help?

Many thanks!

@Andy_zhao This would be a very high-dimensional object to store. So Dynare does not compute or save it. You would need to compute it yourself using the saved posterior draws on the hard-disk.

Dear Johannes,

Thank you so much for your help! Now I see. Dynare actually does not save the posterior draws.

To be honest, I have no idea how to save the posterior draws from MCMC estimation on my own hard-disk. Would it be possible for you to offer some further guidance?

Many thanks!

Unfortunately, the Manual is not explicit about the information stored in the structure oo_.posterior_density.

Variable set by the estimation command, if it is used with mh_replic > 0 or
load_mh_file option. Fields are of the form:

  1. What exactly is stored in this structure? I initially thought it would store the draws of the MH-algorithm from the posterior, but this seems to be not the case.

  2. My second guess was that the posterior draws from the MH-algorithm are stored in the metropolis subfolder. But the files File_Name_posterior_draws1 and File_Name_posterior_draws2 do not store the posterior draws. So, what are these .mat files good for? And where do I get the posterior draws?

  1. The parameter draws are saved in the _mh1_blck*.mat-files in the metropolis-subfolder.
  2. The _posterior_draws*.mat-files only store the draws used to compute the posterior statistics.
  3. The oo_.posterior_density stores the results of a univariate kernel density smoother applied to the posterior draws, i.e. essentially a slice through the posterior.
1 Like

Dear Johannes,

Thank you so much for your clear explanation! Now it become more clear to me where to find the posterior draws.

one follow up question is where can I find “posterior_draws*.mat" -files, is it stored under "oo.”?

Many thanks

Thank you very much for the answer.

I have some open questions.

  1. In the manual I found the following

posterior_sampler_options = (NAME, VALUE, …)

Save the MCMC draws into a _mh_tmp_blck file at the refresh rate of the status
bar instead of just saving the draws when the current _mh*_blck file is full.
Default: 0

What is meant by " just saving the draws when the current _mh*_blck file is full "?
Which value is required to tell Dynare to store the draws in the _mh_tmp_blck file?
(I assume the default 0 means something like “do not store”?)
Under which conditions is it reasonable to use this ‘save_tmp_file’ option instead of using the _mh1_blck*.mat -files in the metropolis -subfolder?

  1. Could you offer more details about the idea behind the _posterior_draws*.mat -files?
    Because this file contains the cell array called "pdraws" which in turn encompasses a lot of information, it is not straightforward to get the idea from the file itself. Is there any further documentation?

  2. It seems to be the case that oo_.posterior_density.parameters.PARAMETER_NAME(:,1) stores 512 grid points and oo_.posterior_density.parameters.PARAMETER_NAME(:,2) stores the respective 512 estimates of the posterior density at that grid points.
    Which kernel density estimator is used for the density estimation and what about the bandwidth selection? Why is the density estimate sometimes turning (weakly) negative?

You can find the _posterior_draws*.mat -files in the metropolis subfolder.

Hi Max1,

Thanks a lot. However, I can not find ‘_posterior_draws*.mat’ -files in the ‘metropolis’ subfolder.

I am running MCMC using dynare 4.4.3, and I set mh_replic = 1000000. What had stored in the ‘metropolis’ subfolder are:
(1), metropolis.log
(2), modname_mh_history_0.mat
(3), modname_mh1_blck1.mat to modname_mh288_blck1.mat: (overall 288 mat files)
(4), modname_mh1_blck2.mat to modname_mh288_blck2.mat: (overall 288 mat files)

Why does not ‘_posterior_draws*.mat’ -files show up in the ‘metropolis’ subfolder? is it because the version of dynare I am using? or maybe because I miss some command code in “estimation” at the time of conducting MCMC Bayesian estimation?

Many thanks!

The _posterior_draws*.mat-files should only be there is subdraws are required, e.g. because of moments_varendo

  1. Dynare has an option options_.MaxNumberOfBytes governing how large a file on the disk is allowed to be. During the MCMC, Dynare will keep all draws in memory until that file size is reached and only then write the last draws to the disk. If you want to see what is going on with your chain before a full file is saved, you can use that option. I personally do not use this at all.
  2. The _posterior_draws*.mat-files are used for the computation of moments_varendo. For the computation of these moments, you need the decision rules. Recomputing them each time for each new moment (e.g. variance, correlation, variance decomposition, etc.) is impractical. So we save both the draw (first column) and the computed decision rule (second column) in the cell array for each parameter draw (rows).
  3. See More information on mh_optimal_bandwidth

Dear Johannes,

Now I see. Thanks a lot!

Best Wishes

Dear Johannes,

Thanks for your help and patience!

May I have one additional question:

I am running MCMC using dynare 4.4.3, and set mh_replic = 1000000, mh_nblocks =2. In the ‘metropolis’ subfolder, I do find the raw posterior draws following your suggestion for the two chain block, which are stored from “modname_mh1_blck1.mat” to “modname_mh288_blck1.mat” (overall 288 mat files) for MCMC chain 1 and from “modname_mh1_blck2.mat” to “modname_mh288_blck2.mat”: (overall 288 mat files) for MCMC chain 2. Base on these results, I am able to collect all raw posterior draw, which is a matrix A with size [1000000*34] as 34 parameters are estimated.

If only a single parameter is estimated, the posterior distribution is one dimension, we can simply use the matlab function"hist" to infer the posterior distribution. However, now I have 34 estimated parameters and the joint posterior distribution should be multi-dimensional. My question is how can I back out the joint posterior distribution based on the raw posterior draw with size [1000000*34]. Could you offer further guidance?

Many thanks

See e.g.

Thanks a lot! Johannes