diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 01ad20056..769723a39 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -513,6 +513,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 @@ -578,11 +596,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 9626306e7..ea551f0bf 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 diff --git a/matlab/mode_check.m b/matlab/mode_check.m index e7591e21d..a8e06a32d 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)