From ea5d2e90b2600ebb141903e8b71d6f2acda3d91d Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 5 Jul 2013 23:46:05 +0200 Subject: [PATCH 1/3] Take care of parameter estimates at prior bounds in check plots Symmetric plots for parameters at the prior bounds resulted in nothing being printed. This commit then switches to asymmetric plots for those parameters and plots a red line signifying the bound. --- matlab/mode_check.m | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/matlab/mode_check.m b/matlab/mode_check.m index 6f9299ac1..8fdbbc2a4 100644 --- a/matlab/mode_check.m +++ b/matlab/mode_check.m @@ -109,15 +109,24 @@ for plt = 1:nbplt, end end xx = x; - l1 = max(BayesInfo.lb(kk),(1-sign(x(kk))*ll)*x(kk)); m1 = 0; - l2 = min(BayesInfo.ub(kk),(1+sign(x(kk))*ll)*x(kk)); - if DynareOptions.mode_check.symmetric_plots, - if l2<(1+ll)*x(kk) - l1 = x(kk) - (l2-x(kk)); + l1 = max(BayesInfo.lb(kk),(1-sign(x(kk))*ll)*x(kk)); m1 = 0; %lower bound + l2 = min(BayesInfo.ub(kk),(1+sign(x(kk))*ll)*x(kk)); %upper bound + binding_lower_bound=0; + binding_upper_bound=0; + if isequal(x(kk),BayesInfo.lb(kk)) + binding_lower_bound=1; + bound_value=BayesInfo.lb(kk); + elseif isequal(x(kk),BayesInfo.ub(kk)) + binding_upper_bound=1; + bound_value=BayesInfo.ub(kk); + end + if DynareOptions.mode_check.symmetric_plots && ~binding_lower_bound && ~binding_upper_bound + if l2<(1+ll)*x(kk) %test whether upper bound is too small due to prior binding + l1 = x(kk) - (l2-x(kk)); %adjust lower bound to become closer m1 = 1; end - if ~m1 && (l1>(1-ll)*x(kk)) && (x(kk)+(x(kk)-l1)(1-ll)*x(kk)) && (x(kk)+(x(kk)-l1) Date: Sat, 6 Jul 2013 00:20:07 +0200 Subject: [PATCH 2/3] Bugfix for correct display of names of parameters outside of bounds --- matlab/dynare_estimation_1.m | 13 ++++++++----- matlab/dynare_estimation_init.m | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index b0e14d585..88e36e382 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -556,11 +556,14 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ... bounds(:,2)=min(bounds(:,2),ub); bayestopt_.lb = bounds(:,1); bayestopt_.ub = bounds(:,2); - 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,:}]; + outside_bound_pars=find(xparam1 < bounds(:,1) | xparam1 > bounds(:,2)); + if ~isempty(outside_bound_pars) + for ii=1:length(outside_bound_pars) + outside_bound_par_names{ii,1}=get_the_name(ii,0,M_,estim_params_,options_); + end + disp_string=[outside_bound_par_names{1,:}]; + for ii=2:size(outside_bound_par_names,1) + disp_string=[disp_string,', ',outside_bound_par_names{ii,:}]; end error(['Mode value(s) of ', disp_string ,' are outside parameter bounds. Potentially, you should set prior_trunc=0.']) end diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index e99b73bb6..6d54ffd2d 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -146,11 +146,14 @@ if ~isempty(estim_params_) end % Test if initial values of the estimated parameters are all between % the prior lower and upper bounds. - 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,:}]; + outside_bound_pars=find(xparam1 < bounds(:,1) | xparam1 > bounds(:,2)); + if ~isempty(outside_bound_pars) + for ii=1:length(outside_bound_pars) + outside_bound_par_names{ii,1}=get_the_name(ii,0,M_,estim_params_,options_); + end + disp_string=[outside_bound_par_names{1,:}]; + for ii=2:size(outside_bound_par_names,1) + disp_string=[disp_string,', ',outside_bound_par_names{ii,:}]; end error(['Initial value(s) of ', disp_string ,' are outside parameter bounds. Potentially, you should set prior_trunc=0. If you used the mode_file-option, check whether your mode-file is consistent with the priors.']) end From 41f6c2ff66c0175a423de39f38a8954f20668f17 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 6 Jul 2013 00:23:09 +0200 Subject: [PATCH 3/3] Display source of non-positive definite Hessian if parameters at prior bound --- matlab/dynare_estimation_1.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 88e36e382..739a22cc5 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -491,6 +491,24 @@ if ~options_.mh_posterior_mode_estimation && options_.cova_compute disp('=> posterior variance of the estimated parameters are not positive.') disp('You should try to change the initial values of the parameters using') disp('the estimated_params_init block, or use another optimization routine.') + params_at_bound=find(xparam1==ub | xparam1==lb); + if ~isempty(params_at_bound) + for ii=1:length(params_at_bound) + params_at_bound_name{ii,1}=get_the_name(ii,0,M_,estim_params_,options_); + end + disp_string=[params_at_bound_name{1,:}]; + for ii=2:size(params_at_bound_name,1) + disp_string=[disp_string,', ',params_at_bound_name{ii,:}]; + end + fprintf('\nThe following parameters are at the prior bound: %s\n', disp_string) + fprintf('Some potential solutions are:\n') + fprintf(' - Check your model for mistakes.\n') + fprintf(' - Check whether model and data are consistent (correct observation equation).\n') + fprintf(' - Shut off prior_trunc.\n') + fprintf(' - Use a different mode_compute like 6 or 9.\n') + fprintf(' - Check whether the parameters estimated are identified.\n') + fprintf(' - Increase the informativeness of the prior.\n') + end warning('The results below are most likely wrong!'); end end