Page 1 of 1

oo_.posterior_mean is missing

PostPosted: Thu Apr 25, 2013 2:30 pm
by lombard
Hi,
I get the following error (Dynare 4.3.3)
Log data density [Laplace approximation] is -6093.935107.

MH: Total number of Mh draws: 500000.
MH: Total number of generated Mh files: 304.
MH: I'll use mh-files 304 to 304.
MH: In mh-file number 304 i'll start at line 1065.
MH: Finally I keep 500 draws.

Reference to non-existent field 'posterior_mean'.

This is the content of oo_


exo_simul: [3x50 double]
endo_simul: []
dr: [1x1 struct]
exo_steady_state: [50x1 double]
exo_det_steady_state: []
exo_det_simul: []
steady_state: [203x1 double]
prior: [1x1 struct]
posterior: [1x1 struct]
posterior_mode: [1x1 struct]
posterior_std: [1x1 struct]
MarginalDensity: [1x1 struct]
Smoother: [1x1 struct]
SmoothedVariables: [1x1 struct]
UpdatedVariables: [1x1 struct]
SmoothedShocks: [1x1 struct]
gamma_y: {7x1 cell}
mean: [6x1 double]
var: [6x6 double]
autocorr: {[6x6 double] [6x6 double] [6x6 double] [6x6 double] [6x6 double]}
irfs: [1x1 struct]
PosteriorTheoreticalMoments: [1x1 struct]

Also, this is the set of optims that I call
estimation(load_mh_file,mode_file=ECB_IPAM_mh_mode,datafile='ECBIPAM_dataestim',nobs=83,presample=8,mode_compute=0,mh_replic= 00000,mh_jscale=0.08,mh_nblocks=6)


Am I doing something wrong?

Thanks

Gianni

Re: oo_.posterior_mean is missing

PostPosted: Thu Apr 25, 2013 2:44 pm
by jpfeifer
In which function does the crash happen? Unfortunately, you cut the message off.

Re: oo_.posterior_mean is missing

PostPosted: Thu Apr 25, 2013 3:19 pm
by lombard
your are right. It crashe in dynare_estimation_1.m . Look for "('mean' " . I replaced it with 'mode' and it works.

Is this a bug? Is the posterior_mean normally produced?

Thanks

Re: oo_.posterior_mean is missing

PostPosted: Thu Apr 25, 2013 3:35 pm
by jpfeifer
If options_.mh_replic is not 0, then it should exist. It is created by GetPosteriorParametersStatistics. Did you really set
Code: Select all
mh_replic= 00000

i.e. to 0?

Re: oo_.posterior_mean is missing

PostPosted: Thu Apr 25, 2013 3:40 pm
by lombard
The manual says
oo_.posterior_mean [MATLAB/Octave variable]
Variable set by the estimation command, if it is used with mh_replic > 0 or load_mh_file
option. Fields are of the form:


so I thought that load_mh_file would suffice (otherwise I have to run an MCMC every time I want to re-generate posterior moments)

Is this correct?

Re: oo_.posterior_mean is missing

PostPosted: Thu Apr 25, 2013 4:02 pm
by jpfeifer
Have you tried leaving the mh_replic option out. My guess is that you specifying it at 0 overwrites the information in the loaded mode-file.

Re: oo_.posterior_mean is missing

PostPosted: Mon Apr 29, 2013 7:29 am
by lombard
Thanks, but if I leave the option out, I guess I'll get the default value [20K]
In any case I see that the chain are not overwritten (by the option load_mh_file)

I'll try with the fs2000 example

Cheers

Gianni

Re: oo_.posterior_mean is missing

PostPosted: Mon Apr 29, 2013 9:37 am
by lombard
I've successfully tried with fs2000.mod and the same options_ used in the model that does not produce "posterior_mean".

Do you know where "posterior_mean" is generated? There must be something odd with the chains that prevent it to be constructed (the other posterior moments are there though)

Cheers

Gianni

Re: oo_.posterior_mean is missing

PostPosted: Mon Apr 29, 2013 10:58 am
by jpfeifer
Ok, we are getting closer. load_mh_file loads the previous draws and adds the number of draws specified in mh_replic at the end. However, posterior moments are only computed in dynare_estimation_1
Code: Select all
        if options_.mh_replic
            [marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_);
            oo_ = GetPosteriorParametersStatistics(estim_params_, M_, options_, bayestopt_, oo_);
            if ~options_.nograph
                oo_ = PlotPosteriorDistributions(estim_params_, M_, options_, bayestopt_, oo_);
            end
            [oo_.posterior.metropolis.mean,oo_.posterior.metropolis.Variance] ...
                = GetPosteriorMeanVariance(M_,options_.mh_drop);
        else
            load([M_.fname '_results'],'oo_');
        end

Thus, if you set mh_replic to 0, Dynare will load the previous results from the results-file and not create additional fields. But for some reason your previous results also did not compute and save the posterior mean field. As a quick hack, you could just set
Code: Select all
if options_.mh_replic >=0


If you could describe the particular use you were intending, we might be able to get around this issue by implementing a solution.

Re: oo_.posterior_mean is missing

PostPosted: Thu May 02, 2013 2:44 pm
by lombard
The workaround seems to do its job. Thanks!

I'm trying to do some graphical analysis of the MCMC output after the chains have been generated in a cluster
in non-graphical mode.

Best

Gianni

Re: oo_.posterior_mean is missing

PostPosted: Wed Nov 27, 2013 2:28 pm
by StephaneAdjemian
Hi,

I crossed this thread while trying to fix Github issue #544. From the details given in the first post of this thread, I infer that the MCMC draws were generated with an older version of dynare (I do not see other explanation). I guess that in this previous version of dynare there was no posterior_mean field in oo_... So this is a compatibility issue between 4.3.3 and older versions). Version compatibility is a recurrent problem in Dynare that we need to fix.

The fix proposed by Johannes works but you should not keep this patch (you only need this once to create the posterior_mean missing field), otherwise you will compute the posterior moments each time you call estimation with the load_mh_file option and mh_replic=0 which can be quite time consuming and is not necessary.

Best,
Stéphane.