# Code running into problem

**URL:** <https://forum.dynare.org/t/code-running-into-problem/12127>\
**Category:** ML/Bayesian estimation\
**Created:** [18 July 2018 14:25 UTC](https://forum.dynare.org/t/code-running-into-problem/12127 "2018-07-18T14:25:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@gdp](https://forum.dynare.org/u/gdp)\
**Post date:** [18 July 2018 14:25 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/1 "2018-07-18T14:25:20Z")

</div>

Hi all,

My code was running properly without errors, somehow I have error messages such as “prior distribution for parameters XX has unbounded density”  
"Warning: gmhmaxlik: Unknown option (MaxIter)! "

Then at some point dynare just stops working without finishing the Bayesian estimation.

I have updated to the most recent Dynare 4.5.5 version, maybe this is causing problem?

Hope to get some insights!

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [19 July 2018 06:45 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/2 "2018-07-19T06:45:00Z")

</div>

The first message is a warning that you use a prior distribution you should not use. Your prior implies an infinite density at the bound of the parameter space. A powerful optimizer should recognize that this may be global optimum, leading to problems in estimation.  
The second message suggest that you are using an old syntax for controlling `mode_compute=6`. What is the problem you encounter after mode-finding?

---

<div class="post-metadata">

**Author:** ![gdp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@gdp](https://forum.dynare.org/u/gdp)\
**Post date:** [19 July 2018 14:42 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/3 "2018-07-19T14:42:07Z")

</div>

For the prior distribution I just follow the literature use Gamma and Beta distribution and set the lower and upper bound to be 0.0000001 and 0.999999. Do you mean I should use a different kind of distribution or different upper or lower bound values?

After several rounds of posterior estimation Dynare just stops, for example:

```auto

==========================================================
   Change in the posterior covariance matrix = 4.
   Change in the posterior mean = 8.9999.
   Mode improvement = 167582702.3443
   New value of jscale = 7.3019e-05
==========================================================

==========================================================
   Change in the posterior covariance matrix = 0.00021355.
   Change in the posterior mean = 8.9999.
   Mode improvement = 167580397.4905
   New value of jscale = 1.3039e-14
==========================================================
Error using chol
Matrix must be positive definite.

Error in gmhmaxlik_core (line 194)
    dd = transpose(chol(CovJump));

Error in gmhmaxlik (line 100)
    [PostMode, PostVariance, Scale, PostMean] = gmhmaxlik_core(fun, OldPostMode,
    bounds, gmhmaxlikOptions, Scale, flag, MeanPar, OldPostVariance, varargin{:});

Error in dynare_minimize_objective (line 254)
    [opt_par_values, hessian_mat, Scale, fval] = gmhmaxlik(objective_function,
    start_par_value, ...

Error in dynare_estimation_1 (line 220)
    [xparam1, fval, exitflag, hh, options_, Scale, new_rat_hess_info] =
    dynare_minimize_objective(objective_function,xparam1,options_.mode_compute,options_,[bounds.lb
    bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
    
Error in dynare_estimation (line 105)
    dynare_estimation_1(var_list,dname);

Error in simple8 (line 615)
oo_recursive_=dynare_estimation(var_list_);

Error in dynare (line 235)
evalin('base',fname) ;
 
Warning: A value of class "matlab.internal.video.PluginManager" was indexed with no subscripts
specified. Currently the result of this operation is the indexed value itself, but in a future
release, it will be an error. 
> In matlab.internal.VideoReader/createChannel (line 495)
  In matlab.internal.VideoReader (line 192)
  In VideoReader/init (line 598)
  In VideoReader (line 171)
  In finfo>getVideoInfo (line 205)
  In finfo>openAsMultimediaFile (line 194)
  In finfo (line 79)
  In open (line 115)
  In uiopen (line 175) 

When I use mode_compute=9, I often get the warning:
Warning: Non-finite fitness range 
> In cmaes (line 974)
  In dynare_minimize_objective (line 360)
  In dynare_estimation_1 (line 220)
  In dynare_estimation (line 105)
  In simple8 (line 615)
  In dynare (line 235) 

And some results like this:

RESULTS FROM POSTERIOR ESTIMATION
parameters
       prior mean mode s.d. prior pstdev

rhoR 0.750 0.7941 NaN beta 0.1500 
rpi 1.200 1.1392 NaN gamm 0.0500 
rdeltay 0.200 0.4434 NaN gamm 0.0500 
b 0.660 0.7650 NaN beta 0.1000 
alfa 0.330 0.1710 NaN beta 0.0300 
s 0.850 0.8550 NaN beta 0.0500 
DSHARE 0.318 0.1196 NaN beta 0.1000 
sigma 0.500 0.7234 NaN beta 0.1000 
rho_g 0.700 0.1717 NaN beta 0.2000 
rho_w 0.700 0.6510 NaN beta 0.2000 
rho_nD 0.700 0.6496 NaN beta 0.2000 
rho_t 0.700 0.4825 NaN beta 0.2000 
rho_i 0.700 0.2989 NaN beta 0.2000 
rho_nH 0.700 0.9177 NaN beta 0.2000 
rho_lp 0.700 0.7202 NaN beta 0.2000 
rho_me 0.700 0.5616 NaN beta 0.2000 
rho_Ome 0.700 0.2432 NaN beta 0.2000 
rho_lq 0.700 0.6188 NaN beta 0.2000 
rho_gb 0.500 0.6771 NaN gamm 0.2500 
rho_wb 0.500 0.6160 NaN gamm 0.2500 
rho_nDb 0.500 0.5114 NaN gamm 0.2500 
rho_gy 0.050 0.1116 NaN norm 0.0500 
rho_wy 0.150 0.0804 NaN norm 0.0500 
rho_nDy 0.150 0.2994 NaN norm 0.0500 

standard deviation of shocks
       prior mean mode s.d. prior pstdev

mpol_eps 0.100 0.0118 NaN invg 2.0000 
mpol_g 0.100 3.1587 NaN invg 2.0000 
mpol_w 0.100 2.0438 NaN invg 2.0000 
mpol_nD 0.100 0.8676 NaN invg 2.0000 
mpol_t 0.100 4.8834 NaN invg 2.0000 
mpol_i 0.100 5.8172 NaN invg 2.0000 
mpol_nH 0.100 2.6733 NaN invg 2.0000 
mpol_lp 0.100 4.6842 NaN invg 2.0000 
mpol_me 0.100 4.3395 NaN invg 2.0000 
mpol_Ome 0.100 4.8172 NaN invg 2.0000 
mpol_lq 0.100 0.8281 NaN invg 2.0000 

Log data density [Laplace approximation] is NaN.

Error using chol
Matrix must be positive definite with real diagonal.

Error in posterior_sampler_initialization (line 84)
d = chol(vv);

Error in posterior_sampler (line 60)
    posterior_sampler_initialization(TargetFun, xparam1, vv,
    mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);

Error in dynare_estimation_1 (line 448)
            posterior_sampler(objective_function,posterior_sampler_options.proposal_distribution,xparam1,posterior_sampler_options,bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
            
Error in dynare_estimation (line 105)
    dynare_estimation_1(var_list,dname);

Error in simple8 (line 615)
oo_recursive_=dynare_estimation(var_list_);

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

```

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [20 July 2018 00:24 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/4 "2018-07-20T00:24:23Z")

</div>

1. How do the `mode_check`-plots look like?
2. For the unbounded density, see [Unbounded density](https://forum.dynare.org/t/unbounded-density/12075)

---

<div class="post-metadata">

**Author:** ![gdp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@gdp](https://forum.dynare.org/u/gdp)\
**Post date:** [25 July 2018 20:29 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/5 "2018-07-25T20:29:39Z")

</div>

Hi Professor,

I try mode\_check, except for some parameters have red dots clustering, most looked normal. When combine with mode\_compute=9, there are always at the prior bound problems, I tried to change the prior mean, tune down the standard deviation or change the upper or lower bound, but the error message would not go away.

However when I try the mode\_compute=6 (the only working one) I did get one model file working. Which I have no idea why…

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [26 July 2018 01:11 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/6 "2018-07-26T01:11:36Z")

</div>

If you run into the prior bounds, this indicates deeper issues like a wrong data treatment

---

<div class="post-metadata">

**Author:** ![abhishek](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@abhishek](https://forum.dynare.org/u/abhishek)\
**Post date:** [26 July 2018 13:19 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/7 "2018-07-26T13:19:01Z")

</div>

Hi,  
I am having an issue of “using chol Matrix must be positive definite” after few MH iterations. I am unable to figure it out. I have attached the mod file. I would be obliged for your help.[Paper\_Estimate\_Bayesian.mod](https://forum.dynare.org/uploads/default/original/2X/c/cdd738ec39e803b307d4b80d217a0929ae14cedf.mod) (6.3 KB)

---

<div class="post-metadata">

**Author:** ![abhishek](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@abhishek](https://forum.dynare.org/u/abhishek)\
**Post date:** [26 July 2018 13:39 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/8 "2018-07-26T13:39:49Z")

</div>

Hi,

If I use option “mcmc\_jumping\_covariance = prior\_variance”, it seems to working fine. Default is “mcmc\_jumping\_covariance = Hessian”. What differences it makes to my estimation? Looking forward to your kind response.

---

<div class="post-metadata">

**Author:** ![abhishek](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@abhishek](https://forum.dynare.org/u/abhishek)\
**Post date:** [26 July 2018 17:44 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/9 "2018-07-26T17:44:25Z")

</div>

Hi

I have another related question. I am getting very low acceptance rate for RW MH. What could be the possible reason and how to improve it. I have already change jump scale but it didn’t help.  
Thank You

---

<div class="post-metadata">

**Author:** ![gdp](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@gdp](https://forum.dynare.org/u/gdp)\
**Post date:** [26 July 2018 18:36 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/10 "2018-07-26T18:36:01Z")

</div>

I use the log difference of the data and the measurement equation is just the linearly detrended by the quarterly growth rate of the data. Maybe one problem with the data is I use the unemployment benefits data which is very volatile and had negative average growth rate.

Another thing I found very strange is in the Historical Variance Decomposition, all data related variables seem to have the same picture, in terms of the magnitude and location of the variance decomposition by each shock. Does this also indicate something fundamental?

---

<div class="post-metadata">

**Author:** ![abhishek](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@abhishek](https://forum.dynare.org/u/abhishek)\
**Post date:** [27 July 2018 13:33 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/11 "2018-07-27T13:33:33Z")

</div>

HI,

I am having the problem of “(minus) the hessian matrix at the “mode” is not positive definite!” in attached mod file. I have changed[Paper\_3.mod](https://forum.dynare.org/uploads/default/original/2X/d/d684b5e8b8c2270eb876f95d4a8c2bb5271337ee.mod) (5.7 KB)  
optimisation routines but is of no help. I would be obliged if you can help.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [27 July 2018 13:56 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/12 "2018-07-27T13:56:38Z")

</div>

In both cases I would need to see the mod-file and the data files or at least the mode\_check plots.  
@gdp As I said, running into the prior bounds usually indicates some more fundamental problems. Which economic parameters are the one that run into the bound?  
@abhishek Any positive definite covariance matrix as the proposal density will work. The identity may simply be less efficient. But using a different matrix is not a substitute for solving the typical problems with the model that give rise to the Hessian at the conjectured mode not being positive definite

---

<div class="post-metadata">

**Author:** ![abhishek](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@abhishek](https://forum.dynare.org/u/abhishek)\
**Post date:** [27 July 2018 14:24 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/13 "2018-07-27T14:24:16Z")

</div>

Hi,  
Thanks for your kind response. Please find attached mod files and data. [data\_nk.mat](https://forum.dynare.org/uploads/default/original/2X/c/cfc3e461b6f736ff28946920cd7ad8b79510f6cb.mat) (5.5 KB)  
[Paper\_3.mod](https://forum.dynare.org/uploads/default/original/2X/d/d684b5e8b8c2270eb876f95d4a8c2bb5271337ee.mod) (5.7 KB)  
[Paper\_Estimate\_Bayesian.mod](https://forum.dynare.org/uploads/default/original/2X/a/a1363aaf4b3bbc726e619131e4c1ef6d6cca6b51.mod) (6.5 KB)

Paper\_3.mod does likelihood estimation while the other mod file does Bayesian estimation. Both of them use same data attached.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [29 July 2018 13:07 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/14 "2018-07-29T13:07:49Z")

</div>

@abhishek

1. You have stochastic singularity as you observe all components of the budget constraint.
2. Your inflation series seems to have a massive seasonal pattern.
3. `npaobs` has a strange step function at the end of the sample that may give the optimizer trouble
4. Try `mode_compute=5`

---

<div class="post-metadata">

**Author:** ![abhishek](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@abhishek](https://forum.dynare.org/u/abhishek)\
**Post date:** [31 July 2018 14:52 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/15 "2018-07-31T14:52:13Z")

</div>

Dear Sir,

Thanks for your kind response.

Could you please elaborate on point 1.

I dropped inflation and npaobs from observables but still having the problem of “(minus) the hessian matrix at the “mode” is not positive definite!” in attached mod file.

[Paper\_4.mod](https://forum.dynare.org/uploads/default/original/2X/d/db17132aae5f5a7f94108be1b7e85d5bd0973802.mod) (5.6 KB)

---

<div class="post-metadata">

**Author:** ![abhishek](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@abhishek](https://forum.dynare.org/u/abhishek)\
**Post date:** [31 July 2018 15:00 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/16 "2018-07-31T15:00:29Z")

</div>

Dear Sir,

And if I have understood your point 1 correctly, even after dropping cobs as observables gives the problem of “(minus) the hessian matrix at the “mode” is not positive definite!”. Kindly have a look.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [2 August 2018 15:14 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/17 "2018-08-02T15:14:54Z")

</div>

Did you solve issues 2 and 3 or at least 2? You did not provide any new data.

---

<div class="post-metadata">

**Author:** ![abhishek](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/7ba0ec/32.png) [@abhishek](https://forum.dynare.org/u/abhishek)\
**Post date:** [3 August 2018 07:41 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/18 "2018-08-03T07:41:58Z")

</div>

Dear Sir,

I dropped both of them from observables. I am no longer estimating model using them. But still the problem persist.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [11 August 2018 11:50 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/19 "2018-08-11T11:50:28Z")

</div>

Have a look at the `mode_check`-plots. There are several parameters that are problematic. You may have to go for Bayesian estimation instead of ML.

---

<div class="post-metadata">

**Author:** ![AlexLee](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@AlexLee](https://forum.dynare.org/u/AlexLee)\
**Post date:** [17 September 2023 18:48 UTC](https://forum.dynare.org/t/code-running-into-problem/12127/20 "2023-09-17T18:48:37Z")

</div>

Dear Prof. Pfeifer,

I have the same warning. Do I have to change the prior distribution? If Ihave to change it, What should I change? The prior initial value, the prior shape, the prior mean, or the prior standard deviation?

Based on my understanding, for the prior distribution, we only need to provode the prior shape, the prior initial value, the prior mean, and the prior standard deviation. The lower bound and the upper bound are optional. We do not have to provide these two values. Is my undersdanding correct?

Thank you,  
Alex

[Next page](https://forum.dynare.org/t/code-running-into-problem/12127.md?page=2)
