Page 1 of 1

Bayesian estimation not working

PostPosted: Sat May 11, 2013 5:53 pm
by chicoutimy
Hi,

I am stuck with this error message, occurring after over thirty minutes of Bayesian estimation.

Loading 165 observations from AADT.mat

Warning: File 'mh_scale_fname' not found.
> In dynare_estimation_1 at 119
In dynare_estimation at 70
In NS5a at 350
In dynare at 120
Initial value of the log posterior (or likelihood): -31792033231.634

==========================================================
Change in the covariance matrix = 1.
Mode improvement = 31791909756.2529
New value of jscale = 7.5517e-18
==========================================================
Warning: Matrix is singular to working precision.
> In dynare_estimation_1 at 341
In dynare_estimation at 70
In NS5a at 350
In dynare at 120
Error using chol
Matrix must be positive definite.

Error in gmhmaxlik (line 196)
dd = transpose(chol(CovJump));

Error in dynare_estimation_1 (line 330)
[xparam1,PostVar,Scale,PostMean] = ...

Error in dynare_estimation (line 70)
dynare_estimation_1(var_list,dname);

Error in NS5a (line 350)
dynare_estimation(var_list_);

Error in dynare (line 120)
evalin('base',fname) ;


I tried to search the forum but found nothing similar as I already use mode_compute=6 and my model seems to be working well when I use stoch_simul before the estimation. I followed two famous papers regarding parameter priors (Smets and Wouters 2007, Justiniano, Primiceri and Tambalotti 2010) so I doubt these priors are two narrow. Also, there is no trend in my linear model, so I have demeaned/detrended the data to be consistent with this.

Any help would be much appreciated. Thanks in advance.

chicoutimy

Re: Bayesian estimation not working

PostPosted: Sat May 11, 2013 8:57 pm
by jpfeifer
Have you tried mode_compute=9?

Re: Bayesian estimation not working

PostPosted: Sun May 12, 2013 10:27 am
by chicoutimy
I've tried with mode_compute=9. There is still a problem with the non positive minus hessian matrix:


POSTERIOR KERNEL OPTIMIZATION PROBLEM!
(minus) the hessian matrix at the "mode" is not positive definite!
=> posterior variance of the estimated parameters are not positive.
You should try to change the initial values of the parameters using
the estimated_params_init block, or use another optimization routine.
Warning: The results below are most likely wrong!
> In dynare_estimation_1 at 458
In dynare_estimation at 70
In NS5a at 350
In dynare at 120
Warning: Matrix is singular to working precision.
> In dynare_estimation_1 at 473
In dynare_estimation at 70
In NS5a at 350
In dynare at 120

RESULTS FROM POSTERIOR MAXIMIZATION
parameters
prior mean mode s.d. t-stat prior pstdev

alpha 0.300 0.6681 Inf 0.0000 norm 0.0500
h 0.700 0.7361 Inf 0.0000 beta 0.1000
lambdaa 5.000 4.9537 Inf 0.0000 gamm 1.0000
mupss 1.200 1.2862 Inf 0.0000 norm 0.1000
muwss 1.200 1.2298 Inf 0.0000 norm 0.1000
phi 2.000 1.9117 Inf 0.0000 gamm 0.7500
phipi 1.700 1.8711 Inf 0.0000 norm 0.3000
phix 0.120 0.3303 Inf 0.0000 norm 0.0500
rhoa 0.500 0.6101 Inf 0.0000 beta 0.2000
rhog 0.500 0.4676 Inf 0.0000 beta 0.2000
rhom 0.500 0.5086 Inf 0.0000 beta 0.2000
rhop 0.500 0.5187 Inf 0.0000 beta 0.2000
rhor 0.750 0.7054 Inf 0.0000 beta 0.1000
rhos 0.500 0.5791 Inf 0.0000 beta 0.2000
rhov 0.500 0.5167 Inf 0.0000 beta 0.2000
rhow 0.500 0.6176 Inf 0.0000 beta 0.2000
rhoz 0.500 0.6045 Inf 0.0000 beta 0.2000
sigma 1.500 1.4379 Inf 0.0000 norm 0.4000
spp 4.000 4.0944 Inf 0.0000 gamm 1.0000
thetap 0.660 0.5311 Inf 0.0000 beta 0.1000
thetaw 0.660 0.6110 Inf 0.0000 beta 0.1000
standard deviation of shocks
prior mean mode s.d. t-stat prior pstdev

epsa 0.100 0.3838 Inf 0.0000 invg 2.0000
epsg 0.100 0.3262 Inf 0.0000 invg 2.0000
epsm 0.100 0.0875 Inf 0.0000 invg 2.0000
epsp 0.100 0.3411 Inf 0.0000 invg 2.0000
epss 0.100 0.0117 Inf 0.0000 invg 2.0000
epsv 0.100 0.4116 Inf 0.0000 invg 2.0000
epsw 0.100 0.3814 Inf 0.0000 invg 2.0000
epsz 0.100 0.1643 Inf 0.0000 invg 2.0000

Log data density [Laplace approximation] is NaN.


ans =

5


ans =

9

Error using dynare_estimation_1 (line 899)
Mode values are outside prior bounds. Reduce prior_trunc.

Error in NS5a (line 350)
dynare_estimation(var_list_);

Error in dynare (line 120)
evalin('base',fname) ;


It seems that my parameters are misspecified. Is there a way to find out which parameters have out-of-bound mode values? What value do you recommend for prior_trunc?

Re: Bayesian estimation not working

PostPosted: Sun May 12, 2013 11:20 am
by jpfeifer
In dynare_estimation_1.m replace

Code: Select all
    if any(xparam1 < bounds(:,1)) || any(xparam1 > bounds(:,2))
        find(xparam1 < bounds(:,1))
        find(xparam1 > bounds(:,2))
        error('Mode values are outside prior bounds. Reduce prior_trunc.')
    end

by
Code: Select all
    if any(xparam1 < bounds(:,1)) || any(xparam1 > bounds(:,2))
        outside_bound_vars=bayestopt_.name([find(xparam1 < bounds(:,1)); find(xparam1 > bounds(:,2))],:);
        disp_string=[outside_bound_vars{1,:}];
        for ii=2:size(outside_bound_vars,1)
            disp_string=[disp_string,', ',outside_bound_vars{ii,:}];
        end
        error(['Mode value(s) of ', disp_string ,' are outside parameter bounds. Potentially, you should set prior_trunc=0.'])
    end

Re: Bayesian estimation not working

PostPosted: Sun May 12, 2013 12:17 pm
by chicoutimy
Thanks for you help. I did what you told me, and it allowed me to see for which parameters the mode was out of bound. Consequently, I changed the priors of these parameters. Now the error message is

Error using chol
Matrix must be positive definite.

Error in metropolis_hastings_initialization (line 68)
d = chol(vv);

Error in random_walk_metropolis_hastings (line 69)
[ ix2, ilogpo2, ModelName, MhDirectoryName, fblck, fline, npar, nblck, nruns,
NewFile, MAX_nruns, d ] = ...

Error in dynare_estimation_1 (line 912)
feval(options_.posterior_sampling_method,objective_function,options_.proposal_distribution,xparam1,invhess,bounds,dataset_,options_,M_,estim_params_,bayestopt_,oo_);

Error in dynare_estimation (line 70)
dynare_estimation_1(var_list,dname);

Error in NS5a (line 350)
dynare_estimation(var_list_);

Error in dynare (line 120)
evalin('base',fname) ;

Has it to do with the fact that some coefficients are negative (actually, only one is negative: the Taylor rule output coefficient)? Sorry to keep pestering you, but I don't understand much about what is going on here.

Re: Bayesian estimation not working

PostPosted: Sun May 12, 2013 1:11 pm
by jpfeifer
Try using the calibrated values as starting values for the Bayesian estimation (instead of the default prior mean).

Re: Bayesian estimation not working

PostPosted: Sun May 12, 2013 8:07 pm
by chicoutimy
I put the calibrated values as starting values. Still the same problem.