Changed posterior_moments (global variable options_ is not needed anymore, mh_conf_sig is a new input argument) + Cosmetic changes.
git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1836 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
f85752893e
commit
de48d0b3ee
|
@ -1,288 +1,290 @@
|
||||||
function get_posterior_parameters_statistics()
|
function get_posterior_parameters_statistics()
|
||||||
|
% This function prints and saves posterior estimates after the mcmc
|
||||||
% function get_posterior_parameters_statistics()
|
% (+updates of oo_ & TeX output).
|
||||||
% This function prints and saves posterior estimates after the mcmc
|
%
|
||||||
% (+updates of oo_ & TeX output).
|
% INPUTS
|
||||||
%
|
% None.
|
||||||
% INPUTS
|
%
|
||||||
% None.
|
% OUTPUTS
|
||||||
%
|
% None.
|
||||||
% OUTPUTS
|
%
|
||||||
% None.
|
% SPECIAL REQUIREMENTS
|
||||||
%
|
% None.
|
||||||
% SPECIAL REQUIREMENTS
|
%
|
||||||
% None.
|
% part of DYNARE, copyright Dynare Team (2006-2008)
|
||||||
%
|
% Gnu Public License.
|
||||||
% part of DYNARE, copyright Dynare Team (2006-2008)
|
|
||||||
% Gnu Public License.
|
global estim_params_ M_ options_ bayestopt_ oo_
|
||||||
|
|
||||||
global estim_params_ M_ options_ bayestopt_ oo_
|
if ~options_.mh_replic & options_.load_mh_file
|
||||||
|
load([M_.fname '_results.mat'],'oo_');
|
||||||
if ~options_.mh_replic & options_.load_mh_file
|
end
|
||||||
load([M_.fname '_results.mat'],'oo_');
|
|
||||||
end
|
TeX = options_.TeX;
|
||||||
|
nblck = options_.mh_nblck;
|
||||||
TeX = options_.TeX;
|
nvx = estim_params_.nvx;
|
||||||
nblck = options_.mh_nblck;
|
nvn = estim_params_.nvn;
|
||||||
nvx = estim_params_.nvx;
|
ncx = estim_params_.ncx;
|
||||||
nvn = estim_params_.nvn;
|
ncn = estim_params_.ncn;
|
||||||
ncx = estim_params_.ncx;
|
np = estim_params_.np ;
|
||||||
ncn = estim_params_.ncn;
|
nx = nvx+nvn+ncx+ncn+np;
|
||||||
np = estim_params_.np ;
|
|
||||||
nx = nvx+nvn+ncx+ncn+np;
|
DirectoryName = CheckPath('metropolis');
|
||||||
|
OutputDirectoryName = CheckPath('Output');
|
||||||
DirectoryName = CheckPath('metropolis');
|
|
||||||
OutputDirectoryName = CheckPath('Output');
|
load([ DirectoryName '/' M_.fname '_mh_history'])
|
||||||
|
FirstMhFile = record.KeepedDraws.FirstMhFile;
|
||||||
load([ DirectoryName '/' M_.fname '_mh_history'])
|
FirstLine = record.KeepedDraws.FirstLine; ifil = FirstLine;
|
||||||
FirstMhFile = record.KeepedDraws.FirstMhFile;
|
TotalNumberOfMhFiles = sum(record.MhDraws(:,2))
|
||||||
FirstLine = record.KeepedDraws.FirstLine; ifil = FirstLine;
|
TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
|
||||||
TotalNumberOfMhFiles = sum(record.MhDraws(:,2))
|
FirstMhFile = record.KeepedDraws.FirstMhFile;
|
||||||
TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
|
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
|
||||||
FirstMhFile = record.KeepedDraws.FirstMhFile;
|
clear record;
|
||||||
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
|
|
||||||
clear record;
|
pnames=[' ';'beta ';'gamm ';'norm ';'invg ';'unif ';'invg2'];
|
||||||
|
tit2 = sprintf('%10s %7s %10s %14s %4s %6s\n',' ','prior mean','post. mean','conf. interval','prior','pstdev');
|
||||||
pnames=[' ';'beta ';'gamm ';'norm ';'invg ';'unif ';'invg2'];
|
pformat = '%12s %7.3f %8.4f %7.4f %7.4f %4s %6.4f';
|
||||||
tit2 = sprintf('%10s %7s %10s %14s %4s %6s\n',' ','prior mean','post. mean','conf. interval','prior','pstdev');
|
|
||||||
pformat = '%12s %7.3f %8.4f %7.4f %7.4f %4s %6.4f';
|
disp(' ');disp(' ');disp('ESTIMATION RESULTS');disp(' ');
|
||||||
|
disp(sprintf('Log data density is %f.',oo_.MarginalDensity.ModifiedHarmonicMean))
|
||||||
disp(' ');disp(' ');disp('ESTIMATION RESULTS');disp(' ');
|
if np
|
||||||
disp(sprintf('Log data density is %f.',oo_.MarginalDensity.ModifiedHarmonicMean))
|
type = 'parameters';
|
||||||
if np
|
if TeX
|
||||||
type = 'parameters';
|
fid = TeXBegin(OutputDirectoryName,M_.fname,1,type);
|
||||||
if TeX
|
end
|
||||||
fid = TeXBegin(OutputDirectoryName,M_.fname,1,type);
|
disp(' ')
|
||||||
end
|
disp(type)
|
||||||
disp(' ')
|
disp(tit2)
|
||||||
disp(type)
|
ip = nvx+nvn+ncx+ncn+1;
|
||||||
disp(tit2)
|
for i=1:np
|
||||||
ip = nvx+nvn+ncx+ncn+1;
|
if options_.mh_replic
|
||||||
for i=1:np
|
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
||||||
if options_.mh_replic
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, ...
|
||||||
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
density] = posterior_moments(Draws,1,options_.mh_conf_sig);
|
||||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, ...
|
name = bayestopt_.name{ip};
|
||||||
density] = posterior_moments(Draws,1);
|
oo_ = Filloo(oo_,name,type,post_mean,hpd_interval,post_median,post_var,post_deciles,density);
|
||||||
name = bayestopt_.name{ip};
|
else
|
||||||
oo_ = Filloo(oo_,name,type,post_mean,hpd_interval,post_median,post_var,post_deciles,density);
|
name = bayestopt_.name{ip};
|
||||||
else
|
[post_mean,hpd_interval,post_var] = Extractoo(oo_,name,type);
|
||||||
name = bayestopt_.name{ip};
|
end
|
||||||
[post_mean,hpd_interval,post_var] = Extractoo(oo_,name,type);
|
disp(sprintf(pformat,name,bayestopt_.pmean(ip),...
|
||||||
end
|
post_mean, ...
|
||||||
disp(sprintf(pformat,name,bayestopt_.pmean(ip),...
|
hpd_interval, ...
|
||||||
post_mean, ...
|
pnames(bayestopt_.pshape(ip)+1,:), ...
|
||||||
hpd_interval, ...
|
bayestopt_.pstdev(ip)));
|
||||||
pnames(bayestopt_.pshape(ip)+1,:), ...
|
if TeX
|
||||||
bayestopt_.pstdev(ip)));
|
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
||||||
if TeX
|
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
||||||
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
end
|
||||||
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
ip = ip+1;
|
||||||
end
|
end
|
||||||
ip = ip+1;
|
if TeX
|
||||||
end
|
TeXEnd(fid,1,type);
|
||||||
if TeX
|
end
|
||||||
TeXEnd(fid,1,type);
|
end
|
||||||
end
|
if nvx
|
||||||
end
|
type = 'shocks_std';
|
||||||
if nvx
|
if TeX
|
||||||
type = 'shocks_std';
|
fid = TeXBegin(OutputDirectoryName,M_.fname,2,'standard deviation of structural shocks');
|
||||||
if TeX
|
end
|
||||||
fid = TeXBegin(OutputDirectoryName,M_.fname,2,'standard deviation of structural shocks');
|
ip = 1;
|
||||||
end
|
disp(' ')
|
||||||
ip = 1;
|
disp('standard deviation of shocks')
|
||||||
disp(' ')
|
disp(tit2)
|
||||||
disp('standard deviation of shocks')
|
for i=1:nvx
|
||||||
disp(tit2)
|
if options_.mh_replic
|
||||||
for i=1:nvx
|
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
||||||
if options_.mh_replic
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = ...
|
||||||
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
posterior_moments(Draws,1,options_.mh_conf_sig);
|
||||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
|
k = estim_params_.var_exo(i,1);
|
||||||
k = estim_params_.var_exo(i,1);
|
name = deblank(M_.exo_names(k,:));
|
||||||
name = deblank(M_.exo_names(k,:));
|
oo_ = Filloo(oo_,name,type,post_mean,hpd_interval,post_median,post_var,post_deciles,density);
|
||||||
oo_ = Filloo(oo_,name,type,post_mean,hpd_interval,post_median,post_var,post_deciles,density);
|
M_.Sigma_e(k,k) = post_mean*post_mean;
|
||||||
M_.Sigma_e(k,k) = post_mean*post_mean;
|
else
|
||||||
else
|
k = estim_params_.var_exo(i,1);
|
||||||
k = estim_params_.var_exo(i,1);
|
name = deblank(M_.exo_names(k,:));
|
||||||
name = deblank(M_.exo_names(k,:));
|
[post_mean,hpd_interval,post_var] = Extractoo(oo_,name,type);
|
||||||
[post_mean,hpd_interval,post_var] = Extractoo(oo_,name,type);
|
end
|
||||||
end
|
disp(sprintf(pformat,name,bayestopt_.pmean(ip),post_mean,hpd_interval,...
|
||||||
disp(sprintf(pformat,name,bayestopt_.pmean(ip),post_mean,hpd_interval,...
|
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
|
||||||
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
|
if TeX
|
||||||
if TeX
|
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
||||||
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
||||||
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
end
|
||||||
end
|
ip = ip+1;
|
||||||
ip = ip+1;
|
end
|
||||||
end
|
if TeX
|
||||||
if TeX
|
TeXEnd(fid,2,'standard deviation of structural shocks');
|
||||||
TeXEnd(fid,2,'standard deviation of structural shocks');
|
end
|
||||||
end
|
end
|
||||||
end
|
if nvn
|
||||||
if nvn
|
type = 'measurement_errors_std';
|
||||||
type = 'measurement_errors_std';
|
if TeX
|
||||||
if TeX
|
fid = TeXBegin(OutputDirectoryName,M_.fname,3,'standard deviation of measurement errors')
|
||||||
fid = TeXBegin(OutputDirectoryName,M_.fname,3,'standard deviation of measurement errors')
|
end
|
||||||
end
|
disp(' ')
|
||||||
disp(' ')
|
disp('standard deviation of measurement errors')
|
||||||
disp('standard deviation of measurement errors')
|
disp(tit2)
|
||||||
disp(tit2)
|
ip = nvx+1;
|
||||||
ip = nvx+1;
|
for i=1:nvn
|
||||||
for i=1:nvn
|
if options_.mh_replic
|
||||||
if options_.mh_replic
|
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
||||||
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = ...
|
||||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
|
posterior_moments(Draws,1,options_.mh_conf_sig);
|
||||||
name = deblank(options_.varobs(estim_params_.var_endo(i,1),:));
|
name = deblank(options_.varobs(estim_params_.var_endo(i,1),:));
|
||||||
oo_ = Filloo(oo_,name,type,post_mean,hpd_interval,post_median,post_var,post_deciles,density);
|
oo_ = Filloo(oo_,name,type,post_mean,hpd_interval,post_median,post_var,post_deciles,density);
|
||||||
else
|
else
|
||||||
name = deblank(options_.varobs(estim_params_.var_endo(i,1),:));
|
name = deblank(options_.varobs(estim_params_.var_endo(i,1),:));
|
||||||
[post_mean,hpd_interval,post_var] = Extractoo(oo_,name,type);
|
[post_mean,hpd_interval,post_var] = Extractoo(oo_,name,type);
|
||||||
end
|
end
|
||||||
disp(sprintf(pformat,name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
|
disp(sprintf(pformat,name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
|
||||||
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
|
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
|
||||||
if TeX
|
if TeX
|
||||||
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
||||||
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
||||||
end
|
end
|
||||||
ip = ip+1;
|
ip = ip+1;
|
||||||
end
|
end
|
||||||
if TeX
|
if TeX
|
||||||
TeXEnd(fid,3,'standard deviation of measurement errors');
|
TeXEnd(fid,3,'standard deviation of measurement errors');
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if ncx
|
if ncx
|
||||||
type = 'shocks_corr';
|
type = 'shocks_corr';
|
||||||
if TeX
|
if TeX
|
||||||
fid = TeXBegin(OutputDirectoryName,M_.fname,4,'correlation of structural shocks');
|
fid = TeXBegin(OutputDirectoryName,M_.fname,4,'correlation of structural shocks');
|
||||||
end
|
end
|
||||||
disp(' ')
|
disp(' ')
|
||||||
disp('correlation of shocks')
|
disp('correlation of shocks')
|
||||||
disp(tit2)
|
disp(tit2)
|
||||||
ip = nvx+nvn+1;
|
ip = nvx+nvn+1;
|
||||||
for i=1:ncx
|
for i=1:ncx
|
||||||
if options_.mh_replic
|
if options_.mh_replic
|
||||||
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
||||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = ...
|
||||||
k1 = estim_params_.corrx(i,1);
|
posterior_moments(Draws,1,options_.mh_conf_sig);
|
||||||
k2 = estim_params_.corrx(i,2);
|
k1 = estim_params_.corrx(i,1);
|
||||||
name = [deblank(M_.exo_names(k1,:)) ',' deblank(M_.exo_names(k2,:))];
|
k2 = estim_params_.corrx(i,2);
|
||||||
NAME = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))];
|
name = [deblank(M_.exo_names(k1,:)) ',' deblank(M_.exo_names(k2,:))];
|
||||||
oo_ = Filloo(oo_,NAME,type,post_mean,hpd_interval,post_median,post_var,post_deciles,density);
|
NAME = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))];
|
||||||
M_.Sigma_e(k1,k2) = post_mean*sqrt(M_.Sigma_e(k1,k1)*M_.Sigma_e(k2,k2));
|
oo_ = Filloo(oo_,NAME,type,post_mean,hpd_interval,post_median,post_var,post_deciles,density);
|
||||||
M_.Sigma_e(k2,k1) = M_.Sigma_e(k1,k2);
|
M_.Sigma_e(k1,k2) = post_mean*sqrt(M_.Sigma_e(k1,k1)*M_.Sigma_e(k2,k2));
|
||||||
else
|
M_.Sigma_e(k2,k1) = M_.Sigma_e(k1,k2);
|
||||||
k1 = estim_params_.corrx(i,1);
|
else
|
||||||
k2 = estim_params_.corrx(i,2);
|
k1 = estim_params_.corrx(i,1);
|
||||||
name = [deblank(M_.exo_names(k1,:)) ',' deblank(M_.exo_names(k2,:))];
|
k2 = estim_params_.corrx(i,2);
|
||||||
NAME = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))];
|
name = [deblank(M_.exo_names(k1,:)) ',' deblank(M_.exo_names(k2,:))];
|
||||||
[post_mean,hpd_interval,post_var] = Extractoo(oo_,NAME,type);
|
NAME = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))];
|
||||||
end
|
[post_mean,hpd_interval,post_var] = Extractoo(oo_,NAME,type);
|
||||||
disp(sprintf(pformat, name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
|
end
|
||||||
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
|
disp(sprintf(pformat, name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
|
||||||
if TeX
|
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
|
||||||
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
if TeX
|
||||||
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
||||||
end
|
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
||||||
ip = ip+1;
|
end
|
||||||
end
|
ip = ip+1;
|
||||||
if TeX
|
end
|
||||||
TeXEnd(fid,4,'correlation of structural shocks');
|
if TeX
|
||||||
end
|
TeXEnd(fid,4,'correlation of structural shocks');
|
||||||
end
|
end
|
||||||
if ncn
|
end
|
||||||
type = 'measurement_errors_corr';
|
if ncn
|
||||||
if TeX
|
type = 'measurement_errors_corr';
|
||||||
fid = TeXBegin(OutputDirectoryName,M_.fname,5,'correlation of measurement errors');
|
if TeX
|
||||||
end
|
fid = TeXBegin(OutputDirectoryName,M_.fname,5,'correlation of measurement errors');
|
||||||
disp(' ')
|
end
|
||||||
disp('correlation of measurement errors')
|
disp(' ')
|
||||||
disp(tit2)
|
disp('correlation of measurement errors')
|
||||||
ip = nvx+nvn+ncx+1;
|
disp(tit2)
|
||||||
for i=1:ncn
|
ip = nvx+nvn+ncx+1;
|
||||||
if options_.mh_replic
|
for i=1:ncn
|
||||||
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
if options_.mh_replic
|
||||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
|
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
|
||||||
k1 = estim_params_.corrn(i,1);
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = ...
|
||||||
k2 = estim_params_.corrn(i,2);
|
posterior_moments(Draws,1,options_.mh_conf_sig);
|
||||||
name = [deblank(M_.endo_names(k1,:)) ',' deblank(M_.endo_names(k2,:))];
|
k1 = estim_params_.corrn(i,1);
|
||||||
NAME = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))];
|
k2 = estim_params_.corrn(i,2);
|
||||||
oo_ = Filloo(oo_,NAME,type,post_mean,hpd_interval,...
|
name = [deblank(M_.endo_names(k1,:)) ',' deblank(M_.endo_names(k2,:))];
|
||||||
post_median,post_var,post_deciles,density);
|
NAME = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))];
|
||||||
else
|
oo_ = Filloo(oo_,NAME,type,post_mean,hpd_interval,...
|
||||||
k1 = estim_params_.corrn(i,1);
|
post_median,post_var,post_deciles,density);
|
||||||
k2 = estim_params_.corrn(i,2);
|
else
|
||||||
name = [deblank(M_.endo_names(k1,:)) ',' deblank(M_.endo_names(k2,:))];
|
k1 = estim_params_.corrn(i,1);
|
||||||
NAME = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))];
|
k2 = estim_params_.corrn(i,2);
|
||||||
[post_mean,hpd_interval,post_var] = Extractoo(oo_,NAME,type);
|
name = [deblank(M_.endo_names(k1,:)) ',' deblank(M_.endo_names(k2,:))];
|
||||||
end
|
NAME = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))];
|
||||||
disp(sprintf(pformat, name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
|
[post_mean,hpd_interval,post_var] = Extractoo(oo_,NAME,type);
|
||||||
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
|
end
|
||||||
if TeX
|
disp(sprintf(pformat, name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
|
||||||
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
|
||||||
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
if TeX
|
||||||
end
|
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
|
||||||
ip = ip+1;
|
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
|
||||||
end
|
end
|
||||||
if TeX
|
ip = ip+1;
|
||||||
TeXEnd(fid,5,'correlation of measurement errors');
|
end
|
||||||
end
|
if TeX
|
||||||
end
|
TeXEnd(fid,5,'correlation of measurement errors');
|
||||||
|
end
|
||||||
|
end
|
||||||
%
|
|
||||||
%% subfunctions:
|
|
||||||
%
|
%
|
||||||
function fid = TeXBegin(directory,fname,fnum,title)
|
%% subfunctions:
|
||||||
TeXfile = [directory '/' fname '_Posterior_Mean_' int2str(fnum) '.TeX'];
|
%
|
||||||
fidTeX = fopen(TeXfile,'w');
|
function fid = TeXBegin(directory,fname,fnum,title)
|
||||||
fprintf(fidTeX,'%% TeX-table generated by Dynare.\n');
|
TeXfile = [directory '/' fname '_Posterior_Mean_' int2str(fnum) '.TeX'];
|
||||||
fprintf(fidTeX,['%% RESULTS FROM METROPOLIS HASTINGS (' title ')\n']);
|
fidTeX = fopen(TeXfile,'w');
|
||||||
fprintf(fidTeX,['%% ' datestr(now,0)]);
|
fprintf(fidTeX,'%% TeX-table generated by Dynare.\n');
|
||||||
fprintf(fidTeX,' \n');
|
fprintf(fidTeX,['%% RESULTS FROM METROPOLIS HASTINGS (' title ')\n']);
|
||||||
fprintf(fidTeX,' \n');
|
fprintf(fidTeX,['%% ' datestr(now,0)]);
|
||||||
fprintf(fidTeX,'\\begin{table}\n');
|
fprintf(fidTeX,' \n');
|
||||||
fprintf(fidTeX,'\\centering\n');
|
fprintf(fidTeX,' \n');
|
||||||
fprintf(fidTeX,'\\begin{tabular}{l|lcccccc} \n');
|
fprintf(fidTeX,'\\begin{table}\n');
|
||||||
fprintf(fidTeX,'\\hline\\hline \\\\ \n');
|
fprintf(fidTeX,'\\centering\n');
|
||||||
fprintf(fidTeX,[' & Prior distribution & Prior mean & Prior ' ...
|
fprintf(fidTeX,'\\begin{tabular}{l|lcccccc} \n');
|
||||||
's.d. & Posterior mean & Posterior s.d. & HPD inf & HPD sup\\\\ \n']);
|
fprintf(fidTeX,'\\hline\\hline \\\\ \n');
|
||||||
fprintf(fidTeX,'\\hline \\\\ \n');
|
fprintf(fidTeX,[' & Prior distribution & Prior mean & Prior ' ...
|
||||||
fid = fidTeX;
|
's.d. & Posterior mean & Posterior s.d. & HPD inf & HPD sup\\\\ \n']);
|
||||||
|
fprintf(fidTeX,'\\hline \\\\ \n');
|
||||||
|
fid = fidTeX;
|
||||||
function TeXCore(fid,name,shape,priormean,priorstd,postmean,poststd,hpd)
|
|
||||||
fprintf(fid,['$%s$ & %s & %7.3f & %6.4f & %7.3f& %6.4f & %7.4f & %7.4f \\\\ \n'],...
|
|
||||||
name,...
|
function TeXCore(fid,name,shape,priormean,priorstd,postmean,poststd,hpd)
|
||||||
shape,...
|
fprintf(fid,['$%s$ & %s & %7.3f & %6.4f & %7.3f& %6.4f & %7.4f & %7.4f \\\\ \n'],...
|
||||||
priormean,...
|
name,...
|
||||||
priorstd,...
|
shape,...
|
||||||
postmean,...
|
priormean,...
|
||||||
poststd,...
|
priorstd,...
|
||||||
hpd(1),...
|
postmean,...
|
||||||
hpd(2));
|
poststd,...
|
||||||
|
hpd(1),...
|
||||||
|
hpd(2));
|
||||||
function TeXEnd(fid,fnum,title)
|
|
||||||
fprintf(fid,'\\hline\\hline \n');
|
|
||||||
fprintf(fid,'\\end{tabular}\n ');
|
function TeXEnd(fid,fnum,title)
|
||||||
fprintf(fid,['\\caption{Results from Metropolis-Hastings (' title ')}\n ']);
|
fprintf(fid,'\\hline\\hline \n');
|
||||||
fprintf(fid,['\\label{Table:MHPosterior:' int2str(fnum) '}\n']);
|
fprintf(fid,'\\end{tabular}\n ');
|
||||||
fprintf(fid,'\\end{table}\n');
|
fprintf(fid,['\\caption{Results from Metropolis-Hastings (' title ')}\n ']);
|
||||||
fprintf(fid,'%% End of TeX file.\n');
|
fprintf(fid,['\\label{Table:MHPosterior:' int2str(fnum) '}\n']);
|
||||||
fclose(fid);
|
fprintf(fid,'\\end{table}\n');
|
||||||
|
fprintf(fid,'%% End of TeX file.\n');
|
||||||
|
fclose(fid);
|
||||||
function oo = Filloo(oo,name,type,postmean,hpdinterval,postmedian,postvar,postdecile,density)
|
|
||||||
eval(['oo.posterior_mean.' type '.' name ' = postmean;']);
|
|
||||||
eval(['oo.posterior_hpdinf.' type '.' name ' = hpdinterval(1);']);
|
function oo = Filloo(oo,name,type,postmean,hpdinterval,postmedian,postvar,postdecile,density)
|
||||||
eval(['oo.posterior_hpdsup.' type '.' name ' = hpdinterval(2);']);
|
eval(['oo.posterior_mean.' type '.' name ' = postmean;']);
|
||||||
eval(['oo.posterior_median.' type '.' name ' = postmedian;']);
|
eval(['oo.posterior_hpdinf.' type '.' name ' = hpdinterval(1);']);
|
||||||
eval(['oo.posterior_variance.' type '.' name ' = postvar;']);
|
eval(['oo.posterior_hpdsup.' type '.' name ' = hpdinterval(2);']);
|
||||||
eval(['oo.posterior_deciles.' type '.' name ' = postdecile;']);
|
eval(['oo.posterior_median.' type '.' name ' = postmedian;']);
|
||||||
eval(['oo.posterior_density.' type '.' name ' = density;']);
|
eval(['oo.posterior_variance.' type '.' name ' = postvar;']);
|
||||||
|
eval(['oo.posterior_deciles.' type '.' name ' = postdecile;']);
|
||||||
function [post_mean,hpd_interval,post_var] = Extractoo(oo,name,type)
|
eval(['oo.posterior_density.' type '.' name ' = density;']);
|
||||||
hpd_interval = zeros(2,1);
|
|
||||||
eval(['post_mean = oo.posterior_mean.' type '.' name ';']);
|
function [post_mean,hpd_interval,post_var] = Extractoo(oo,name,type)
|
||||||
eval(['hpd_interval(1) = oo.posterior_hpdinf.' type '.' name ';']);
|
hpd_interval = zeros(2,1);
|
||||||
eval(['hpd_interval(2) = oo.posterior_hpdsup.' type '.' name ';']);
|
eval(['post_mean = oo.posterior_mean.' type '.' name ';']);
|
||||||
|
eval(['hpd_interval(1) = oo.posterior_hpdinf.' type '.' name ';']);
|
||||||
|
eval(['hpd_interval(2) = oo.posterior_hpdsup.' type '.' name ';']);
|
||||||
eval(['post_var = oo.posterior_variance.' type '.' name ';']);
|
eval(['post_var = oo.posterior_variance.' type '.' name ';']);
|
|
@ -1,483 +1,481 @@
|
||||||
function PosteriorIRF(type)
|
function PosteriorIRF(type)
|
||||||
|
% Builds posterior IRFs after the MH algorithm.
|
||||||
% function PosteriorIRF(type)
|
%
|
||||||
% Builds posterior IRFs after the MH algorithm.
|
% INPUTS
|
||||||
%
|
% o type [char] string specifying the joint density of the
|
||||||
% INPUTS
|
% deep parameters ('prior','posterior').
|
||||||
% o type [char] string specifying the joint density of the
|
%
|
||||||
% deep parameters ('prior','posterior').
|
% OUTPUTS
|
||||||
%
|
% None (oo_ and plots).
|
||||||
% OUTPUTS
|
%
|
||||||
% None (oo_ and plots).
|
% SPECIAL REQUIREMENTS
|
||||||
%
|
% None
|
||||||
% SPECIAL REQUIREMENTS
|
%
|
||||||
% None
|
% part of DYNARE, copyright Dynare Team(2006-2008)
|
||||||
%
|
% Gnu Public License.
|
||||||
% part of DYNARE, copyright Dynare Team(2006-2008)
|
|
||||||
% Gnu Public License.
|
global options_ estim_params_ oo_ M_ bayestopt_
|
||||||
|
% Set the number of periods
|
||||||
global options_ estim_params_ oo_ M_ bayestopt_
|
if isempty(options_.irf) | ~options_.irf
|
||||||
% Set the number of periods
|
options_.irf = 40;
|
||||||
if isempty(options_.irf) | ~options_.irf
|
end
|
||||||
options_.irf = 40;
|
% Set varlist if necessary
|
||||||
end
|
varlist = options_.varlist;
|
||||||
% Set varlist if necessary
|
if isempty(varlist)
|
||||||
varlist = options_.varlist;
|
varlist = options_.varobs;
|
||||||
if isempty(varlist)
|
end
|
||||||
varlist = options_.varobs;
|
options_.varlist = varlist;
|
||||||
end
|
nvar = size(varlist,1);
|
||||||
options_.varlist = varlist;
|
IndxVariables = [];
|
||||||
nvar = size(varlist,1);
|
for i=1:nvar
|
||||||
IndxVariables = [];
|
idx = strmatch(deblank(varlist(i,:)),M_.endo_names,'exact');
|
||||||
for i=1:nvar
|
if isempty(idx)
|
||||||
idx = strmatch(deblank(varlist(i,:)),M_.endo_names,'exact');
|
disp(['PosteriorIRF :: ' deblank(varlist(i,:)) 'is not a declared endogenous variable!'])
|
||||||
if isempty(idx)
|
else
|
||||||
disp(['PosteriorIRF :: ' deblank(varlist(i,:)) 'is not a declared endogenous variable!'])
|
IndxVariables = [IndxVariables,idx];
|
||||||
else
|
end
|
||||||
IndxVariables = [IndxVariables,idx];
|
end
|
||||||
end
|
% Set various parameters & Check or create directories
|
||||||
end
|
nvx = estim_params_.nvx;
|
||||||
% Set various parameters & Check or create directories
|
nvn = estim_params_.nvn;
|
||||||
nvx = estim_params_.nvx;
|
ncx = estim_params_.ncx;
|
||||||
nvn = estim_params_.nvn;
|
ncn = estim_params_.ncn;
|
||||||
ncx = estim_params_.ncx;
|
np = estim_params_.np ;
|
||||||
ncn = estim_params_.ncn;
|
npar = nvx+nvn+ncx+ncn+np;
|
||||||
np = estim_params_.np ;
|
offset = npar-np;
|
||||||
npar = nvx+nvn+ncx+ncn+np;
|
clear('nvx','nvn','ncx','ncn','np');
|
||||||
offset = npar-np;
|
nvobs = size(options_.varobs,1);
|
||||||
clear('nvx','nvn','ncx','ncn','np');
|
gend = options_.nobs;
|
||||||
nvobs = size(options_.varobs,1);
|
MaxNumberOfPlotPerFigure = 9;
|
||||||
gend = options_.nobs;
|
nn = sqrt(MaxNumberOfPlotPerFigure);
|
||||||
MaxNumberOfPlotPerFigure = 9;
|
MAX_nirfs_dsge = ceil(options_.MaxNumberOfBytes/(options_.irf*nvar*M_.exo_nbr)/8);
|
||||||
nn = sqrt(MaxNumberOfPlotPerFigure);
|
MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
|
||||||
MAX_nirfs_dsge = ceil(options_.MaxNumberOfBytes/(options_.irf*nvar*M_.exo_nbr)/8);
|
if ~isempty(strmatch('dsge_prior_weight',M_.param_names))
|
||||||
MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
|
MAX_nirfs_dsgevar = ceil(options_.MaxNumberOfBytes/(options_.irf*nvobs*M_.exo_nbr)/8);
|
||||||
if ~isempty(strmatch('dsge_prior_weight',M_.param_names))
|
else
|
||||||
MAX_nirfs_dsgevar = ceil(options_.MaxNumberOfBytes/(options_.irf*nvobs*M_.exo_nbr)/8);
|
MAX_nirfs_dsgevar = 0;
|
||||||
else
|
end
|
||||||
MAX_nirfs_dsgevar = 0;
|
DirectoryName = CheckPath('Output');
|
||||||
end
|
if strcmpi(type,'posterior')
|
||||||
DirectoryName = CheckPath('Output');
|
MhDirectoryName = CheckPath('metropolis');
|
||||||
if strcmpi(type,'posterior')
|
elseif strcmpi(type,'gsa')
|
||||||
MhDirectoryName = CheckPath('metropolis');
|
MhDirectoryName = CheckPath('GSA');
|
||||||
elseif strcmpi(type,'gsa')
|
else
|
||||||
MhDirectoryName = CheckPath('GSA');
|
MhDirectoryName = CheckPath('prior');
|
||||||
else
|
end
|
||||||
MhDirectoryName = CheckPath('prior');
|
if strcmpi(type,'posterior')
|
||||||
end
|
load([ MhDirectoryName '/' M_.fname '_mh_history'])
|
||||||
if strcmpi(type,'posterior')
|
TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
|
||||||
load([ MhDirectoryName '/' M_.fname '_mh_history'])
|
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
|
||||||
TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
|
elseif strcmpi(type,'gsa')
|
||||||
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
|
load([ MhDirectoryName '/' M_.fname '_prior'],'lpmat0','lpmat','istable')
|
||||||
elseif strcmpi(type,'gsa')
|
x=[lpmat0(istable,:) lpmat(istable,:)];
|
||||||
load([ MhDirectoryName '/' M_.fname '_prior'],'lpmat0','lpmat','istable')
|
clear lpmat istable
|
||||||
x=[lpmat0(istable,:) lpmat(istable,:)];
|
NumberOfDraws=size(x,1);
|
||||||
clear lpmat istable
|
B=NumberOfDraws; options_.B = B;
|
||||||
NumberOfDraws=size(x,1);
|
else% type = 'prior'
|
||||||
B=NumberOfDraws; options_.B = B;
|
NumberOfDraws = 500;
|
||||||
else% type = 'prior'
|
end
|
||||||
NumberOfDraws = 500;
|
if ~strcmpi(type,'gsa')
|
||||||
end
|
B = min([round(.5*NumberOfDraws),500]); options_.B = B;
|
||||||
if ~strcmpi(type,'gsa')
|
end
|
||||||
B = min([round(.5*NumberOfDraws),500]); options_.B = B;
|
try delete([MhDirectoryName '/' M_.fname '_irf_dsge*.mat'])
|
||||||
end
|
catch disp('No _IRFs (dsge) files to be deleted!')
|
||||||
try delete([MhDirectoryName '/' M_.fname '_irf_dsge*.mat'])
|
end
|
||||||
catch disp('No _IRFs (dsge) files to be deleted!')
|
try delete([MhDirectoryName '/' M_.fname '_irf_bvardsge*.mat'])
|
||||||
end
|
catch disp('No _IRFs (bvar-dsge) files to be deleted!')
|
||||||
try delete([MhDirectoryName '/' M_.fname '_irf_bvardsge*.mat'])
|
end
|
||||||
catch disp('No _IRFs (bvar-dsge) files to be deleted!')
|
irun = 0;
|
||||||
end
|
IRUN = 0;
|
||||||
irun = 0;
|
irun2 = 0;
|
||||||
IRUN = 0;
|
NumberOfIRFfiles_dsge = 1;
|
||||||
irun2 = 0;
|
NumberOfIRFfiles_dsgevar = 1;
|
||||||
NumberOfIRFfiles_dsge = 1;
|
ifil2 = 1;
|
||||||
NumberOfIRFfiles_dsgevar = 1;
|
if strcmpi(type,'posterior')
|
||||||
ifil2 = 1;
|
h = waitbar(0,'Bayesian (posterior) IRFs...');
|
||||||
if strcmpi(type,'posterior')
|
elseif strcmpi(type,'gsa')
|
||||||
h = waitbar(0,'Bayesian (posterior) IRFs...');
|
h = waitbar(0,'GSA (prior) IRFs...');
|
||||||
elseif strcmpi(type,'gsa')
|
else
|
||||||
h = waitbar(0,'GSA (prior) IRFs...');
|
h = waitbar(0,'Bayesian (prior) IRFs...');
|
||||||
else
|
end
|
||||||
h = waitbar(0,'Bayesian (prior) IRFs...');
|
% Create arrays
|
||||||
end
|
if B <= MAX_nruns
|
||||||
% Create arrays
|
stock_param = zeros(B, npar);
|
||||||
if B <= MAX_nruns
|
else
|
||||||
stock_param = zeros(B, npar);
|
stock_param = zeros(MAX_nruns, npar);
|
||||||
else
|
end
|
||||||
stock_param = zeros(MAX_nruns, npar);
|
if B >= MAX_nirfs_dsge
|
||||||
end
|
stock_irf_dsge = zeros(options_.irf,nvar,M_.exo_nbr,MAX_nirfs_dsge);
|
||||||
if B >= MAX_nirfs_dsge
|
else
|
||||||
stock_irf_dsge = zeros(options_.irf,nvar,M_.exo_nbr,MAX_nirfs_dsge);
|
stock_irf_dsge = zeros(options_.irf,nvar,M_.exo_nbr,B);
|
||||||
else
|
end
|
||||||
stock_irf_dsge = zeros(options_.irf,nvar,M_.exo_nbr,B);
|
if MAX_nirfs_dsgevar
|
||||||
end
|
if B >= MAX_nirfs_dsgevar
|
||||||
if MAX_nirfs_dsgevar
|
stock_irf_bvardsge = zeros(options_.irf,nvobs,M_.exo_nbr,MAX_nirfs_dsgevar);
|
||||||
if B >= MAX_nirfs_dsgevar
|
else
|
||||||
stock_irf_bvardsge = zeros(options_.irf,nvobs,M_.exo_nbr,MAX_nirfs_dsgevar);
|
stock_irf_bvardsge = zeros(options_.irf,nvobs,M_.exo_nbr,B);
|
||||||
else
|
end
|
||||||
stock_irf_bvardsge = zeros(options_.irf,nvobs,M_.exo_nbr,B);
|
[mYY,mXY,mYX,mXX,Ydata,Xdata] = ...
|
||||||
end
|
var_sample_moments(options_.first_obs,options_.first_obs+options_.nobs-1,options_.varlag,-1);
|
||||||
[mYY,mXY,mYX,mXX,Ydata,Xdata] = ...
|
NumberOfLags = options_.varlag;
|
||||||
var_sample_moments(options_.first_obs,options_.first_obs+options_.nobs-1,options_.varlag,-1);
|
NumberOfLagsTimesNvobs = NumberOfLags*nvobs;
|
||||||
NumberOfLags = options_.varlag;
|
if options_.noconstant
|
||||||
NumberOfLagsTimesNvobs = NumberOfLags*nvobs;
|
NumberOfParametersPerEquation = NumberOfLagsTimesNvobs;
|
||||||
if options_.noconstant
|
else
|
||||||
NumberOfParametersPerEquation = NumberOfLagsTimesNvobs;
|
NumberOfParametersPerEquation = NumberOfLagsTimesNvobs+1;
|
||||||
else
|
end
|
||||||
NumberOfParametersPerEquation = NumberOfLagsTimesNvobs+1;
|
Companion_matrix = diag(ones(nvobs*(NumberOfLags-1),1),-nvobs);
|
||||||
end
|
end
|
||||||
Companion_matrix = diag(ones(nvobs*(NumberOfLags-1),1),-nvobs);
|
b = 0;
|
||||||
end
|
nosaddle = 0;
|
||||||
b = 0;
|
while b<=B
|
||||||
nosaddle = 0;
|
b = b + 1;
|
||||||
while b<=B
|
irun = irun+1;
|
||||||
b = b + 1;
|
irun2 = irun2+1;
|
||||||
irun = irun+1;
|
if ~strcmpi(type,'gsa')
|
||||||
irun2 = irun2+1;
|
deep = GetOneDraw(type);
|
||||||
if ~strcmpi(type,'gsa')
|
else
|
||||||
deep = GetOneDraw(type);
|
deep = x(b,:);
|
||||||
else
|
end
|
||||||
deep = x(b,:);
|
stock_param(irun2,:) = deep;
|
||||||
end
|
set_parameters(deep);
|
||||||
stock_param(irun2,:) = deep;
|
[dr,info] = resol(oo_.steady_state,0);
|
||||||
set_parameters(deep);
|
if info(1)
|
||||||
[dr,info] = resol(oo_.steady_state,0);
|
nosaddle = nosaddle + 1;
|
||||||
if info(1)
|
b = b - 1;
|
||||||
nosaddle = nosaddle + 1;
|
irun = irun-1;
|
||||||
b = b - 1;
|
irun2 = irun2-1;
|
||||||
irun = irun-1;
|
if info(1) == 1
|
||||||
irun2 = irun2-1;
|
errordef = 'Static variables are not uniquely defined';
|
||||||
if info(1) == 1
|
elseif info(1) == 2
|
||||||
errordef = 'Static variables are not uniquely defined';
|
errordef = 'Dll problem';
|
||||||
elseif info(1) == 2
|
elseif info(1) == 3
|
||||||
errordef = 'Dll problem';
|
errordef = 'No stable trajectory';
|
||||||
elseif info(1) == 3
|
elseif info(1) == 4
|
||||||
errordef = 'No stable trajectory';
|
errordef = 'Indeterminacy';
|
||||||
elseif info(1) == 4
|
elseif info(1) == 5
|
||||||
errordef = 'Indeterminacy';
|
errordef = 'Rank condition is not satisfied';
|
||||||
elseif info(1) == 5
|
end
|
||||||
errordef = 'Rank condition is not satisfied';
|
disp(['PosteriorIRF :: Dynare is unable to solve the model (' errordef ')'])
|
||||||
end
|
continue
|
||||||
disp(['PosteriorIRF :: Dynare is unable to solve the model (' errordef ')'])
|
end
|
||||||
continue
|
SS(M_.exo_names_orig_ord,M_.exo_names_orig_ord) = M_.Sigma_e+1e-14*eye(M_.exo_nbr);
|
||||||
end
|
SS = transpose(chol(SS));
|
||||||
SS(M_.exo_names_orig_ord,M_.exo_names_orig_ord) = M_.Sigma_e+1e-14*eye(M_.exo_nbr);
|
for i = 1:M_.exo_nbr
|
||||||
SS = transpose(chol(SS));
|
if SS(i,i) > 1e-13
|
||||||
for i = 1:M_.exo_nbr
|
y=irf(dr,SS(M_.exo_names_orig_ord,i), options_.irf, options_.drop,options_.replic,options_.order);
|
||||||
if SS(i,i) > 1e-13
|
if options_.relative_irf
|
||||||
y=irf(dr,SS(M_.exo_names_orig_ord,i), options_.irf, options_.drop,options_.replic,options_.order);
|
y = 100*y/cs(i,i);
|
||||||
if options_.relative_irf
|
end
|
||||||
y = 100*y/cs(i,i);
|
for j = 1:nvar
|
||||||
end
|
if max(y(IndxVariables(j),:)) - min(y(IndxVariables(j),:)) > 1e-12
|
||||||
for j = 1:nvar
|
stock_irf_dsge(:,j,i,irun) = transpose(y(IndxVariables(j),:));
|
||||||
if max(y(IndxVariables(j),:)) - min(y(IndxVariables(j),:)) > 1e-12
|
end
|
||||||
stock_irf_dsge(:,j,i,irun) = transpose(y(IndxVariables(j),:));
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if MAX_nirfs_dsgevar
|
||||||
end
|
IRUN = IRUN+1;
|
||||||
if MAX_nirfs_dsgevar
|
%tmp_dsgevar = zeros(options_.irf,nvobs*M_.exo_nbr);
|
||||||
IRUN = IRUN+1;
|
[fval,cost_flag,info,PHI,SIGMAu,iXX] = DsgeVarLikelihood(deep',gend);
|
||||||
%tmp_dsgevar = zeros(options_.irf,nvobs*M_.exo_nbr);
|
dsge_prior_weight = M_.params(strmatch('dsge_prior_weight',M_.param_names));
|
||||||
[fval,cost_flag,info,PHI,SIGMAu,iXX] = DsgeVarLikelihood(deep',gend);
|
DSGE_PRIOR_WEIGHT = floor(gend*(1+dsge_prior_weight));
|
||||||
dsge_prior_weight = M_.params(strmatch('dsge_prior_weight',M_.param_names));
|
SIGMA_inv_upper_chol = chol(inv(SIGMAu*gend*(dsge_prior_weight+1)));
|
||||||
DSGE_PRIOR_WEIGHT = floor(gend*(1+dsge_prior_weight));
|
explosive_var = 1;
|
||||||
SIGMA_inv_upper_chol = chol(inv(SIGMAu*gend*(dsge_prior_weight+1)));
|
while explosive_var
|
||||||
explosive_var = 1;
|
% draw from the marginal posterior of SIGMA
|
||||||
while explosive_var
|
SIGMAu_draw = rand_inverse_wishart(nvobs, DSGE_PRIOR_WEIGHT-NumberOfParametersPerEquation, ...
|
||||||
% draw from the marginal posterior of SIGMA
|
SIGMA_inv_upper_chol);
|
||||||
SIGMAu_draw = rand_inverse_wishart(nvobs, DSGE_PRIOR_WEIGHT-NumberOfParametersPerEquation, ...
|
% draw from the conditional posterior of PHI
|
||||||
SIGMA_inv_upper_chol);
|
PHI_draw = rand_matrix_normal(NumberOfParametersPerEquation,nvobs, PHI, ...
|
||||||
% draw from the conditional posterior of PHI
|
chol(SIGMAu_draw)', chol(iXX)');
|
||||||
PHI_draw = rand_matrix_normal(NumberOfParametersPerEquation,nvobs, PHI, ...
|
Companion_matrix(1:nvobs,:) = transpose(PHI_draw(1:NumberOfLagsTimesNvobs,:));
|
||||||
chol(SIGMAu_draw)', chol(iXX)');
|
% Check for stationarity
|
||||||
Companion_matrix(1:nvobs,:) = transpose(PHI_draw(1:NumberOfLagsTimesNvobs,:));
|
explosive_var = any(abs(eig(Companion_matrix))>1.000000001);
|
||||||
% Check for stationarity
|
end
|
||||||
explosive_var = any(abs(eig(Companion_matrix))>1.000000001);
|
% Get the mean
|
||||||
end
|
% $$$ if options_.noconstant
|
||||||
% Get the mean
|
mu = zeros(1,nvobs);
|
||||||
% $$$ if options_.noconstant
|
% $$$ else
|
||||||
mu = zeros(1,nvobs);
|
% $$$ AA = eye(nvobs);
|
||||||
% $$$ else
|
% $$$ for lag=1:NumberOfLags
|
||||||
% $$$ AA = eye(nvobs);
|
% $$$ AA = AA-PHI_draw((lag-1)*nvobs+1:lag*nvobs,:);
|
||||||
% $$$ for lag=1:NumberOfLags
|
% $$$ end
|
||||||
% $$$ AA = AA-PHI_draw((lag-1)*nvobs+1:lag*nvobs,:);
|
% $$$ mu = transpose(AA\transpose(PHI_draw(end,:)));
|
||||||
% $$$ end
|
% $$$ end
|
||||||
% $$$ mu = transpose(AA\transpose(PHI_draw(end,:)));
|
% Get rotation
|
||||||
% $$$ end
|
if dsge_prior_weight > 0
|
||||||
% Get rotation
|
Atheta(oo_.dr.order_var,M_.exo_names_orig_ord) = oo_.dr.ghu*sqrt(M_.Sigma_e);
|
||||||
if dsge_prior_weight > 0
|
A0 = Atheta(bayestopt_.mfys,:);
|
||||||
Atheta(oo_.dr.order_var,M_.exo_names_orig_ord) = oo_.dr.ghu*sqrt(M_.Sigma_e);
|
[OMEGAstar,SIGMAtr] = qr2(A0');
|
||||||
A0 = Atheta(bayestopt_.mfys,:);
|
end
|
||||||
[OMEGAstar,SIGMAtr] = qr2(A0');
|
SIGMAu_chol = chol(SIGMAu_draw)';
|
||||||
end
|
SIGMAtrOMEGA = SIGMAu_chol*OMEGAstar';
|
||||||
SIGMAu_chol = chol(SIGMAu_draw)';
|
PHIpower = eye(NumberOfLagsTimesNvobs);
|
||||||
SIGMAtrOMEGA = SIGMAu_chol*OMEGAstar';
|
irfs = zeros (options_.irf,nvobs*M_.exo_nbr);
|
||||||
PHIpower = eye(NumberOfLagsTimesNvobs);
|
tmp3 = PHIpower(1:nvobs,1:nvobs)*SIGMAtrOMEGA;
|
||||||
irfs = zeros (options_.irf,nvobs*M_.exo_nbr);
|
irfs(1,:) = tmp3(:)';
|
||||||
tmp3 = PHIpower(1:nvobs,1:nvobs)*SIGMAtrOMEGA;
|
for t = 2:options_.irf
|
||||||
irfs(1,:) = tmp3(:)';
|
PHIpower = Companion_matrix*PHIpower;
|
||||||
for t = 2:options_.irf
|
tmp3 = PHIpower(1:nvobs,1:nvobs)*SIGMAtrOMEGA;
|
||||||
PHIpower = Companion_matrix*PHIpower;
|
irfs(t,:) = tmp3(:)'+kron(ones(1,M_.exo_nbr),mu);
|
||||||
tmp3 = PHIpower(1:nvobs,1:nvobs)*SIGMAtrOMEGA;
|
end
|
||||||
irfs(t,:) = tmp3(:)'+kron(ones(1,M_.exo_nbr),mu);
|
tmp_dsgevar = kron(ones(options_.irf,1),mu);
|
||||||
end
|
for j = 1:(nvobs*M_.exo_nbr)
|
||||||
tmp_dsgevar = kron(ones(options_.irf,1),mu);
|
if max(irfs(:,j)) - min(irfs(:,j)) > 1e-10
|
||||||
for j = 1:(nvobs*M_.exo_nbr)
|
tmp_dsgevar(:,j) = (irfs(:,j));
|
||||||
if max(irfs(:,j)) - min(irfs(:,j)) > 1e-10
|
end
|
||||||
tmp_dsgevar(:,j) = (irfs(:,j));
|
end
|
||||||
end
|
if IRUN < MAX_nirfs_dsgevar
|
||||||
end
|
stock_irf_bvardsge(:,:,:,IRUN) = reshape(tmp_dsgevar,options_.irf,nvobs,M_.exo_nbr);
|
||||||
if IRUN < MAX_nirfs_dsgevar
|
else
|
||||||
stock_irf_bvardsge(:,:,:,IRUN) = reshape(tmp_dsgevar,options_.irf,nvobs,M_.exo_nbr);
|
stock_irf_bvardsge(:,:,:,IRUN) = reshape(tmp_dsgevar,options_.irf,nvobs,M_.exo_nbr);
|
||||||
else
|
instr = [MhDirectoryName '/' M_.fname '_irf_bvardsge' ...
|
||||||
stock_irf_bvardsge(:,:,:,IRUN) = reshape(tmp_dsgevar,options_.irf,nvobs,M_.exo_nbr);
|
int2str(NumberOfIRFfiles_dsgevar) ' stock_irf_bvardsge;'];,
|
||||||
instr = [MhDirectoryName '/' M_.fname '_irf_bvardsge' ...
|
eval(['save ' instr]);
|
||||||
int2str(NumberOfIRFfiles_dsgevar) ' stock_irf_bvardsge;'];,
|
NumberOfIRFfiles_dsgevar = NumberOfIRFfiles_dsgevar+1;
|
||||||
eval(['save ' instr]);
|
IRUN =0;
|
||||||
NumberOfIRFfiles_dsgevar = NumberOfIRFfiles_dsgevar+1;
|
stock_irf_dsgevar = zeros(options_.irf,nvobs,M_.exo_nbr,MAX_nirfs_dsgevar);
|
||||||
IRUN =0;
|
end
|
||||||
stock_irf_dsgevar = zeros(options_.irf,nvobs,M_.exo_nbr,MAX_nirfs_dsgevar);
|
end
|
||||||
end
|
if irun == MAX_nirfs_dsge | irun == B | b == B
|
||||||
end
|
if b == B
|
||||||
if irun == MAX_nirfs_dsge | irun == B | b == B
|
stock_irf_dsge = stock_irf_dsge(:,:,:,1:irun);
|
||||||
if b == B
|
if MAX_nirfs_dsgevar & (b == B | IRUN == B)
|
||||||
stock_irf_dsge = stock_irf_dsge(:,:,:,1:irun);
|
stock_irf_bvardsge = stock_irf_bvardsge(:,:,:,1:IRUN);
|
||||||
if MAX_nirfs_dsgevar & (b == B | IRUN == B)
|
instr = [MhDirectoryName '/' M_.fname '_irf_bvardsge' ...
|
||||||
stock_irf_bvardsge = stock_irf_bvardsge(:,:,:,1:IRUN);
|
int2str(NumberOfIRFfiles_dsgevar) ' stock_irf_bvardsge;'];,
|
||||||
instr = [MhDirectoryName '/' M_.fname '_irf_bvardsge' ...
|
eval(['save ' instr]);
|
||||||
int2str(NumberOfIRFfiles_dsgevar) ' stock_irf_bvardsge;'];,
|
NumberOfIRFfiles_dsgevar = NumberOfIRFfiles_dsgevar+1;
|
||||||
eval(['save ' instr]);
|
irun = 0;
|
||||||
NumberOfIRFfiles_dsgevar = NumberOfIRFfiles_dsgevar+1;
|
end
|
||||||
irun = 0;
|
end
|
||||||
end
|
save([MhDirectoryName '/' M_.fname '_irf_dsge' int2str(NumberOfIRFfiles_dsge)],'stock_irf_dsge');
|
||||||
end
|
NumberOfIRFfiles_dsge = NumberOfIRFfiles_dsge+1;
|
||||||
save([MhDirectoryName '/' M_.fname '_irf_dsge' int2str(NumberOfIRFfiles_dsge)],'stock_irf_dsge');
|
irun = 0;
|
||||||
NumberOfIRFfiles_dsge = NumberOfIRFfiles_dsge+1;
|
end
|
||||||
irun = 0;
|
if irun2 == MAX_nruns | b == B
|
||||||
end
|
if b == B
|
||||||
if irun2 == MAX_nruns | b == B
|
stock_param = stock_param(1:irun2,:);
|
||||||
if b == B
|
end
|
||||||
stock_param = stock_param(1:irun2,:);
|
stock = stock_param;
|
||||||
end
|
save([MhDirectoryName '/' M_.fname '_param_irf' int2str(ifil2)],'stock');
|
||||||
stock = stock_param;
|
ifil2 = ifil2 + 1;
|
||||||
save([MhDirectoryName '/' M_.fname '_param_irf' int2str(ifil2)],'stock');
|
irun2 = 0;
|
||||||
ifil2 = ifil2 + 1;
|
end
|
||||||
irun2 = 0;
|
waitbar(b/B,h);
|
||||||
end
|
end
|
||||||
waitbar(b/B,h);
|
if nosaddle
|
||||||
end
|
disp(['PosteriorIRF :: Percentage of discarded posterior draws = ' num2str(nosaddle/(B+nosaddle))])
|
||||||
if nosaddle
|
end
|
||||||
disp(['PosteriorIRF :: Percentage of discarded posterior draws = ' num2str(nosaddle/(B+nosaddle))])
|
close(h);
|
||||||
end
|
|
||||||
close(h);
|
ReshapeMatFiles('irf_dsge')
|
||||||
|
if MAX_nirfs_dsgevar
|
||||||
ReshapeMatFiles('irf_dsge')
|
ReshapeMatFiles('irf_bvardsge')
|
||||||
if MAX_nirfs_dsgevar
|
end
|
||||||
ReshapeMatFiles('irf_bvardsge')
|
|
||||||
end
|
if strcmpi(type,'gsa')
|
||||||
|
return
|
||||||
if strcmpi(type,'gsa')
|
end
|
||||||
return
|
|
||||||
end
|
IRF_DSGEs = dir([MhDirectoryName '/' M_.fname '_IRF_DSGEs*.mat']);
|
||||||
|
NumberOfIRFfiles_dsge = length(IRF_DSGEs);
|
||||||
IRF_DSGEs = dir([MhDirectoryName '/' M_.fname '_IRF_DSGEs*.mat']);
|
|
||||||
NumberOfIRFfiles_dsge = length(IRF_DSGEs);
|
IRF_BVARDSGEs = dir([MhDirectoryName '/' M_.fname '_IRF_BVARDSGEs*.mat']);
|
||||||
|
NumberOfIRFfiles_dsgevar = length(IRF_BVARDSGEs);
|
||||||
IRF_BVARDSGEs = dir([MhDirectoryName '/' M_.fname '_IRF_BVARDSGEs*.mat']);
|
|
||||||
NumberOfIRFfiles_dsgevar = length(IRF_BVARDSGEs);
|
|
||||||
|
|
||||||
|
MeanIRF = zeros(options_.irf,nvar,M_.exo_nbr);
|
||||||
|
MedianIRF = zeros(options_.irf,nvar,M_.exo_nbr);
|
||||||
MeanIRF = zeros(options_.irf,nvar,M_.exo_nbr);
|
VarIRF = zeros(options_.irf,nvar,M_.exo_nbr);
|
||||||
MedianIRF = zeros(options_.irf,nvar,M_.exo_nbr);
|
DistribIRF = zeros(options_.irf,9,nvar,M_.exo_nbr);
|
||||||
VarIRF = zeros(options_.irf,nvar,M_.exo_nbr);
|
HPDIRF = zeros(options_.irf,2,nvar,M_.exo_nbr);
|
||||||
DistribIRF = zeros(options_.irf,9,nvar,M_.exo_nbr);
|
|
||||||
HPDIRF = zeros(options_.irf,2,nvar,M_.exo_nbr);
|
if options_.TeX
|
||||||
|
varlist_TeX = [];
|
||||||
if options_.TeX
|
for i=1:nvar
|
||||||
varlist_TeX = [];
|
varlist_TeX = strvcat(varlist_TeX,M_.endo_names_tex(IndxVariables(i),:));
|
||||||
for i=1:nvar
|
end
|
||||||
varlist_TeX = strvcat(varlist_TeX,M_.endo_names_tex(IndxVariables(i),:));
|
end
|
||||||
end
|
|
||||||
end
|
fprintf('MH: Posterior (dsge) IRFs...\n');
|
||||||
|
tit(M_.exo_names_orig_ord,:) = M_.exo_names;
|
||||||
fprintf('MH: Posterior (dsge) IRFs...\n');
|
kdx = 0;
|
||||||
tit(M_.exo_names_orig_ord,:) = M_.exo_names;
|
|
||||||
kdx = 0;
|
for file = 1:NumberOfIRFfiles_dsge
|
||||||
|
load([MhDirectoryName '/' M_.fname '_IRF_DSGEs' int2str(file)]);
|
||||||
for file = 1:NumberOfIRFfiles_dsge
|
for i = 1:M_.exo_nbr
|
||||||
load([MhDirectoryName '/' M_.fname '_IRF_DSGEs' int2str(file)]);
|
for j = 1:nvar
|
||||||
for i = 1:M_.exo_nbr
|
for k = 1:size(STOCK_IRF_DSGE,1)
|
||||||
for j = 1:nvar
|
kk = k+kdx;
|
||||||
for k = 1:size(STOCK_IRF_DSGE,1)
|
[MeanIRF(kk,j,i),MedianIRF(kk,j,i),VarIRF(kk,j,i),HPDIRF(kk,:,j,i),...
|
||||||
kk = k+kdx;
|
DistribIRF(kk,:,j,i)] = posterior_moments(squeeze(STOCK_IRF_DSGE(k,j,i,:)),0,options_.mh_conf_sig);
|
||||||
[MeanIRF(kk,j,i),MedianIRF(kk,j,i),VarIRF(kk,j,i),HPDIRF(kk,:,j,i),...
|
end
|
||||||
DistribIRF(kk,:,j,i)] = posterior_moments(squeeze(STOCK_IRF_DSGE(k,j,i,:)),0);
|
end
|
||||||
end
|
end
|
||||||
end
|
kdx = kdx + size(STOCK_IRF_DSGE,1);
|
||||||
end
|
end
|
||||||
kdx = kdx + size(STOCK_IRF_DSGE,1);
|
|
||||||
end
|
clear STOCK_IRF_DSGE;
|
||||||
|
|
||||||
clear STOCK_IRF_DSGE;
|
for i = 1:M_.exo_nbr
|
||||||
|
for j = 1:nvar
|
||||||
for i = 1:M_.exo_nbr
|
name = [deblank(M_.endo_names(IndxVariables(j),:)) '_' deblank(tit(i,:))];
|
||||||
for j = 1:nvar
|
eval(['oo_.PosteriorIRF.dsge.Mean.' name ' = MeanIRF(:,j,i);']);
|
||||||
name = [deblank(M_.endo_names(IndxVariables(j),:)) '_' deblank(tit(i,:))];
|
eval(['oo_.PosteriorIRF.dsge.Median.' name ' = MedianIRF(:,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.dsge.Mean.' name ' = MeanIRF(:,j,i);']);
|
eval(['oo_.PosteriorIRF.dsge.Var.' name ' = VarIRF(:,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.dsge.Median.' name ' = MedianIRF(:,j,i);']);
|
eval(['oo_.PosteriorIRF.dsge.Distribution.' name ' = DistribIRF(:,:,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.dsge.Var.' name ' = VarIRF(:,j,i);']);
|
eval(['oo_.PosteriorIRF.dsge.HPDinf.' name ' = HPDIRF(:,1,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.dsge.Distribution.' name ' = DistribIRF(:,:,j,i);']);
|
eval(['oo_.PosteriorIRF.dsge.HPDsup.' name ' = HPDIRF(:,2,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.dsge.HPDinf.' name ' = HPDIRF(:,1,j,i);']);
|
end
|
||||||
eval(['oo_.PosteriorIRF.dsge.HPDsup.' name ' = HPDIRF(:,2,j,i);']);
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
if MAX_nirfs_dsgevar
|
||||||
|
MeanIRFdsgevar = zeros(options_.irf,nvar,M_.exo_nbr);
|
||||||
if MAX_nirfs_dsgevar
|
MedianIRFdsgevar = zeros(options_.irf,nvar,M_.exo_nbr);
|
||||||
MeanIRFdsgevar = zeros(options_.irf,nvar,M_.exo_nbr);
|
VarIRFdsgevar = zeros(options_.irf,nvar,M_.exo_nbr);
|
||||||
MedianIRFdsgevar = zeros(options_.irf,nvar,M_.exo_nbr);
|
DistribIRFdsgevar = zeros(options_.irf,9,nvar,M_.exo_nbr);
|
||||||
VarIRFdsgevar = zeros(options_.irf,nvar,M_.exo_nbr);
|
HPDIRFdsgevar = zeros(options_.irf,2,nvar,M_.exo_nbr);
|
||||||
DistribIRFdsgevar = zeros(options_.irf,9,nvar,M_.exo_nbr);
|
fprintf('MH: Posterior (bvar-dsge) IRFs...\n');
|
||||||
HPDIRFdsgevar = zeros(options_.irf,2,nvar,M_.exo_nbr);
|
tit(M_.exo_names_orig_ord,:) = M_.exo_names;
|
||||||
fprintf('MH: Posterior (bvar-dsge) IRFs...\n');
|
kdx = 0;
|
||||||
tit(M_.exo_names_orig_ord,:) = M_.exo_names;
|
for file = 1:NumberOfIRFfiles_dsgevar
|
||||||
kdx = 0;
|
load([MhDirectoryName '/' M_.fname '_IRF_BVARDSGEs' int2str(file)]);
|
||||||
for file = 1:NumberOfIRFfiles_dsgevar
|
for i = 1:M_.exo_nbr
|
||||||
load([MhDirectoryName '/' M_.fname '_IRF_BVARDSGEs' int2str(file)]);
|
for j = 1:nvar
|
||||||
for i = 1:M_.exo_nbr
|
for k = 1:size(STOCK_IRF_BVARDSGE,1)
|
||||||
for j = 1:nvar
|
kk = k+kdx;
|
||||||
for k = 1:size(STOCK_IRF_BVARDSGE,1)
|
[MeanIRFdsgevar(kk,j,i),MedianIRFdsgevar(kk,j,i),VarIRFdsgevar(kk,j,i),...
|
||||||
kk = k+kdx;
|
HPDIRFdsgevar(kk,:,j,i),DistribIRFdsgevar(kk,:,j,i)] = ...
|
||||||
[MeanIRFdsgevar(kk,j,i),MedianIRFdsgevar(kk,j,i),VarIRFdsgevar(kk,j,i),...
|
posterior_moments(squeeze(STOCK_IRF_BVARDSGE(k,j,i,:)),0,options_.mh_conf_sig);
|
||||||
HPDIRFdsgevar(kk,:,j,i),DistribIRFdsgevar(kk,:,j,i)] = ...
|
end
|
||||||
posterior_moments(squeeze(STOCK_IRF_BVARDSGE(k,j,i,:)),0);
|
end
|
||||||
end
|
end
|
||||||
end
|
kdx = kdx + size(STOCK_IRF_BVARDSGE,1);
|
||||||
end
|
end
|
||||||
kdx = kdx + size(STOCK_IRF_BVARDSGE,1);
|
clear STOCK_IRF_BVARDSGE;
|
||||||
end
|
for i = 1:M_.exo_nbr
|
||||||
clear STOCK_IRF_BVARDSGE;
|
for j = 1:nvar
|
||||||
for i = 1:M_.exo_nbr
|
name = [deblank(M_.endo_names(IndxVariables(j),:)) '_' deblank(tit(i,:))];
|
||||||
for j = 1:nvar
|
eval(['oo_.PosteriorIRF.bvardsge.Mean.' name ' = MeanIRFdsgevar(:,j,i);']);
|
||||||
name = [deblank(M_.endo_names(IndxVariables(j),:)) '_' deblank(tit(i,:))];
|
eval(['oo_.PosteriorIRF.bvardsge.Median.' name ' = MedianIRFdsgevar(:,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.bvardsge.Mean.' name ' = MeanIRFdsgevar(:,j,i);']);
|
eval(['oo_.PosteriorIRF.bvardsge.Var.' name ' = VarIRFdsgevar(:,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.bvardsge.Median.' name ' = MedianIRFdsgevar(:,j,i);']);
|
eval(['oo_.PosteriorIRF.bvardsge.Distribution.' name ' = DistribIRFdsgevar(:,:,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.bvardsge.Var.' name ' = VarIRFdsgevar(:,j,i);']);
|
eval(['oo_.PosteriorIRF.bvardsge.HPDinf.' name ' = HPDIRFdsgevar(:,1,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.bvardsge.Distribution.' name ' = DistribIRFdsgevar(:,:,j,i);']);
|
eval(['oo_.PosteriorIRF.bvardsge.HPDsup.' name ' = HPDIRFdsgevar(:,2,j,i);']);
|
||||||
eval(['oo_.PosteriorIRF.bvardsge.HPDinf.' name ' = HPDIRFdsgevar(:,1,j,i);']);
|
end
|
||||||
eval(['oo_.PosteriorIRF.bvardsge.HPDsup.' name ' = HPDIRFdsgevar(:,2,j,i);']);
|
end
|
||||||
end
|
end
|
||||||
end
|
%%
|
||||||
end
|
%% Finally I build the plots.
|
||||||
%%
|
%%
|
||||||
%% Finally I build the plots.
|
if options_.TeX
|
||||||
%%
|
fidTeX = fopen([DirectoryName '/' M_.fname '_BayesianIRF.TeX'],'w');
|
||||||
if options_.TeX
|
fprintf(fidTeX,'%% TeX eps-loader file generated by PosteriorIRF.m (Dynare).\n');
|
||||||
fidTeX = fopen([DirectoryName '/' M_.fname '_BayesianIRF.TeX'],'w');
|
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
||||||
fprintf(fidTeX,'%% TeX eps-loader file generated by PosteriorIRF.m (Dynare).\n');
|
fprintf(fidTeX,' \n');
|
||||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
titTeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex;
|
||||||
fprintf(fidTeX,' \n');
|
end
|
||||||
titTeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex;
|
%%
|
||||||
end
|
subplotnum = 0;
|
||||||
%%
|
for i=1:M_.exo_nbr
|
||||||
subplotnum = 0;
|
NAMES = [];
|
||||||
for i=1:M_.exo_nbr
|
if options_.TeX
|
||||||
NAMES = [];
|
TEXNAMES = [];
|
||||||
if options_.TeX
|
end
|
||||||
TEXNAMES = [];
|
figunumber = 0;
|
||||||
end
|
for j=1:nvar
|
||||||
figunumber = 0;
|
if max(abs(MeanIRF(:,j,i))) > 10^(-6)
|
||||||
for j=1:nvar
|
subplotnum = subplotnum+1;
|
||||||
if max(abs(MeanIRF(:,j,i))) > 10^(-6)
|
if options_.nograph
|
||||||
subplotnum = subplotnum+1;
|
if subplotnum == 1 & options_.relative_irf
|
||||||
if options_.nograph
|
hh = figure('Name',['Relative response to orthogonalized shock to ' tit(i,:)],'Visible','off');
|
||||||
if subplotnum == 1 & options_.relative_irf
|
elseif subplotnum == 1 & ~options_.relative_irf
|
||||||
hh = figure('Name',['Relative response to orthogonalized shock to ' tit(i,:)],'Visible','off');
|
hh = figure('Name',['Orthogonalized shock to ' tit(i,:)],'Visible','off');
|
||||||
elseif subplotnum == 1 & ~options_.relative_irf
|
end
|
||||||
hh = figure('Name',['Orthogonalized shock to ' tit(i,:)],'Visible','off');
|
else
|
||||||
end
|
if subplotnum == 1 & options_.relative_irf
|
||||||
else
|
hh = figure('Name',['Relative response to orthogonalized shock to ' tit(i,:)]);
|
||||||
if subplotnum == 1 & options_.relative_irf
|
elseif subplotnum == 1 & ~options_.relative_irf
|
||||||
hh = figure('Name',['Relative response to orthogonalized shock to ' tit(i,:)]);
|
hh = figure('Name',['Orthogonalized shock to ' tit(i,:)]);
|
||||||
elseif subplotnum == 1 & ~options_.relative_irf
|
end
|
||||||
hh = figure('Name',['Orthogonalized shock to ' tit(i,:)]);
|
end
|
||||||
end
|
set(0,'CurrentFigure',hh)
|
||||||
end
|
subplot(nn,nn,subplotnum);
|
||||||
set(0,'CurrentFigure',hh)
|
if ~MAX_nirfs_dsgevar
|
||||||
subplot(nn,nn,subplotnum);
|
h1 = area(1:options_.irf,HPDIRF(:,2,j,i));
|
||||||
if ~MAX_nirfs_dsgevar
|
set(h1,'FaceColor',[.9 .9 .9]);
|
||||||
h1 = area(1:options_.irf,HPDIRF(:,2,j,i));
|
set(h1,'BaseValue',min(HPDIRF(:,1,j,i)));
|
||||||
set(h1,'FaceColor',[.9 .9 .9]);
|
hold on
|
||||||
set(h1,'BaseValue',min(HPDIRF(:,1,j,i)));
|
h2 = area(1:options_.irf,HPDIRF(:,1,j,i),'FaceColor',[1 1 1],'BaseValue',min(HPDIRF(:,1,j,i)));
|
||||||
hold on
|
set(h2,'FaceColor',[1 1 1]);
|
||||||
h2 = area(1:options_.irf,HPDIRF(:,1,j,i),'FaceColor',[1 1 1],'BaseValue',min(HPDIRF(:,1,j,i)));
|
set(h2,'BaseValue',min(HPDIRF(:,1,j,i)));
|
||||||
set(h2,'FaceColor',[1 1 1]);
|
plot(1:options_.irf,MeanIRF(:,j,i),'-k','linewidth',3)
|
||||||
set(h2,'BaseValue',min(HPDIRF(:,1,j,i)));
|
% plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
||||||
plot(1:options_.irf,MeanIRF(:,j,i),'-k','linewidth',3)
|
box on
|
||||||
% plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
axis tight
|
||||||
box on
|
xlim([1 options_.irf]);
|
||||||
axis tight
|
hold off
|
||||||
xlim([1 options_.irf]);
|
else
|
||||||
hold off
|
h1 = area(1:options_.irf,HPDIRF(:,2,j,i));
|
||||||
else
|
set(h1,'FaceColor',[.9 .9 .9]);
|
||||||
h1 = area(1:options_.irf,HPDIRF(:,2,j,i));
|
set(h1,'BaseValue',min([min(HPDIRF(:,1,j,i)),min(HPDIRFdsgevar(:,1,j,i))]));
|
||||||
set(h1,'FaceColor',[.9 .9 .9]);
|
hold on;
|
||||||
set(h1,'BaseValue',min([min(HPDIRF(:,1,j,i)),min(HPDIRFdsgevar(:,1,j,i))]));
|
h2 = area(1:options_.irf,HPDIRF(:,1,j,i));
|
||||||
hold on;
|
set(h2,'FaceColor',[1 1 1]);
|
||||||
h2 = area(1:options_.irf,HPDIRF(:,1,j,i));
|
set(h2,'BaseValue',min([min(HPDIRF(:,1,j,i)),min(HPDIRFdsgevar(:,1,j,i))]));
|
||||||
set(h2,'FaceColor',[1 1 1]);
|
plot(1:options_.irf,MeanIRF(:,j,i),'-k','linewidth',3)
|
||||||
set(h2,'BaseValue',min([min(HPDIRF(:,1,j,i)),min(HPDIRFdsgevar(:,1,j,i))]));
|
% plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
||||||
plot(1:options_.irf,MeanIRF(:,j,i),'-k','linewidth',3)
|
plot(1:options_.irf,MeanIRFdsgevar(:,j,i),'--k','linewidth',2)
|
||||||
% plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
plot(1:options_.irf,HPDIRFdsgevar(:,1,j,i),'--k','linewidth',1)
|
||||||
plot(1:options_.irf,MeanIRFdsgevar(:,j,i),'--k','linewidth',2)
|
plot(1:options_.irf,HPDIRFdsgevar(:,2,j,i),'--k','linewidth',1)
|
||||||
plot(1:options_.irf,HPDIRFdsgevar(:,1,j,i),'--k','linewidth',1)
|
box on
|
||||||
plot(1:options_.irf,HPDIRFdsgevar(:,2,j,i),'--k','linewidth',1)
|
axis tight
|
||||||
box on
|
xlim([1 options_.irf]);
|
||||||
axis tight
|
hold off
|
||||||
xlim([1 options_.irf]);
|
end
|
||||||
hold off
|
name = deblank(varlist(j,:));
|
||||||
end
|
NAMES = strvcat(NAMES,name);
|
||||||
name = deblank(varlist(j,:));
|
if options_.TeX
|
||||||
NAMES = strvcat(NAMES,name);
|
texname = deblank(varlist_TeX(j,:));
|
||||||
if options_.TeX
|
TEXNAMES = strvcat(TEXNAMES,['$' texname '$']);
|
||||||
texname = deblank(varlist_TeX(j,:));
|
end
|
||||||
TEXNAMES = strvcat(TEXNAMES,['$' texname '$']);
|
title(name,'Interpreter','none')
|
||||||
end
|
end
|
||||||
title(name,'Interpreter','none')
|
if subplotnum == MaxNumberOfPlotPerFigure | (j == nvar & subplotnum> 0)
|
||||||
end
|
figunumber = figunumber+1;
|
||||||
if subplotnum == MaxNumberOfPlotPerFigure | (j == nvar & subplotnum> 0)
|
set(hh,'visible','on')
|
||||||
figunumber = figunumber+1;
|
eval(['print -depsc2 ' DirectoryName '/' M_.fname '_Bayesian_IRF_' deblank(tit(i,:)) '_' int2str(figunumber)]);
|
||||||
set(hh,'visible','on')
|
eval(['print -dpdf ' DirectoryName '/' M_.fname '_Bayesian_IRF_' deblank(tit(i,:)) '_' int2str(figunumber)]);
|
||||||
eval(['print -depsc2 ' DirectoryName '/' M_.fname '_Bayesian_IRF_' deblank(tit(i,:)) '_' int2str(figunumber)]);
|
saveas(hh,[DirectoryName '/' M_.fname '_Bayesian_IRF_' deblank(tit(i,:)) '_' int2str(figunumber) '.fig']);
|
||||||
eval(['print -dpdf ' DirectoryName '/' M_.fname '_Bayesian_IRF_' deblank(tit(i,:)) '_' int2str(figunumber)]);
|
set(hh,'visible','off')
|
||||||
saveas(hh,[DirectoryName '/' M_.fname '_Bayesian_IRF_' deblank(tit(i,:)) '_' int2str(figunumber) '.fig']);
|
if options_.nograph, close(hh), end
|
||||||
set(hh,'visible','off')
|
if options_.TeX
|
||||||
if options_.nograph, close(hh), end
|
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||||
if options_.TeX
|
for jj = 1:size(TEXNAMES,1)
|
||||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{%s}\n'],deblank(NAMES(jj,:)),deblank(TEXNAMES(jj,:)));
|
||||||
for jj = 1:size(TEXNAMES,1)
|
end
|
||||||
fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{%s}\n'],deblank(NAMES(jj,:)),deblank(TEXNAMES(jj,:)));
|
fprintf(fidTeX,'\\centering \n');
|
||||||
end
|
fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_Bayesian_IRF_%s}\n',M_.fname,deblank(tit(i,:)));
|
||||||
fprintf(fidTeX,'\\centering \n');
|
if options_.relative_irf
|
||||||
fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_Bayesian_IRF_%s}\n',M_.fname,deblank(tit(i,:)));
|
fprintf(fidTeX,['\\caption{Bayesian relative IRF.}']);
|
||||||
if options_.relative_irf
|
else
|
||||||
fprintf(fidTeX,['\\caption{Bayesian relative IRF.}']);
|
fprintf(fidTeX,'\\caption{Bayesian IRF.}');
|
||||||
else
|
end
|
||||||
fprintf(fidTeX,'\\caption{Bayesian IRF.}');
|
fprintf(fidTeX,'\\label{Fig:BayesianIRF:%s}\n',deblank(tit(i,:)));
|
||||||
end
|
fprintf(fidTeX,'\\end{figure}\n');
|
||||||
fprintf(fidTeX,'\\label{Fig:BayesianIRF:%s}\n',deblank(tit(i,:)));
|
fprintf(fidTeX,' \n');
|
||||||
fprintf(fidTeX,'\\end{figure}\n');
|
end
|
||||||
fprintf(fidTeX,' \n');
|
subplotnum = 0;
|
||||||
end
|
end
|
||||||
subplotnum = 0;
|
end% loop over selected endo_var
|
||||||
end
|
end% loop over exo_var
|
||||||
end% loop over selected endo_var
|
%%
|
||||||
end% loop over exo_var
|
if options_.TeX
|
||||||
%%
|
fprintf(fidTeX,'%% End of TeX file.\n');
|
||||||
if options_.TeX
|
fclose(fidTeX);
|
||||||
fprintf(fidTeX,'%% End of TeX file.\n');
|
end
|
||||||
fclose(fidTeX);
|
|
||||||
end
|
|
||||||
fprintf('MH: Posterior IRFs, done!\n');
|
fprintf('MH: Posterior IRFs, done!\n');
|
|
@ -1,6 +1,4 @@
|
||||||
function dsge_posterior_theoretical_covariance()
|
function dsge_posterior_theoretical_covariance()
|
||||||
|
|
||||||
% function dsge_posterior_theoretical_covariance()
|
|
||||||
% This function estimates the posterior density of the endogenous
|
% This function estimates the posterior density of the endogenous
|
||||||
% variables second order moments.
|
% variables second order moments.
|
||||||
%
|
%
|
||||||
|
@ -11,7 +9,14 @@ function dsge_posterior_theoretical_covariance()
|
||||||
% None.
|
% None.
|
||||||
%
|
%
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% None.
|
% Other matlab routines distributed with Dynare: set_stationary_variables_list.m
|
||||||
|
% CheckPath.m
|
||||||
|
% selec_posterior_draws.m
|
||||||
|
% set_parameters.m
|
||||||
|
% resol.m
|
||||||
|
% th_autocovariances.m
|
||||||
|
% posterior_moments.m
|
||||||
|
%
|
||||||
%
|
%
|
||||||
% part of DYNARE, copyright Dynare Team (2007-2008)
|
% part of DYNARE, copyright Dynare Team (2007-2008)
|
||||||
% Gnu Public License.
|
% Gnu Public License.
|
||||||
|
@ -41,6 +46,11 @@ if ~rows(DrawsFiles)
|
||||||
DrawsFiles = dir([fname '_' type '_draws*']);
|
DrawsFiles = dir([fname '_' type '_draws*']);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
% Get the number of stationary endogenous variables.
|
||||||
|
nvar = length(ivar);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
nar = options_.ar;% Saves size of the auto-correlation function.
|
nar = options_.ar;% Saves size of the auto-correlation function.
|
||||||
options_.ar = 0;% Set the size of the auto-correlation function.
|
options_.ar = 0;% Set the size of the auto-correlation function.
|
||||||
|
|
||||||
|
@ -104,7 +114,8 @@ for i=1:nvar
|
||||||
tmp(i1:i2) = Covariance_matrix(:,idx(i,j,nvar));
|
tmp(i1:i2) = Covariance_matrix(:,idx(i,j,nvar));
|
||||||
i1 = i2+1;
|
i1 = i2+1;
|
||||||
end
|
end
|
||||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(tmp,1);
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = ...
|
||||||
|
posterior_moments(tmp,1,options_.mh_conf_sig);
|
||||||
name = fieldname(i,j,vartan);
|
name = fieldname(i,j,vartan);
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.covariance.mean.' name ' = post_mean;']);
|
eval(['oo_.PosteriorTheoreticalMoments.dsge.covariance.mean.' name ' = post_mean;']);
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.covariance.median.' name ' = post_median;']);
|
eval(['oo_.PosteriorTheoreticalMoments.dsge.covariance.median.' name ' = post_median;']);
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
function dsge_posterior_theoretical_variance_decomposition()
|
function dsge_posterior_theoretical_variance_decomposition()
|
||||||
|
|
||||||
% function dsge_posterior_theoretical_variance_decomposition()
|
|
||||||
% This function estimates the posterior distribution of the variance
|
% This function estimates the posterior distribution of the variance
|
||||||
% decomposition of the observed endogenous variables.
|
% decomposition of the observed endogenous variables.
|
||||||
%
|
%
|
||||||
|
@ -11,7 +9,13 @@ function dsge_posterior_theoretical_variance_decomposition()
|
||||||
% None.
|
% None.
|
||||||
%
|
%
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% None.
|
% Other matlab routines distributed with Dynare: set_stationary_variables_list.m
|
||||||
|
% CheckPath.m
|
||||||
|
% selec_posterior_draws.m
|
||||||
|
% set_parameters.m
|
||||||
|
% resol.m
|
||||||
|
% th_autocovariances.m
|
||||||
|
% posterior_moments.m
|
||||||
%
|
%
|
||||||
% part of DYNARE, copyright Dynare Team (2007-2008).
|
% part of DYNARE, copyright Dynare Team (2007-2008).
|
||||||
% Gnu Public License.
|
% Gnu Public License.
|
||||||
|
@ -133,7 +137,8 @@ for i=1:nvar
|
||||||
post_deciles = NaN(9,1);
|
post_deciles = NaN(9,1);
|
||||||
density = NaN;
|
density = NaN;
|
||||||
else
|
else
|
||||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(tmp,1);
|
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = ...
|
||||||
|
posterior_moments(tmp,1,options_.mh_conf_sig);
|
||||||
end
|
end
|
||||||
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.mean.' name ' = post_mean;']);
|
eval(['oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.mean.' name ' = post_mean;']);
|
||||||
|
|
|
@ -1,72 +1,73 @@
|
||||||
function [abscissa,f] = kernel_density_estimate(data,number_of_grid_points,bandwidth,kernel_function)
|
function [abscissa,f] = kernel_density_estimate(data,number_of_grid_points,number_of_draws,bandwidth,kernel_function)
|
||||||
|
|
||||||
% function [abscissa,f] = kernel_density_estimate(data,number_of_grid_points,bandwidth,kernel_function)
|
|
||||||
% Estimates a continuous density.
|
% Estimates a continuous density.
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
% data: data
|
% data [double] Vector (number_of_draws*1) of draws.
|
||||||
% number_of_grid_points: number of grid points
|
% number_of_grid_points [integer] Scalar, number of points where the density is estimated.
|
||||||
% bandwidth: scalar equals to 0,-1 or -2. For a value different from 0,-1 or -2 the
|
% This (positive) integer must be a power of two.
|
||||||
% function will return optimal_bandwidth = bandwidth.
|
% number_of_draws [integer] Scalar, number of draws.
|
||||||
% kernel_function: 'gaussian','uniform','triangle','epanechnikov',
|
% bandwidth [double] Real positive scalar.
|
||||||
% 'quartic','triweight','cosinus'.
|
% kernel_function [string] Name of the kernel function: 'gaussian', 'triweight',
|
||||||
|
% 'uniform', 'triangle', 'epanechnikov', 'quartic',
|
||||||
|
% 'triweight' and 'cosinus'
|
||||||
%
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% abscissa: value on the abscissa axis
|
% abscissa [double] Vector (number_of_grid_points*1) of values on the abscissa axis.
|
||||||
% f: density
|
% f: [double] Vector (number_of_grid_points*1) of values on the ordinate axis,
|
||||||
|
% (density estimates).
|
||||||
%
|
%
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
|
% none.
|
||||||
|
%
|
||||||
|
% REFERENCES
|
||||||
% A kernel density estimator is used (see Silverman [1986], "Density estimation for statistics and data analysis")
|
% A kernel density estimator is used (see Silverman [1986], "Density estimation for statistics and data analysis")
|
||||||
% The code is adapted from Anders Holtsberg's matlab toolbox (stixbox).
|
% The code is adapted from Anders Holtsberg's matlab toolbox (stixbox).
|
||||||
%
|
%
|
||||||
% part of DYNARE, copyright Dynare Team (2004-2008)
|
% part of DYNARE, copyright Dynare Team (2004-2008)
|
||||||
% Gnu Public License.
|
% Gnu Public License.
|
||||||
|
|
||||||
|
if min(size(data))>1
|
||||||
|
error('kernel_density_estimate:: data must be a one dimensional array.');
|
||||||
if size(data,2) > 1 & size(data,1) == 1
|
else
|
||||||
data = transpose(data);
|
data = data(:);
|
||||||
elseif size(data,2)>1 & size(data,1)>1
|
|
||||||
error('kernel_density_estimate :: data must be a one dimensional array.');
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test = log(number_of_grid_points)/log(2);
|
test = log(number_of_grid_points)/log(2);
|
||||||
if (abs(test-round(test)) > 10^(-12))
|
if (abs(test-round(test)) > 1e-12)
|
||||||
error('kernel_density_estimate :: The number of grid points must be a power of 2.');
|
error('kernel_density_estimate:: The number of grid points must be a power of 2.');
|
||||||
end
|
end
|
||||||
|
|
||||||
n = size(data,1);
|
%% Kernel specification.
|
||||||
|
|
||||||
%% KERNEL SPECIFICATION...
|
|
||||||
if strcmpi(kernel_function,'gaussian')
|
if strcmpi(kernel_function,'gaussian')
|
||||||
k = inline('inv(sqrt(2*pi))*exp(-0.5*x.^2)');
|
kernel = inline('inv(sqrt(2*pi))*exp(-0.5*x.^2)');
|
||||||
elseif strcmpi(kernel_function,'uniform')
|
elseif strcmpi(kernel_function,'uniform')
|
||||||
k = inline('0.5*(abs(x) <= 1)');
|
kernel = inline('0.5*(abs(x) <= 1)');
|
||||||
elseif strcmpi(kernel_function,'triangle')
|
elseif strcmpi(kernel_function,'triangle')
|
||||||
k = inline('(1-abs(x)).*(abs(x) <= 1)');
|
kernel = inline('(1-abs(x)).*(abs(x) <= 1)');
|
||||||
elseif strcmpi(kernel_function,'epanechnikov')
|
elseif strcmpi(kernel_function,'epanechnikov')
|
||||||
k = inline('0.75*(1-x.^2).*(abs(x) <= 1)');
|
kernel = inline('0.75*(1-x.^2).*(abs(x) <= 1)');
|
||||||
elseif strcmpi(kernel_function,'quartic')
|
elseif strcmpi(kernel_function,'quartic')
|
||||||
k = inline('0.9375*((1-x.^2).^2).*(abs(x) <= 1)');
|
kernel = inline('0.9375*((1-x.^2).^2).*(abs(x) <= 1)');
|
||||||
elseif strcmpi(kernel_function,'triweight')
|
elseif strcmpi(kernel_function,'triweight')
|
||||||
k = inline('1.09375*((1-x.^2).^3).*(abs(x) <= 1)');
|
kernel = inline('1.09375*((1-x.^2).^3).*(abs(x) <= 1)');
|
||||||
elseif strcmpi(kernel_function,'cosinus')
|
elseif strcmpi(kernel_function,'cosinus')
|
||||||
k = inline('(pi/4)*cos((pi/2)*x).*(abs(x) <= 1)');
|
kernel = inline('(pi/4)*cos((pi/2)*x).*(abs(x) <= 1)');
|
||||||
end
|
end
|
||||||
|
|
||||||
%% COMPUTE DENSITY ESTIMATE... Gaussian kernel should be used (FFT).
|
%% Non parametric estimation (Gaussian kernel should be used (FFT)).
|
||||||
a = min(data) - (max(data)-min(data))/3;
|
lower_bound = min(data) - (max(data)-min(data))/3;
|
||||||
b = max(data) + (max(data)-min(data))/3;
|
upper_bound = max(data) + (max(data)-min(data))/3;
|
||||||
abscissa = linspace(a,b,number_of_grid_points)';
|
abscissa = linspace(lower_bound,upper_bound,number_of_grid_points)';
|
||||||
d = abscissa(2)-abscissa(1);
|
inc = abscissa(2)-abscissa(1);
|
||||||
xi = zeros(number_of_grid_points,1);
|
xi = zeros(number_of_grid_points,1);
|
||||||
xa = (data-a)/(b-a)*number_of_grid_points;
|
xa = (data-lower_bound)/(upper_bound-lower_bound)*number_of_grid_points;
|
||||||
for i = 1:n;
|
for i = 1:number_of_draws
|
||||||
indx = floor(xa(i));
|
indx = floor(xa(i));
|
||||||
temp = xa(i)-indx;
|
temp = xa(i)-indx;
|
||||||
xi(indx+[1 2]) = xi(indx+[1 2]) + [1-temp,temp]';
|
xi(indx+[1 2]) = xi(indx+[1 2]) + [1-temp,temp]';
|
||||||
end;
|
end
|
||||||
xk = [-number_of_grid_points:number_of_grid_points-1]'*d;
|
xk = [-number_of_grid_points:number_of_grid_points-1]'*inc;
|
||||||
kk = k(xk/bandwidth);
|
kk = kernel(xk/bandwidth);
|
||||||
kk = kk / (sum(kk)*d*n);
|
kk = kk / (sum(kk)*inc*number_of_draws);
|
||||||
f = ifft(fft(fftshift(kk)).*fft([xi ;zeros(size(xi))]));
|
f = ifft(fft(fftshift(kk)).*fft([ xi ; zeros(number_of_grid_points,1) ]));
|
||||||
f = real(f(1:number_of_grid_points));
|
f = real(f(1:number_of_grid_points));
|
|
@ -1,159 +1,165 @@
|
||||||
function optimal_bandwidth = mh_optimal_bandwidth(data,n,bandwidth,kernel_function)
|
function optimal_bandwidth = mh_optimal_bandwidth(data,number_of_draws,bandwidth,kernel_function)
|
||||||
|
|
||||||
% function optimal_bandwidth = mh_optimal_bandwidth(data,n,bandwidth,kernel_function)
|
|
||||||
% This function gives the optimal bandwidth parameter of a kernel estimator
|
% This function gives the optimal bandwidth parameter of a kernel estimator
|
||||||
% used to estimate a posterior univariate density from realisations of a
|
% used to estimate a posterior univariate density from realisations of a
|
||||||
% Metropolis-Hastings algorithm.
|
% Metropolis-Hastings algorithm.
|
||||||
%
|
%
|
||||||
% INPUTS:
|
% INPUTS:
|
||||||
% data: vector with n elements
|
% data [double] Vector (number_of_draws*1) of draws.
|
||||||
% n: number of observations
|
% number_of_draws [integer] Scalar, number of draws.
|
||||||
% bandwidth: scalar equal to 0,-1 or -2. For a value different from 0,-1 or -2 the
|
% bandwidth [integer] Scalar equal to 0,-1 or -2.
|
||||||
% function will return optimal_bandwidth = bandwidth
|
% bandwidth = 0 => Silverman [1986] rule of thumb.
|
||||||
% kernel_function: 'gaussian','uniform','triangle','epanechnikov', 'quartic','triweight','cosinus'
|
% bandwidth = -1 => Sheather and Jones [1991].
|
||||||
|
% bandwidth = -2 => Local bandwith parameters.
|
||||||
|
% kernel_function [string] Name of the kernel function: 'gaussian', 'triweight',
|
||||||
|
% 'uniform', 'triangle', 'epanechnikov', 'quartic',
|
||||||
|
% 'triweight' and 'cosinus'
|
||||||
%
|
%
|
||||||
% OUTPUTS:
|
% OUTPUTS:
|
||||||
% optimal_bandwidth: optimal window width (kernel smoothing)
|
% optimal_bandwidth: [double] Scalar or vector, optimal window width.
|
||||||
%
|
%
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS:
|
||||||
% M. Skold and G.O. Roberts [2003], "Density estimation for the Metropolis-Hastings algorithm".
|
% none.
|
||||||
% Silverman [1986], "Density estimation for statistics and data analysis".
|
%
|
||||||
|
% REFERENCES:
|
||||||
|
% [1] M. Skold and G.O. Roberts [2003], "Density estimation for the Metropolis-Hastings algorithm".
|
||||||
|
% [2] Silverman [1986], "Density estimation for statistics and data analysis".
|
||||||
%
|
%
|
||||||
% part of DYNARE, copyright Dynare Team (2004-2007)
|
% part of DYNARE, copyright Dynare Team (2004-2008)
|
||||||
% Gnu Public License.
|
% Gnu Public License.
|
||||||
|
|
||||||
|
|
||||||
|
%% Kernel specifications.
|
||||||
%% KERNEL SPECIFICATION...
|
if strcmpi(kernel_function,'gaussian')
|
||||||
if strcmpi(kernel_function,'gaussian')
|
% Kernel definition
|
||||||
k = inline('inv(sqrt(2*pi))*exp(-0.5*x.^2)');
|
k = inline('inv(sqrt(2*pi))*exp(-0.5*x.^2)');
|
||||||
k2 = inline('inv(sqrt(2*pi))*(-exp(-0.5*x.^2)+(x.^2).*exp(-0.5*x.^2))'); % second derivate of the gaussian kernel
|
% Second derivate of the kernel function
|
||||||
k4 = inline('inv(sqrt(2*pi))*(3*exp(-0.5*x.^2)-6*(x.^2).*exp(-0.5*x.^2)+(x.^4).*exp(-0.5*x.^2))'); % fourth derivate...
|
k2 = inline('inv(sqrt(2*pi))*(-exp(-0.5*x.^2)+(x.^2).*exp(-0.5*x.^2))');
|
||||||
k6 = inline('inv(sqrt(2*pi))*(-15*exp(-0.5*x.^2)+45*(x.^2).*exp(-0.5*x.^2)-15*(x.^4).*exp(-0.5*x.^2)+(x.^6).*exp(-0.5*x.^2))'); % sixth derivate...
|
% Fourth derivate of the kernel function
|
||||||
mu02 = inv(2*sqrt(pi));
|
k4 = inline('inv(sqrt(2*pi))*(3*exp(-0.5*x.^2)-6*(x.^2).*exp(-0.5*x.^2)+(x.^4).*exp(-0.5*x.^2))');
|
||||||
mu21 = 1;
|
% Sixth derivate of the kernel function
|
||||||
|
k6 = inline(['inv(sqrt(2*pi))*(-15*exp(-0.5*x.^2)+45*(x.^2).*exp(-' ...
|
||||||
|
'0.5*x.^2)-15*(x.^4).*exp(-0.5*x.^2)+(x.^6).*exp(-0.5*x.^2))']);
|
||||||
|
mu02 = inv(2*sqrt(pi));
|
||||||
|
mu21 = 1;
|
||||||
elseif strcmpi(kernel_function,'uniform')
|
elseif strcmpi(kernel_function,'uniform')
|
||||||
k = inline('0.5*(abs(x) <= 1)');
|
k = inline('0.5*(abs(x) <= 1)');
|
||||||
mu02 = 0.5;
|
mu02 = 0.5;
|
||||||
mu21 = 1/3;
|
mu21 = 1/3;
|
||||||
elseif strcmpi(kernel_function,'triangle')
|
elseif strcmpi(kernel_function,'triangle')
|
||||||
k = inline('(1-abs(x)).*(abs(x) <= 1)');
|
k = inline('(1-abs(x)).*(abs(x) <= 1)');
|
||||||
mu02 = 2/3;
|
mu02 = 2/3;
|
||||||
mu21 = 1/6;
|
mu21 = 1/6;
|
||||||
elseif strcmpi(kernel_function,'epanechnikov')
|
elseif strcmpi(kernel_function,'epanechnikov')
|
||||||
k = inline('0.75*(1-x.^2).*(abs(x) <= 1)');
|
k = inline('0.75*(1-x.^2).*(abs(x) <= 1)');
|
||||||
mu02 = 3/5;
|
mu02 = 3/5;
|
||||||
mu21 = 1/5;
|
mu21 = 1/5;
|
||||||
elseif strcmpi(kernel_function,'quartic')
|
elseif strcmpi(kernel_function,'quartic')
|
||||||
k = inline('0.9375*((1-x.^2).^2).*(abs(x) <= 1)');
|
k = inline('0.9375*((1-x.^2).^2).*(abs(x) <= 1)');
|
||||||
mu02 = 15/21;
|
mu02 = 15/21;
|
||||||
mu21 = 1/7;
|
mu21 = 1/7;
|
||||||
elseif strcmpi(kernel_function,'triweight')
|
elseif strcmpi(kernel_function,'triweight')
|
||||||
k = inline('1.09375*((1-x.^2).^3).*(abs(x) <= 1)');
|
k = inline('1.09375*((1-x.^2).^3).*(abs(x) <= 1)');
|
||||||
k2 = inline('(105/4*(1-x.^2).*x.^2-105/16*(1-x.^2).^2).*(abs(x) <= 1)');
|
k2 = inline('(105/4*(1-x.^2).*x.^2-105/16*(1-x.^2).^2).*(abs(x) <= 1)');
|
||||||
k4 = inline('(-1575/4*x.^2+315/4).*(abs(x) <= 1)');
|
k4 = inline('(-1575/4*x.^2+315/4).*(abs(x) <= 1)');
|
||||||
k6 = inline('(-1575/2).*(abs(x) <= 1)');
|
k6 = inline('(-1575/2).*(abs(x) <= 1)');
|
||||||
mu02 = 350/429;
|
mu02 = 350/429;
|
||||||
mu21 = 1/9;
|
mu21 = 1/9;
|
||||||
elseif strcmpi(kernel_function,'cosinus')
|
elseif strcmpi(kernel_function,'cosinus')
|
||||||
k = inline('(pi/4)*cos((pi/2)*x).*(abs(x) <= 1)');
|
k = inline('(pi/4)*cos((pi/2)*x).*(abs(x) <= 1)');
|
||||||
k2 = inline('(-1/16*cos(pi*x/2)*pi^3).*(abs(x) <= 1)');
|
k2 = inline('(-1/16*cos(pi*x/2)*pi^3).*(abs(x) <= 1)');
|
||||||
k4 = inline('(1/64*cos(pi*x/2)*pi^5).*(abs(x) <= 1)');
|
k4 = inline('(1/64*cos(pi*x/2)*pi^5).*(abs(x) <= 1)');
|
||||||
k6 = inline('(-1/256*cos(pi*x/2)*pi^7).*(abs(x) <= 1)');
|
k6 = inline('(-1/256*cos(pi*x/2)*pi^7).*(abs(x) <= 1)');
|
||||||
mu02 = (pi^2)/16;
|
mu02 = (pi^2)/16;
|
||||||
mu21 = (pi^2-8)/pi^2;
|
mu21 = (pi^2-8)/pi^2;
|
||||||
else
|
else
|
||||||
disp('mh_optimal_bandwidth :: ');
|
disp('mh_optimal_bandwidth:: ');
|
||||||
error('This kernel function is not yet implemented in Dynare!');
|
error('This kernel function is not yet implemented in Dynare!');
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
%% OPTIMAL BANDWIDTH PARAMETER....
|
%% Get the Skold and Roberts' correction.
|
||||||
if bandwidth == 0; % Rule of thumb bandwidth parameter (Silverman [1986] corrected by
|
if bandwidth==0 | bandwidth==-1
|
||||||
% Skold and Roberts [2003] for Metropolis-Hastings).
|
correction = correction_for_repeated_draws(data,number_of_draws);
|
||||||
sigma = std(data);
|
else
|
||||||
h = 2*sigma*(sqrt(pi)*mu02/(12*(mu21^2)*n))^(1/5); % Silverman's optimal bandwidth parameter.
|
correction = 0;
|
||||||
A = 0;
|
end
|
||||||
for i=1:n;
|
%% Compute the standard deviation of the draws.
|
||||||
j = i;
|
sigma = std(data);
|
||||||
while j<= n & data(j,1)==data(i,1);
|
%% Optimal bandwidth parameter.
|
||||||
j = j+1;
|
if bandwidth == 0; % Rule of thumb bandwidth parameter (Silverman [1986].
|
||||||
end;
|
h = 2*sigma*(sqrt(pi)*mu02/(12*(mu21^2)*number_of_draws))^(1/5);
|
||||||
A = A + 2*(j-i) - 1;
|
h = h*correction^(1/5);
|
||||||
end;
|
elseif bandwidth == -1; % Sheather and Jones [1991] plug-in estimation of the optimal bandwidth parameter.
|
||||||
A = A/n;
|
|
||||||
h = h*A^(1/5); % correction
|
|
||||||
elseif bandwidth == -1; % Adaptation of the Sheather and Jones [1991] plug-in estimation of the optimal bandwidth
|
|
||||||
% parameter for metropolis hastings algorithm.
|
|
||||||
if strcmp(kernel_function,'uniform') | ...
|
if strcmp(kernel_function,'uniform') | ...
|
||||||
strcmp(kernel_function,'triangle') | ...
|
strcmp(kernel_function,'triangle') | ...
|
||||||
strcmp(kernel_function,'epanechnikov') | ...
|
strcmp(kernel_function,'epanechnikov') | ...
|
||||||
strcmp(kernel_function,'quartic');
|
strcmp(kernel_function,'quartic')
|
||||||
error('I can''t compute the optimal bandwidth with this kernel... Try the gaussian, triweight or cosinus kernels.');
|
error(['I can''t compute the optimal bandwidth with this kernel...' ...
|
||||||
end;
|
'Try the gaussian, triweight or cosinus kernels.']);
|
||||||
sigma = std(data);
|
end
|
||||||
A = 0;
|
Itilda4 = 8*7*6*5/(((2*sigma)^9)*sqrt(pi));
|
||||||
for i=1:n;
|
g3 = abs(2*correction*k6(0)/(mu21*Itilda4*number_of_draws))^(1/9);
|
||||||
j = i;
|
Ihat3 = 0;
|
||||||
while j<= n & data(j,1)==data(i,1);
|
for i=1:number_of_draws
|
||||||
j = j+1;
|
Ihat3 = Ihat3 + sum(k6((data(i,1)-data)/g3));
|
||||||
end;
|
end
|
||||||
A = A + 2*(j-i) - 1;
|
Ihat3 = - Ihat3/((number_of_draws^2)*g3^7);
|
||||||
end;
|
g2 = abs(2*correction*k4(0)/(mu21*Ihat3*number_of_draws))^(1/7);
|
||||||
A = A/n;
|
Ihat2 = 0;
|
||||||
Itilda4 = 8*7*6*5/(((2*sigma)^9)*sqrt(pi));
|
for i=1:number_of_draws
|
||||||
g3 = abs(2*A*k6(0)/(mu21*Itilda4*n))^(1/9);
|
Ihat2 = Ihat2 + sum(k4((data(i)-data)/g2));
|
||||||
Ihat3 = 0;
|
end
|
||||||
for i=1:n;
|
Ihat2 = Ihat2/((number_of_draws^2)*g2^5);
|
||||||
Ihat3 = Ihat3 + sum(k6((data(i,1)-data)/g3));
|
h = (correction*mu02/(number_of_draws*Ihat2*mu21^2))^(1/5); % equation (22) in Skold and Roberts [2003].
|
||||||
end;
|
elseif bandwidth == -2; % Bump killing... I compute local bandwith parameters in order to remove
|
||||||
Ihat3 = -Ihat3/((n^2)*g3^7);
|
|
||||||
g2 = abs(2*A*k4(0)/(mu21*Ihat3*n))^(1/7);
|
|
||||||
Ihat2 = 0;
|
|
||||||
for i=1:n;
|
|
||||||
Ihat2 = Ihat2 + sum(k4((data(i)-data)/g2));
|
|
||||||
end;
|
|
||||||
Ihat2 = Ihat2/((n^2)*g2^5);
|
|
||||||
h = (A*mu02/(n*Ihat2*mu21^2))^(1/5); % equation (22) in Skold and Roberts [2003] --> h_{MH}
|
|
||||||
elseif bandwidth == -2; % Bump killing... We construct local bandwith parameters in order to remove
|
|
||||||
% spurious bumps introduced by long rejecting periods.
|
% spurious bumps introduced by long rejecting periods.
|
||||||
if strcmp(kernel_function,'uniform') | ...
|
if strcmp(kernel_function,'uniform') | ...
|
||||||
strcmp(kernel_function,'triangle') | ...
|
strcmp(kernel_function,'triangle') | ...
|
||||||
strcmp(kernel_function,'epanechnikov') | ...
|
strcmp(kernel_function,'epanechnikov') | ...
|
||||||
strcmp(kernel_function,'quartic');
|
strcmp(kernel_function,'quartic')
|
||||||
error('I can''t compute the optimal bandwidth with this kernel... Try the gaussian, triweight or cosinus kernels.');
|
error(['I can''t compute the optimal bandwidth with this kernel...' ...
|
||||||
end;
|
'Try the gaussian, triweight or cosinus kernels.']);
|
||||||
sigma = std(data);
|
end
|
||||||
A = 0;
|
T = zeros(n,1);
|
||||||
T = zeros(n,1);
|
for i=1:n
|
||||||
for i=1:n;
|
j = i;
|
||||||
j = i;
|
while j<= n & (data(j,1)-data(i,1))<2*eps;
|
||||||
while j<= n & data(j,1)==data(i,1);
|
j = j+1;
|
||||||
j = j+1;
|
end
|
||||||
end;
|
T(i) = (j-i);
|
||||||
T(i) = (j-i);
|
correction = correction + 2*T(i) - 1;
|
||||||
A = A + 2*T(i) - 1;
|
end
|
||||||
end;
|
correction = correction/number_of_draws;
|
||||||
A = A/n;
|
Itilda4 = 8*7*6*5/(((2*sigma)^9)*sqrt(pi));
|
||||||
Itilda4 = 8*7*6*5/(((2*sigma)^9)*sqrt(pi));
|
g3 = abs(2*correction*k6(0)/(mu21*Itilda4*correction))^(1/9);
|
||||||
g3 = abs(2*A*k6(0)/(mu21*Itilda4*n))^(1/9);
|
Ihat3 = 0;
|
||||||
Ihat3 = 0;
|
for i=1:number_of_draws
|
||||||
for i=1:n;
|
Ihat3 = Ihat3 + sum(k6((data(i,1)-data)/g3));
|
||||||
Ihat3 = Ihat3 + sum(k6((data(i,1)-data)/g3));
|
end
|
||||||
end;
|
Ihat3 = -Ihat3/((n^2)*g3^7);
|
||||||
Ihat3 = -Ihat3/((n^2)*g3^7);
|
g2 = abs(2*correction*k4(0)/(mu21*Ihat3*n))^(1/7);
|
||||||
g2 = abs(2*A*k4(0)/(mu21*Ihat3*n))^(1/7);
|
Ihat2 = 0;
|
||||||
Ihat2 = 0;
|
for i=1:number_of_draws;
|
||||||
for i=1:n;
|
Ihat2 = Ihat2 + sum(k4((data(i)-data)/g2));
|
||||||
Ihat2 = Ihat2 + sum(k4((data(i)-data)/g2));
|
end
|
||||||
end;
|
Ihat2 = Ihat2/((number_of_draws^2)*g2^5);
|
||||||
Ihat2 = Ihat2/((n^2)*g2^5);
|
h = ((2*T-1)*mu02/(number_of_draws*Ihat2*mu21^2)).^(1/5); % h is a column vector (local banwidth parameters).
|
||||||
h = ((2*T-1)*mu02/(n*Ihat2*mu21^2)).^(1/5); % Note that h is a column vector (local banwidth parameters).
|
|
||||||
elseif bandwidth > 0
|
|
||||||
h = bandwidth;
|
|
||||||
else
|
else
|
||||||
disp('mh_optimal_bandwidth :: ');
|
disp('mh_optimal_bandwidth:: ');
|
||||||
error('Parameter bandwidth must be a real parameter value or equal to 0,-1 or -2.');
|
error('Parameter bandwidth must be equal to 0, -1 or -2.');
|
||||||
end
|
end
|
||||||
|
|
||||||
optimal_bandwidth = h;
|
optimal_bandwidth = h;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function correction = correction_for_repeated_draws(draws,n)
|
||||||
|
correction = 0;
|
||||||
|
for i=1:n
|
||||||
|
j = i;
|
||||||
|
while j<=n & ( draws(j,1) - draws(i,1) )<2*eps;
|
||||||
|
j = j+1;
|
||||||
|
end
|
||||||
|
correction = correction + 2*(j-i) - 1;
|
||||||
|
end
|
||||||
|
correction = correction/n;
|
|
@ -40,7 +40,8 @@ function pm3(n1,n2,ifil,B,tit1,tit2,tit3,tit_tex,names1,names2,name3,DirectoryNa
|
||||||
tmp =zeros(B,1);
|
tmp =zeros(B,1);
|
||||||
for i = 1:nvar
|
for i = 1:nvar
|
||||||
for j = 1:n2
|
for j = 1:n2
|
||||||
[Mean(j,i),Median(j,i),Var(j,i),HPD(:,j,i),Distrib(:,j,i)] = posterior_moments(squeeze(stock1(SelecVariables(i),j,:)),0);
|
[Mean(j,i),Median(j,i),Var(j,i),HPD(:,j,i),Distrib(:,j,i)] = ...
|
||||||
|
posterior_moments(squeeze(stock1(SelecVariables(i),j,:)),0,options_.mh_conf_sig);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
clear stock1
|
clear stock1
|
||||||
|
|
|
@ -1,29 +1,28 @@
|
||||||
function [post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(xx,info)
|
function [post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(xx,info,mh_conf_sig)
|
||||||
|
|
||||||
% function [post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(xx,info)
|
|
||||||
% Computes posterior mean, median, variance, HPD interval, deciles, and density from posterior draws.
|
% Computes posterior mean, median, variance, HPD interval, deciles, and density from posterior draws.
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
% xx: vector of posterior draws
|
% xx [double] Vector of posterior draws (or prior draws ;-)
|
||||||
% info=1: estimates posterior density
|
% info [integer] If equal to one the posterior density is estimated.
|
||||||
% info=0: computes moments
|
% mh_config_sig [double] Scalar between 0 and 1 specifying the size of the HPD interval.
|
||||||
%
|
%
|
||||||
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% post_mean: posterior mean
|
% post_mean [double] Scalar, posterior mean.
|
||||||
% post_median: median
|
% post_median [double] Scalar, posterior median.
|
||||||
% post_var: variance
|
% post_var [double] Scalar, posterior variance.
|
||||||
% hpd_interval: HPD interval
|
% hpd_interval [double] Vector (1*2), Highest Probability Density interval
|
||||||
% post_deciles: post deciles
|
% post_deciles [double] Vector (9*1), deciles of the posterior distribution.
|
||||||
% density: density
|
% density [double] Matrix (n*2), non parametric estimate of the posterior density. First and second
|
||||||
|
% columns are respectively abscissa and ordinate coordinates.
|
||||||
%
|
%
|
||||||
% SPECIAL REQUIREMENTS
|
% SPECIAL REQUIREMENTS
|
||||||
% none
|
% Other matlab routines distributed with Dynare: mh_optimal_bandwidth.m
|
||||||
%
|
% kernel_density_estimate.m.
|
||||||
|
%
|
||||||
% part of DYNARE, copyright Dynare Team (2005-2008)
|
% part of DYNARE, copyright Dynare Team (2005-2008)
|
||||||
% Gnu Public License.
|
% Gnu Public License.
|
||||||
|
|
||||||
global options_
|
|
||||||
|
|
||||||
xx = xx(:);
|
xx = xx(:);
|
||||||
xx = sort(xx);
|
xx = sort(xx);
|
||||||
|
|
||||||
|
@ -32,33 +31,33 @@ post_mean = mean(xx);
|
||||||
post_median = median(xx);
|
post_median = median(xx);
|
||||||
post_var = var(xx);
|
post_var = var(xx);
|
||||||
|
|
||||||
n = length(xx);
|
number_of_draws = length(xx);
|
||||||
m = round((1-options_.mh_conf_sig)*n);
|
hpd_draws = round((1-mh_conf_sig)*number_of_draws);
|
||||||
k = zeros(m,1);
|
kk = zeros(hpd_draws,1);
|
||||||
jj = n-m;
|
jj = number_of_draws-hpd_draws;
|
||||||
for ii = 1:m
|
for ii = 1:hpd_draws
|
||||||
k(ii) = xx(jj)-xx(ii);
|
kk(ii) = xx(jj)-xx(ii);
|
||||||
jj = jj + 1;
|
jj = jj + 1;
|
||||||
end
|
end
|
||||||
[kmin,idx] = min(k);
|
[kmin,idx] = min(kk);
|
||||||
hpd_interval = [xx(idx) xx(idx)+kmin];
|
hpd_interval = [xx(idx) xx(idx)+kmin];
|
||||||
|
|
||||||
post_deciles = xx([round(0.1*n) ...
|
post_deciles = xx([round(0.1*number_of_draws) ...
|
||||||
round(0.2*n)...
|
round(0.2*number_of_draws) ...
|
||||||
round(0.3*n)...
|
round(0.3*number_of_draws) ...
|
||||||
round(0.4*n)...
|
round(0.4*number_of_draws) ...
|
||||||
round(0.5*n)...
|
round(0.5*number_of_draws) ...
|
||||||
round(0.6*n)...
|
round(0.6*number_of_draws) ...
|
||||||
round(0.7*n)...
|
round(0.7*number_of_draws) ...
|
||||||
round(0.8*n)...
|
round(0.8*number_of_draws) ...
|
||||||
round(0.9*n)]);
|
round(0.9*number_of_draws)]);
|
||||||
|
|
||||||
if ~info
|
density = [];
|
||||||
density = [];
|
if info
|
||||||
else
|
number_of_grid_points = 2^9; % 2^9 = 512 !... Must be a power of two.
|
||||||
number_of_grid_points = 2^9; % 2^9 = 512 !... Must be a power of two.
|
bandwidth = 0; % Rule of thumb optimal bandwidth parameter.
|
||||||
bandwidth = 0; % Rule of thumb optimal bandwidth parameter.
|
kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourrier Transform approximaton.
|
||||||
kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourrier Transform approximaton.
|
optimal_bandwidth = mh_optimal_bandwidth(xx,number_of_draws,bandwidth,kernel_function);
|
||||||
optimal_bandwidth = mh_optimal_bandwidth(xx,length(xx),bandwidth,kernel_function);
|
[density(:,1),density(:,2)] = kernel_density_estimate(xx,number_of_grid_points,...
|
||||||
[density(:,1),density(:,2)] = kernel_density_estimate(xx,number_of_grid_points,optimal_bandwidth,kernel_function);
|
number_of_draws,optimal_bandwidth,kernel_function);
|
||||||
end
|
end
|
Loading…
Reference in New Issue