2015-12-04 14:50:44 +01:00
|
|
|
function oo_ = GetPosteriorParametersStatistics(estim_params_, M_, options_, bayestopt_, oo_, pnames)
|
2008-05-19 15:22:57 +02:00
|
|
|
% This function prints and saves posterior estimates after the mcmc
|
2017-05-16 15:10:20 +02:00
|
|
|
% (+updates of oo_ & TeX output).
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% estim_params_ [structure]
|
2008-09-03 18:05:35 +02:00
|
|
|
% M_ [structure]
|
|
|
|
% options_ [structure]
|
|
|
|
% bayestopt_ [structure]
|
|
|
|
% oo_ [structure]
|
2017-10-10 10:05:59 +02:00
|
|
|
% pnames [cell] cell of strings, names of the prior shapes available
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% oo_ [structure]
|
2008-05-19 15:22:57 +02:00
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% None.
|
2008-08-01 14:40:33 +02:00
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
% Copyright (C) 2006-2018 Dynare Team
|
2008-08-01 14:40:33 +02:00
|
|
|
%
|
|
|
|
% 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
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2008-05-19 15:22:57 +02:00
|
|
|
|
2011-02-10 17:23:22 +01:00
|
|
|
%if ~options_.mh_replic && options_.load_mh_file
|
2017-05-16 15:10:20 +02:00
|
|
|
% load([M_.fname '_results.mat'],'oo_');
|
2008-09-03 18:05:35 +02:00
|
|
|
%end
|
2008-05-19 15:22:57 +02:00
|
|
|
|
2010-01-05 11:46:10 +01:00
|
|
|
TeX = options_.TeX;
|
|
|
|
nblck = options_.mh_nblck;
|
|
|
|
nvx = estim_params_.nvx;
|
|
|
|
nvn = estim_params_.nvn;
|
|
|
|
ncx = estim_params_.ncx;
|
|
|
|
ncn = estim_params_.ncn;
|
|
|
|
np = estim_params_.np ;
|
|
|
|
nx = nvx+nvn+ncx+ncn+np;
|
2008-05-19 15:22:57 +02:00
|
|
|
|
2013-11-20 18:03:12 +01:00
|
|
|
MetropolisFolder = CheckPath('metropolis',M_.dname);
|
|
|
|
OutputFolder = CheckPath('Output',M_.dname);
|
2017-05-16 15:10:20 +02:00
|
|
|
FileName = M_.fname;
|
2013-11-20 18:03:12 +01:00
|
|
|
|
|
|
|
load_last_mh_history_file(MetropolisFolder,FileName);
|
2008-05-19 15:22:57 +02:00
|
|
|
|
|
|
|
FirstMhFile = record.KeepedDraws.FirstMhFile;
|
2008-09-02 12:00:15 +02:00
|
|
|
FirstLine = record.KeepedDraws.FirstLine;
|
2008-09-05 18:48:39 +02:00
|
|
|
TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
|
2008-05-19 15:22:57 +02:00
|
|
|
TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
|
|
|
|
FirstMhFile = record.KeepedDraws.FirstMhFile;
|
|
|
|
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
|
|
|
|
clear record;
|
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
header_width = row_header_width(M_, estim_params_, bayestopt_);
|
2013-09-16 17:11:25 +02:00
|
|
|
hpd_interval=[num2str(options_.mh_conf_sig*100), '% HPD interval'];
|
|
|
|
tit2 = sprintf('%-*s %12s %12s %23s %8s %12s\n',header_width,' ','prior mean','post. mean',hpd_interval,'prior','pstdev');
|
2021-08-16 14:50:34 +02:00
|
|
|
pformat = '%-*s %12.3f % 12.4f %11.4f %11.4f %8s %12.4f';
|
2008-05-19 15:22:57 +02:00
|
|
|
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline(2)
|
|
|
|
disp('ESTIMATION RESULTS')
|
|
|
|
skipline()
|
|
|
|
|
2008-09-03 18:05:35 +02:00
|
|
|
try
|
2017-10-10 10:05:59 +02:00
|
|
|
disp(sprintf('Log data density is %f.', oo_.MarginalDensity.ModifiedHarmonicMean))
|
2008-09-03 18:05:35 +02:00
|
|
|
catch
|
2015-09-25 18:23:21 +02:00
|
|
|
[marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_, bayestopt_);
|
2017-10-10 10:05:59 +02:00
|
|
|
disp(sprintf('Log data density is %f.', oo_.MarginalDensity.ModifiedHarmonicMean))
|
2008-09-03 18:05:35 +02:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
|
2014-08-09 10:37:16 +02:00
|
|
|
num_draws=NumberOfDraws*options_.mh_nblck;
|
2014-03-06 08:10:51 +01:00
|
|
|
hpd_draws = round((1-options_.mh_conf_sig)*num_draws);
|
2017-10-10 10:05:59 +02:00
|
|
|
|
2014-03-06 08:10:51 +01:00
|
|
|
if hpd_draws<2
|
|
|
|
fprintf('posterior_moments: There are not enough draws computes to compute HPD Intervals. Skipping their computation.\n')
|
|
|
|
end
|
|
|
|
if num_draws<9
|
|
|
|
fprintf('posterior_moments: There are not enough draws computes to compute deciles. Skipping their computation.\n')
|
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
if np
|
|
|
|
type = 'parameters';
|
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
fid = TeXBegin(OutputFolder, M_.fname, 1, type);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2008-05-19 15:22:57 +02:00
|
|
|
disp(type)
|
|
|
|
disp(tit2)
|
|
|
|
ip = nvx+nvn+ncx+ncn+1;
|
|
|
|
for i=1:np
|
2021-02-13 18:53:17 +01:00
|
|
|
if options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh)
|
2017-10-10 10:05:59 +02:00
|
|
|
Draws = GetAllPosteriorDraws(ip, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws);
|
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws, 1, options_.mh_conf_sig);
|
2008-05-19 15:22:57 +02:00
|
|
|
name = bayestopt_.name{ip};
|
2017-10-10 10:05:59 +02:00
|
|
|
oo_ = Filloo(oo_, name, type, post_mean, hpd_interval, post_median, post_var, post_deciles, density);
|
2008-05-19 15:22:57 +02:00
|
|
|
else
|
2008-09-03 18:05:35 +02:00
|
|
|
try
|
|
|
|
name = bayestopt_.name{ip};
|
2017-10-10 10:05:59 +02:00
|
|
|
[post_mean, hpd_interval, post_var] = Extractoo(oo_, name, type);
|
2008-09-03 18:05:35 +02:00
|
|
|
catch
|
2017-10-10 10:05:59 +02:00
|
|
|
Draws = GetAllPosteriorDraws(ip, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws);
|
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws, 1, options_.mh_conf_sig);
|
2008-09-03 18:05:35 +02:00
|
|
|
name = bayestopt_.name{ip};
|
2017-10-10 10:05:59 +02:00
|
|
|
oo_ = Filloo(oo_, name, type, post_mean, hpd_interval, post_median, post_var, post_deciles, density);
|
2008-09-03 18:05:35 +02:00
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
disp(sprintf(pformat, header_width, name, bayestopt_.p1(ip),...
|
2008-05-19 15:22:57 +02:00
|
|
|
post_mean, ...
|
|
|
|
hpd_interval, ...
|
2017-10-10 10:05:59 +02:00
|
|
|
pnames{bayestopt_.pshape(ip)+1}, ...
|
2017-05-16 15:10:20 +02:00
|
|
|
bayestopt_.p2(ip)));
|
2008-05-19 15:22:57 +02:00
|
|
|
if TeX
|
2012-05-30 11:22:59 +02:00
|
|
|
k = estim_params_.param_vals(i,1);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = M_.param_names_tex{k};
|
|
|
|
TeXCore(fid, name, pnames{bayestopt_.pshape(ip)+1}, bayestopt_.p1(ip), bayestopt_.p2(ip), post_mean, sqrt(post_var), hpd_interval);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
ip = ip+1;
|
|
|
|
end
|
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
TeXEnd(fid, 1, type);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
if nvx
|
|
|
|
type = 'shocks_std';
|
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
fid = TeXBegin(OutputFolder, FileName,2, 'standard deviation of structural shocks');
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
ip = 1;
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2008-05-19 15:22:57 +02:00
|
|
|
disp('standard deviation of shocks')
|
|
|
|
disp(tit2)
|
|
|
|
for i=1:nvx
|
2021-02-13 18:53:17 +01:00
|
|
|
if options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh)
|
2017-10-10 10:05:59 +02:00
|
|
|
Draws = GetAllPosteriorDraws(ip, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws);
|
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws, 1, options_.mh_conf_sig);
|
2008-05-19 15:22:57 +02:00
|
|
|
k = estim_params_.var_exo(i,1);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = M_.exo_names{k};
|
|
|
|
oo_ = Filloo(oo_, name, type, post_mean, hpd_interval, post_median, post_var, post_deciles, density);
|
2008-05-19 15:22:57 +02:00
|
|
|
M_.Sigma_e(k,k) = post_mean*post_mean;
|
|
|
|
else
|
2008-09-03 18:05:35 +02:00
|
|
|
try
|
|
|
|
k = estim_params_.var_exo(i,1);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = M_.exo_names{k};
|
|
|
|
[post_mean, hpd_interval, post_var] = Extractoo(oo_, name, type);
|
2008-09-03 18:05:35 +02:00
|
|
|
catch
|
2017-10-10 10:05:59 +02:00
|
|
|
Draws = GetAllPosteriorDraws(ip, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws);
|
2008-09-03 18:05:35 +02:00
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = ...
|
2017-10-10 10:05:59 +02:00
|
|
|
posterior_moments(Draws, 1, options_.mh_conf_sig);
|
2008-09-03 18:05:35 +02:00
|
|
|
k = estim_params_.var_exo(i,1);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = M_.exo_names{k};
|
|
|
|
oo_ = Filloo(oo_, name, type, post_mean, hpd_interval, post_median, post_var, post_deciles, density);
|
2008-09-03 18:05:35 +02:00
|
|
|
M_.Sigma_e(k,k) = post_mean*post_mean;
|
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
disp(sprintf(pformat,header_width,name, bayestopt_.p1(ip), post_mean, hpd_interval, pnames{bayestopt_.pshape(ip)+1}, bayestopt_.p2(ip)));
|
2017-05-16 12:42:01 +02:00
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
name = M_.exo_names_tex{k};
|
|
|
|
TeXCore(fid,name, pnames{bayestopt_.pshape(ip)+1}, bayestopt_.p1(ip), bayestopt_.p2(ip), post_mean, sqrt(post_var), hpd_interval);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
ip = ip+1;
|
|
|
|
end
|
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
TeXEnd(fid, 2, 'standard deviation of structural shocks');
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
if nvn
|
|
|
|
type = 'measurement_errors_std';
|
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
fid = TeXBegin(OutputFolder, FileName, 3, 'standard deviation of measurement errors');
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2008-05-19 15:22:57 +02:00
|
|
|
disp('standard deviation of measurement errors')
|
|
|
|
disp(tit2)
|
|
|
|
ip = nvx+1;
|
|
|
|
for i=1:nvn
|
2021-02-13 18:53:17 +01:00
|
|
|
if options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh)
|
2017-10-10 10:05:59 +02:00
|
|
|
Draws = GetAllPosteriorDraws(ip, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws);
|
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws, 1, options_.mh_conf_sig);
|
2013-05-21 16:38:17 +02:00
|
|
|
name = options_.varobs{estim_params_.nvn_observable_correspondence(i,1)};
|
2017-10-10 10:05:59 +02:00
|
|
|
oo_ = Filloo(oo_, name, type, post_mean, hpd_interval, post_median, post_var, post_deciles, density);
|
2008-05-19 15:22:57 +02:00
|
|
|
else
|
2008-09-03 18:05:35 +02:00
|
|
|
try
|
2013-05-21 16:38:17 +02:00
|
|
|
name = options_.varobs{estim_params_.nvn_observable_correspondence(i,1)};
|
2008-09-03 18:05:35 +02:00
|
|
|
[post_mean,hpd_interval,post_var] = Extractoo(oo_,name,type);
|
|
|
|
catch
|
|
|
|
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
2017-10-10 10:05:59 +02:00
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1,options_.mh_conf_sig);
|
2013-05-21 16:38:17 +02:00
|
|
|
name = options_.varobs{estim_params_.nvn_observable_correspondence(i,1)};
|
2008-09-03 18:05:35 +02:00
|
|
|
oo_ = Filloo(oo_,name,type,post_mean,hpd_interval,post_median,post_var,post_deciles,density);
|
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
disp(sprintf(pformat, header_width, name,bayestopt_.p1(ip), post_mean, hpd_interval, pnames{bayestopt_.pshape(ip)+1}, bayestopt_.p2(ip)));
|
2008-05-19 15:22:57 +02:00
|
|
|
if TeX
|
2012-05-30 11:22:59 +02:00
|
|
|
k = estim_params_.var_endo(i,1);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = M_.endo_names_tex{k};
|
|
|
|
TeXCore(fid, name, pnames{bayestopt_.pshape(ip)+1}, bayestopt_.p1(ip), bayestopt_.p2(ip), post_mean, sqrt(post_var), hpd_interval);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
ip = ip+1;
|
|
|
|
end
|
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
TeXEnd(fid, 3, 'standard deviation of measurement errors');
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
if ncx
|
|
|
|
type = 'shocks_corr';
|
|
|
|
if TeX
|
2013-11-20 18:03:12 +01:00
|
|
|
fid = TeXBegin(OutputFolder,FileName,4,'correlation of structural shocks');
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2008-05-19 15:22:57 +02:00
|
|
|
disp('correlation of shocks')
|
|
|
|
disp(tit2)
|
|
|
|
ip = nvx+nvn+1;
|
|
|
|
for i=1:ncx
|
2021-02-13 18:53:17 +01:00
|
|
|
if options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh)
|
2017-10-10 10:05:59 +02:00
|
|
|
Draws = GetAllPosteriorDraws(ip, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws);
|
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1,options_.mh_conf_sig);
|
2008-05-19 15:22:57 +02:00
|
|
|
k1 = estim_params_.corrx(i,1);
|
|
|
|
k2 = estim_params_.corrx(i,2);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s,%s', M_.exo_names{k1}, M_.exo_names{k2});
|
|
|
|
NAME = sprintf('%s_%s', M_.exo_names{k1}, M_.exo_names{k2});
|
|
|
|
oo_ = Filloo(oo_, NAME, type, post_mean, hpd_interval, post_median, post_var, post_deciles, density);
|
2008-05-19 15:22:57 +02:00
|
|
|
M_.Sigma_e(k1,k2) = post_mean*sqrt(M_.Sigma_e(k1,k1)*M_.Sigma_e(k2,k2));
|
|
|
|
M_.Sigma_e(k2,k1) = M_.Sigma_e(k1,k2);
|
|
|
|
else
|
2008-09-03 18:05:35 +02:00
|
|
|
try
|
|
|
|
k1 = estim_params_.corrx(i,1);
|
|
|
|
k2 = estim_params_.corrx(i,2);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s,%s', M_.exo_names{k1}, M_.exo_names{k2});
|
|
|
|
NAME = sprintf('%s_%s', M_.exo_names{k1}, M_.exo_names{k2});
|
|
|
|
[post_mean,hpd_interval,post_var] = Extractoo(oo_, NAME, type);
|
2008-09-03 18:05:35 +02:00
|
|
|
catch
|
2017-10-10 10:05:59 +02:00
|
|
|
Draws = GetAllPosteriorDraws(ip, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws);
|
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws, 1, options_.mh_conf_sig);
|
2008-09-03 18:05:35 +02:00
|
|
|
k1 = estim_params_.corrx(i,1);
|
|
|
|
k2 = estim_params_.corrx(i,2);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s,%s', M_.exo_names{k1}, M_.exo_names{k2});
|
|
|
|
NAME = sprintf('%s_%s', M_.exo_names{k1}, M_.exo_names{k2});
|
|
|
|
oo_ = Filloo(oo_, NAME, type, post_mean, hpd_interval, post_median, post_var, post_deciles, density);
|
2008-09-03 18:05:35 +02:00
|
|
|
M_.Sigma_e(k1,k2) = post_mean*sqrt(M_.Sigma_e(k1,k1)*M_.Sigma_e(k2,k2));
|
|
|
|
M_.Sigma_e(k2,k1) = M_.Sigma_e(k1,k2);
|
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
disp(sprintf(pformat, header_width,name, bayestopt_.p1(ip), post_mean, hpd_interval, pnames{bayestopt_.pshape(ip)+1}, bayestopt_.p2(ip)));
|
2008-05-19 15:22:57 +02:00
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('(%s,%s)', M_.exo_names_tex{k1}, M_.exo_names_tex{k2});
|
|
|
|
TeXCore(fid, name, pnames{bayestopt_.pshape(ip)+1}, bayestopt_.p1(ip), bayestopt_.p2(ip), post_mean, sqrt(post_var), hpd_interval);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
ip = ip+1;
|
|
|
|
end
|
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
TeXEnd(fid, 4, 'correlation of structural shocks');
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if ncn
|
|
|
|
type = 'measurement_errors_corr';
|
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
fid = TeXBegin(OutputFolder, FileName, 5, 'correlation of measurement errors');
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2013-07-10 17:12:34 +02:00
|
|
|
skipline()
|
2008-05-19 15:22:57 +02:00
|
|
|
disp('correlation of measurement errors')
|
|
|
|
disp(tit2)
|
|
|
|
ip = nvx+nvn+ncx+1;
|
|
|
|
for i=1:ncn
|
2021-02-13 18:53:17 +01:00
|
|
|
if options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh)
|
2008-05-19 15:22:57 +02:00
|
|
|
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
2017-10-10 10:05:59 +02:00
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws, 1, options_.mh_conf_sig);
|
2008-05-19 15:22:57 +02:00
|
|
|
k1 = estim_params_.corrn(i,1);
|
|
|
|
k2 = estim_params_.corrn(i,2);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s,%s', M_.endo_names{k1}, M_.endo_names{k2});
|
|
|
|
NAME = sprintf('%s_%s', M_.endo_names{k1}, M_.endo_names{k2});
|
|
|
|
oo_ = Filloo(oo_, NAME, type, post_mean, hpd_interval, post_median, post_var, post_deciles,density);
|
2008-05-19 15:22:57 +02:00
|
|
|
else
|
2008-09-03 18:05:35 +02:00
|
|
|
try
|
|
|
|
k1 = estim_params_.corrn(i,1);
|
|
|
|
k2 = estim_params_.corrn(i,2);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s,%s', M_.endo_names{k1}, M_.endo_names{k2});
|
|
|
|
NAME = sprintf('%s_%s', M_.endo_names{k1}, M_.endo_names{k2});
|
|
|
|
[post_mean,hpd_interval,post_var] = Extractoo(oo_, NAME, type);
|
2008-09-03 18:05:35 +02:00
|
|
|
catch
|
2017-10-10 10:05:59 +02:00
|
|
|
Draws = GetAllPosteriorDraws(ip, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws);
|
|
|
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws, 1, options_.mh_conf_sig);
|
2008-09-03 18:05:35 +02:00
|
|
|
k1 = estim_params_.corrn(i,1);
|
|
|
|
k2 = estim_params_.corrn(i,2);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s,%s', M_.endo_names{k1}, M_.endo_names{k2});
|
|
|
|
NAME = sprintf('%s_%s', M_.endo_names{k1}, M_.endo_names{k2});
|
|
|
|
oo_ = Filloo(oo_, NAME, type, post_mean, hpd_interval, post_median, post_var, post_deciles, density);
|
2008-09-03 18:05:35 +02:00
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
disp(sprintf(pformat, header_width, name, bayestopt_.p1(ip), post_mean, hpd_interval, pnames{bayestopt_.pshape(ip)+1}, bayestopt_.p2(ip)));
|
2017-05-16 12:42:01 +02:00
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('(%s,%s)', M_.endo_names_tex{k1}, M_.endo_names_tex{k2});
|
|
|
|
TeXCore(fid, name, pnames{bayestopt_.pshape(ip)+1}, bayestopt_.p1(ip), bayestopt_.p2(ip), post_mean, sqrt(post_var), hpd_interval);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
ip = ip+1;
|
|
|
|
end
|
|
|
|
if TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
TeXEnd(fid, 5, 'correlation of measurement errors');
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
%
|
|
|
|
%% subfunctions:
|
|
|
|
%
|
2017-10-10 10:05:59 +02:00
|
|
|
function fid = TeXBegin(directory, fname, fnum, title)
|
2016-06-14 09:48:35 +02:00
|
|
|
TeXfile = [directory '/' fname '_Posterior_Mean_' int2str(fnum) '.tex'];
|
2009-12-16 18:17:34 +01:00
|
|
|
fidTeX = fopen(TeXfile,'w');
|
2017-10-10 10:05:59 +02:00
|
|
|
fprintf(fidTeX, '%% TeX-table generated by Dynare.\n');
|
|
|
|
fprintf(fidTeX, ['%% RESULTS FROM METROPOLIS HASTINGS (' title ')\n']);
|
|
|
|
fprintf(fidTeX, ['%% ' datestr(now, 0)]);
|
|
|
|
fprintf(fidTeX, ' \n');
|
|
|
|
fprintf(fidTeX, ' \n');
|
|
|
|
fprintf(fidTeX, '\\begin{center}\n');
|
|
|
|
fprintf(fidTeX, '\\begin{longtable}{llcccccc} \n');
|
|
|
|
fprintf(fidTeX, ['\\caption{Results from Metropolis-Hastings (' title ')}\n ']);
|
|
|
|
fprintf(fidTeX, ['\\label{Table:MHPosterior:' int2str(fnum) '}\\\\\n']);
|
|
|
|
fprintf(fidTeX, '\\toprule \n');
|
|
|
|
fprintf(fidTeX, ' & \\multicolumn{3}{c}{Prior} & \\multicolumn{4}{c}{Posterior} \\\\\n');
|
|
|
|
fprintf(fidTeX, ' \\cmidrule(r{.75em}){2-4} \\cmidrule(r{.75em}){5-8}\n');
|
|
|
|
fprintf(fidTeX, ' & Dist. & Mean & Stdev. & Mean & Stdev. & HPD inf & HPD sup\\\\\n');
|
|
|
|
fprintf(fidTeX, '\\midrule \\endfirsthead \n');
|
|
|
|
fprintf(fidTeX, ['\\caption{(continued)}\\\\']);
|
|
|
|
fprintf(fidTeX, '\\toprule \n');
|
|
|
|
fprintf(fidTeX, ' & \\multicolumn{3}{c}{Prior} & \\multicolumn{4}{c}{Posterior} \\\\\n');
|
|
|
|
fprintf(fidTeX, ' \\cmidrule(r{.75em}){2-4} \\cmidrule(r{.75em}){5-8}\n');
|
|
|
|
fprintf(fidTeX, ' & Dist. & Mean & Stdev. & Mean & Stdev. & HPD inf & HPD sup\\\\\n');
|
|
|
|
fprintf(fidTeX, '\\midrule \\endhead \n');
|
2012-05-30 11:22:59 +02:00
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
fprintf(fidTeX, '\\bottomrule \\multicolumn{8}{r}{(Continued on next page)} \\endfoot \n');
|
|
|
|
fprintf(fidTeX, '\\bottomrule \\endlastfoot \n');
|
2012-05-30 11:22:59 +02:00
|
|
|
|
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
fid = fidTeX;
|
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
function TeXCore(fid, name, shape, priormean, priorstd, postmean, poststd, hpd)
|
2017-05-16 15:10:20 +02:00
|
|
|
fprintf(fid,['$%s$ & %s & %7.3f & %6.4f & %7.3f& %6.4f & %7.4f & %7.4f \\\\ \n'],...
|
2017-10-10 10:05:59 +02:00
|
|
|
name, ...
|
|
|
|
shape, ...
|
|
|
|
priormean, ...
|
|
|
|
priorstd, ...
|
|
|
|
postmean, ...
|
|
|
|
poststd, ...
|
|
|
|
hpd(1), ...
|
2009-12-16 18:17:34 +01:00
|
|
|
hpd(2));
|
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
function TeXEnd(fid, fnum, title)
|
|
|
|
fprintf(fid, '\\end{longtable}\n ');
|
|
|
|
fprintf(fid, '\\end{center}\n');
|
|
|
|
fprintf(fid, '%% End of TeX file.\n');
|
2009-12-16 18:17:34 +01:00
|
|
|
fclose(fid);
|
|
|
|
|
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
function oo = Filloo(oo, name, type, postmean, hpdinterval, postmedian, postvar, postdecile, density)
|
2015-08-25 09:45:39 +02:00
|
|
|
oo.posterior_mean.(type).(name) = postmean;
|
|
|
|
oo.posterior_hpdinf.(type).(name) = hpdinterval(1);
|
|
|
|
oo.posterior_hpdsup.(type).(name) = hpdinterval(2);
|
|
|
|
oo.posterior_median.(type).(name) = postmedian;
|
|
|
|
oo.posterior_variance.(type).(name) = postvar;
|
|
|
|
oo.posterior_std.(type).(name) = sqrt(postvar);
|
|
|
|
oo.posterior_deciles.(type).(name) = postdecile;
|
|
|
|
oo.posterior_density.(type).(name) = density;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
function [post_mean,hpd_interval,post_var] = Extractoo(oo, name, type)
|
2009-12-16 18:17:34 +01:00
|
|
|
hpd_interval = zeros(2,1);
|
2015-08-25 09:45:39 +02:00
|
|
|
post_mean = oo.posterior_mean.(type).(name);
|
2015-10-12 15:20:15 +02:00
|
|
|
hpd_interval(1) = oo.posterior_hpdinf.(type).(name);
|
2015-08-25 09:45:39 +02:00
|
|
|
hpd_interval(2) = oo.posterior_hpdsup.(type).(name);
|
|
|
|
post_var = oo.posterior_variance.(type).(name);
|