2015-02-27 17:12:04 +01:00
|
|
|
function varargout = prior(varargin)
|
|
|
|
|
|
|
|
% Computes various prior statistics and display them in the command window.
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% 'table', 'moments', 'optimize', 'simulate', 'plot'
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% none
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
|
|
|
% Copyright (C) 2015 Dynare Team
|
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-05-09 22:26:59 +02:00
|
|
|
if isempty(varargin) || ( isequal(length(varargin), 1) && isequal(varargin{1},'help'))
|
|
|
|
skipline()
|
|
|
|
disp('Possible options are:')
|
|
|
|
disp(' + table Prints a table describing the priors.')
|
|
|
|
disp(' + moments Computes and displays moments of the endogenous variables at the prior mode.')
|
|
|
|
disp(' + optimize Optimizes the prior density (starting from a random initial guess).')
|
|
|
|
disp(' + simulate Computes the effective prior mass (using a Monte-Carlo).')
|
|
|
|
disp(' + plot Plots the marginal prior densities.')
|
|
|
|
skipline()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-06-01 18:22:51 +02:00
|
|
|
global options_ M_ estim_params_ bayestopt_ oo_
|
2015-10-09 14:20:54 +02:00
|
|
|
|
2015-02-27 17:12:04 +01:00
|
|
|
donesomething = false;
|
|
|
|
|
2016-06-16 11:16:23 +02:00
|
|
|
if ~isbayes(estim_params_)
|
|
|
|
warning('No prior detected!')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if (size(estim_params_.var_endo,1) || size(estim_params_.corrn,1))
|
|
|
|
% Prior over measurement errors are defined...
|
|
|
|
if ((isfield(options_,'varobs') && isempty(options_.varobs)) || ~isfield(options_,'varobs'))
|
|
|
|
% ... But the list of observed variabled is not yet defined.
|
|
|
|
warning('Prior detected on measurement erros, but no list of observed variables (varobs is missing)!')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
% Fill or update bayestopt_ structure
|
2016-06-16 11:57:16 +02:00
|
|
|
[xparam1, EstimatedParams, BayesOptions, lb, ub, Model] = set_prior(estim_params_, M_, options_);
|
2016-06-16 11:16:23 +02:00
|
|
|
|
|
|
|
|
2015-02-27 17:12:04 +01:00
|
|
|
% Temporarly change qz_criterium option value
|
|
|
|
changed_qz_criterium_flag = 0;
|
|
|
|
if isempty(options_.qz_criterium)
|
|
|
|
options_.qz_criterium = 1+1e-9;
|
|
|
|
changed_qz_criterium_flag = 1;
|
|
|
|
end
|
|
|
|
|
2016-06-16 11:57:16 +02:00
|
|
|
Model.dname = Model.fname;
|
2015-02-27 17:12:04 +01:00
|
|
|
|
|
|
|
% Temporarly set options_.order equal to one
|
|
|
|
order = options_.order;
|
|
|
|
options_.order = 1;
|
|
|
|
|
|
|
|
if ismember('plot', varargin)
|
2016-06-16 11:57:16 +02:00
|
|
|
plot_priors(BayesOptions, Model, EstimatedParams, options_)
|
2015-02-27 17:12:04 +01:00
|
|
|
donesomething = true;
|
|
|
|
end
|
|
|
|
|
|
|
|
if ismember('table', varargin)
|
2016-06-16 11:57:16 +02:00
|
|
|
print_table_prior(lb, ub, options_, Model, BayesOptions, EstimatedParams);
|
2015-02-27 17:12:04 +01:00
|
|
|
donesomething = true;
|
|
|
|
end
|
|
|
|
|
|
|
|
if ismember('simulate', varargin) % Prior simulations (BK).
|
2016-06-16 11:57:16 +02:00
|
|
|
results = prior_sampler(0, Model, BayesOptions, options_, oo_, EstimatedParams);
|
2015-02-27 17:12:04 +01:00
|
|
|
% Display prior mass info
|
|
|
|
skipline(2)
|
|
|
|
disp(['Prior mass = ' num2str(results.prior.mass)])
|
|
|
|
disp(['BK indeterminacy share = ' num2str(results.bk.indeterminacy_share)])
|
|
|
|
disp(['BK unstability share = ' num2str(results.bk.unstability_share)])
|
|
|
|
disp(['BK singularity share = ' num2str(results.bk.singularity_share)])
|
|
|
|
disp(['Complex jacobian share = ' num2str(results.jacobian.problem_share)])
|
|
|
|
disp(['mjdgges crash share = ' num2str(results.dll.problem_share)])
|
|
|
|
disp(['Steady state problem share = ' num2str(results.ss.problem_share)])
|
|
|
|
disp(['Complex steady state share = ' num2str(results.ss.complex_share)])
|
|
|
|
disp(['Analytical steady state problem share = ' num2str(results.ass.problem_share)])
|
|
|
|
skipline(2)
|
|
|
|
donesomething = true;
|
|
|
|
end
|
|
|
|
|
|
|
|
if ismember('optimize', varargin) % Prior optimization.
|
2016-06-16 11:57:16 +02:00
|
|
|
optimize_prior(options_, Model, oo_, BayesOptions, EstimatedParams);
|
2015-02-27 17:12:04 +01:00
|
|
|
donesomething = true;
|
|
|
|
end
|
|
|
|
|
|
|
|
if ismember('moments', varargin) % Prior simulations (2nd order moments).
|
|
|
|
% Set estimated parameters to the prior mode...
|
2016-06-16 11:57:16 +02:00
|
|
|
xparam1 = BayesOptions.p5;
|
2016-06-16 11:59:47 +02:00
|
|
|
% ... Except for uniform priors (use the prior mean)!
|
2015-02-27 17:12:04 +01:00
|
|
|
k = find(isnan(xparam1));
|
2016-06-16 11:59:47 +02:00
|
|
|
xparam1(k) = BayesOptions.p1(k);
|
2015-02-27 17:12:04 +01:00
|
|
|
% Update vector of parameters and covariance matrices
|
2016-06-16 11:57:16 +02:00
|
|
|
Model = set_all_parameters(xparam1, EstimatedParams, Model);
|
2015-02-27 17:12:04 +01:00
|
|
|
% Check model.
|
2016-06-16 11:57:16 +02:00
|
|
|
check_model(Model);
|
2015-02-27 17:12:04 +01:00
|
|
|
% Compute state space representation of the model.
|
2016-06-16 11:57:16 +02:00
|
|
|
oo__ = oo_;
|
|
|
|
oo__.dr = set_state_space(oo__.dr, Model, options_);
|
2015-02-27 17:12:04 +01:00
|
|
|
% Solve model
|
2016-06-16 11:57:16 +02:00
|
|
|
[dr, info, Model , options__ , oo__] = resol(0, Model , options_ ,oo__);
|
2015-02-27 17:12:04 +01:00
|
|
|
% Compute and display second order moments
|
2016-06-16 11:57:16 +02:00
|
|
|
oo__ = disp_th_moments(oo__.dr, [], Model, options__, oo__);
|
2015-02-27 17:12:04 +01:00
|
|
|
skipline(2)
|
|
|
|
donesomething = true;
|
|
|
|
end
|
|
|
|
|
|
|
|
if changed_qz_criterium_flag
|
|
|
|
options_.qz_criterium = [];
|
|
|
|
end
|
|
|
|
|
|
|
|
options_.order = order;
|
|
|
|
|
|
|
|
if ~donesomething
|
|
|
|
error('prior: Unexpected arguments!')
|
|
|
|
end
|
|
|
|
|
2016-06-16 11:57:16 +02:00
|
|
|
function format_string = build_format_string(PriorStandardDeviation, LowerBound, UpperBound)
|
2015-02-27 17:12:04 +01:00
|
|
|
format_string = ['%s & %s & %6.4f &'];
|
|
|
|
if ~isnumeric(PriorStandardDeviation)
|
|
|
|
format_string = [ format_string , ' %s &'];
|
|
|
|
else
|
|
|
|
format_string = [ format_string , ' %6.4f &'];
|
|
|
|
end
|
|
|
|
if ~isnumeric(LowerBound)
|
|
|
|
format_string = [ format_string , ' %s &'];
|
|
|
|
else
|
|
|
|
format_string = [ format_string , ' %6.4f &'];
|
|
|
|
end
|
|
|
|
if ~isnumeric(UpperBound)
|
|
|
|
format_string = [ format_string , ' %s &'];
|
|
|
|
else
|
|
|
|
format_string = [ format_string , ' %6.4f &'];
|
|
|
|
end
|
|
|
|
format_string = [ format_string , ' %6.4f & %6.4f \\\\ \n'];
|