+ Changed some files so that they can handle prior montecarlo.
+ New version of prior_analysis.m. + Changed names and calls. + Bug fix. + Cosmetic changes. git-svn-id: https://www.dynare.org/svn/dynare/trunk@2765 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
bdabde9b58
commit
5695c1d528
|
@ -0,0 +1,96 @@
|
||||||
|
function oo_ = conditional_variance_decomposition_mc_analysis(NumberOfSimulations, typr, dname, fname, Steps, exonames, exo, vartan, var, mh_conf_sig, oo_)
|
||||||
|
% This function analyses the (posterior or prior) distribution of the
|
||||||
|
% endogenous conditional variance decomposition.
|
||||||
|
|
||||||
|
% Copyright (C) 2009 Dynare Team
|
||||||
|
%
|
||||||
|
% This file is part of Dynare.
|
||||||
|
%
|
||||||
|
% Dynare is free software: you can redistribute it and/or modify
|
||||||
|
% it under the terms of the GNU General Public License as published by
|
||||||
|
% the Free Software Foundation, either version 3 of the License, or
|
||||||
|
% (at your option) any later version.
|
||||||
|
%
|
||||||
|
% Dynare is distributed in the hope that it will be useful,
|
||||||
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
% GNU General Public License for more details.
|
||||||
|
%
|
||||||
|
% You should have received a copy of the GNU General Public License
|
||||||
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
if strcmpi(type,'posterior')
|
||||||
|
TYPE = 'Posterior';
|
||||||
|
PATH = [dname '/metropolis/'];
|
||||||
|
else
|
||||||
|
TYPE = 'Prior';
|
||||||
|
PATH = [dname '/prior/moments/'];
|
||||||
|
end
|
||||||
|
|
||||||
|
indx = check_name(vartan,var);
|
||||||
|
if isempty(indx)
|
||||||
|
disp([ type '_analysis:: ' var ' is not a stationary endogenous variable!'])
|
||||||
|
return
|
||||||
|
end
|
||||||
|
endogenous_variable_index = sum(1:indx);
|
||||||
|
exogenous_variable_index = check_name(exonames,exo);
|
||||||
|
if isempty(exogenous_variable_index)
|
||||||
|
disp([ type '_analysis:: ' exo ' is not a declared exogenous variable!'])
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
name = [ var '.' exo ];
|
||||||
|
if isfield(oo_, [ TYPE 'TheoreticalMoments' ])
|
||||||
|
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments;'])
|
||||||
|
if isfield(temporary_structure,'dsge')
|
||||||
|
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge;'])
|
||||||
|
if isfield(temporary_structure,'ConditionalVarianceDecomposition')
|
||||||
|
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge.VarianceDecomposition.mean;'])
|
||||||
|
if isfield(temporary_structure,name)
|
||||||
|
if sum(Steps-temporary_structure.(name)(1,:)) == 0
|
||||||
|
% Nothing (new) to do here...
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ListOfFiles = dir([ PATH fname '_' TYPE 'ConditionalVarianceDecomposition*.mat']);
|
||||||
|
i1 = 1; tmp = zeros(NumberOfSimulations,length(Steps));
|
||||||
|
for file = 1:length(ListOfFiles)
|
||||||
|
load([ PATH fname ListOfFiles(file).name ]);
|
||||||
|
% 4D-array (endovar,time,exovar,simul)
|
||||||
|
i2 = i1 + size(Conditional_decomposition_array,4) - 1;
|
||||||
|
tmp(i1:i2,:) = transpose(dynare_squeeze(Conditional_decomposition_array(endogenous_variable_index,:,exogenous_variable_index,:)));
|
||||||
|
i1 = i2+1;
|
||||||
|
end
|
||||||
|
|
||||||
|
p_mean = NaN(2,length(Steps));
|
||||||
|
p_mean(1,:) = Steps;
|
||||||
|
p_median = NaN(1,length(Steps));
|
||||||
|
p_variance = NaN(1,length(Steps));
|
||||||
|
p_deciles = NaN(9,length(Steps));
|
||||||
|
p_density = NaN(2^9,2,length(Steps));
|
||||||
|
p_hpdinf = NaN(1,length(Steps));
|
||||||
|
p_hpdsup = NaN(1,length(Steps));
|
||||||
|
for i=1:length(Steps)
|
||||||
|
if ~isconst(tmp(:,i))
|
||||||
|
[pp_mean, pp_median, pp_var, hpd_interval, pp_deciles, pp_density] = ...
|
||||||
|
posterior_moments(tmp(:,i),1,mh_conf_sig);
|
||||||
|
p_mean(2,i) = pp_mean;
|
||||||
|
p_median(i) = pp_median;
|
||||||
|
p_variance(i) = pp_var;
|
||||||
|
p_deciles(:,i) = pp_deciles;
|
||||||
|
p_hpdinf(i) = hpd_interval(1);
|
||||||
|
p_hpdinf(i) = hpd_interval(2);
|
||||||
|
p_density(:,:,i) = pp_density;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.ConditionalVarianceDecomposition.mean.' name ' = p_mean;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.ConditionalVarianceDecomposition.median.' name ' = p_median;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.ConditionalVarianceDecomposition.variance.' name ' = p_variance;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.ConditionalVarianceDecomposition.hpdinf.' name ' = p_hpdinf;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.ConditionalVarianceDecomposition.hpdsup.' name ' = p_hpdsup;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.ConditionalVarianceDecomposition.deciles.' name ' = p_deciles;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.ConditionalVarianceDecomposition.density.' name ' = p_density;']);
|
|
@ -1,83 +0,0 @@
|
||||||
function oo_ = conditional_variance_decomposition_posterior_analysis(NumberOfSimulations, dname, fname, ...
|
|
||||||
Steps, exonames, exo, vartan, var, mh_conf_sig, oo_)
|
|
||||||
% Copyright (C) 2009 Dynare Team
|
|
||||||
%
|
|
||||||
% This file is part of Dynare.
|
|
||||||
%
|
|
||||||
% Dynare is free software: you can redistribute it and/or modify
|
|
||||||
% it under the terms of the GNU General Public License as published by
|
|
||||||
% the Free Software Foundation, either version 3 of the License, or
|
|
||||||
% (at your option) any later version.
|
|
||||||
%
|
|
||||||
% Dynare is distributed in the hope that it will be useful,
|
|
||||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
% GNU General Public License for more details.
|
|
||||||
%
|
|
||||||
% You should have received a copy of the GNU General Public License
|
|
||||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
indx = check_name(vartan,var);
|
|
||||||
if isempty(indx)
|
|
||||||
disp(['posterior_analysis:: ' var ' is not a stationary endogenous variable!'])
|
|
||||||
return
|
|
||||||
end
|
|
||||||
endogenous_variable_index = sum(1:indx);
|
|
||||||
exogenous_variable_index = check_name(exonames,exo);
|
|
||||||
if isempty(exogenous_variable_index)
|
|
||||||
disp(['posterior_analysis:: ' exo ' is not a declared exogenous variable!'])
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
tmp = dir([ dname '/metropolis/' fname '_PosteriorConditionalVarianceDecomposition*.mat']);
|
|
||||||
NumberOfFiles = length(tmp);
|
|
||||||
i1 = 1; tmp = zeros(NumberOfSimulations,length(Steps));
|
|
||||||
|
|
||||||
for file = 1:NumberOfFiles
|
|
||||||
load([dname '/metropolis/' fname '_PosteriorConditionalVarianceDecomposition' int2str(file) '.mat']);
|
|
||||||
% (endovar,time,exovar,simul)
|
|
||||||
i2 = i1 + size(Conditional_decomposition_array,4) - 1;
|
|
||||||
tmp(i1:i2,:) = transpose(dynare_squeeze(Conditional_decomposition_array(endogenous_variable_index,:,exogenous_variable_index,:)));
|
|
||||||
i1 = i2+1;
|
|
||||||
end
|
|
||||||
name = [ var '.' exo ];
|
|
||||||
if isfield(oo_,'PosteriorTheoreticalMoments')
|
|
||||||
if isfield(oo_.PosteriorTheoreticalMoments,'dsge')
|
|
||||||
if isfield(oo_.PosteriorTheoreticalMoments.dsge,'ConditionalVarianceDecomposition')
|
|
||||||
if isfield(oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.mean,name)
|
|
||||||
if sum(Steps-oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.mean.(name)(1,:)) == 0
|
|
||||||
% Nothing (new) to do here...
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
posterior_mean = NaN(2,length(Steps));
|
|
||||||
posterior_mean(1,:) = Steps;
|
|
||||||
posterior_median = NaN(1,length(Steps));
|
|
||||||
posterior_variance = NaN(1,length(Steps));
|
|
||||||
posterior_deciles = NaN(9,length(Steps));
|
|
||||||
posterior_density = NaN(2^9,2,length(Steps));
|
|
||||||
posterior_hpdinf = NaN(1,length(Steps));
|
|
||||||
posterior_hpdsup = NaN(1,length(Steps));
|
|
||||||
for i=1:length(Steps)
|
|
||||||
if ~isconst(tmp(:,i))
|
|
||||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = ...
|
|
||||||
posterior_moments(tmp(:,i),1,mh_conf_sig);
|
|
||||||
posterior_mean(2,i) = post_mean;
|
|
||||||
posterior_median(i) = post_median;
|
|
||||||
posterior_variance(i) = post_var;
|
|
||||||
posterior_deciles(:,i) = post_deciles;
|
|
||||||
posterior_hpdinf(i) = hpd_interval(1);
|
|
||||||
posterior_hpdinf(i) = hpd_interval(2);
|
|
||||||
posterior_density(:,:,i) = density;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.ConditionalVarianceDecomposition.mean.' name ' = posterior_mean;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.ConditionalVarianceDecomposition.median.' name ' = posterior_median;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.ConditionalVarianceDecomposition.variance.' name ' = posterior_variance;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.ConditionalVarianceDecomposition.hpdinf.' name ' = posterior_hpdinf;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.ConditionalVarianceDecomposition.hpdsup.' name ' = posterior_hpdsup;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.ConditionalVarianceDecomposition.deciles.' name ' = posterior_deciles;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.ConditionalVarianceDecomposition.density.' name ' = posterior_density;']);
|
|
|
@ -21,10 +21,10 @@ function oo_ = correlation_mc_analysis(SampleSize,type,dname,fname,vartan,nvar,v
|
||||||
|
|
||||||
if strcmpi(type,'posterior')
|
if strcmpi(type,'posterior')
|
||||||
TYPE = 'Posterior';
|
TYPE = 'Posterior';
|
||||||
PATH = [dname '/metropolis/']
|
PATH = [dname '/metropolis/'];
|
||||||
else
|
else
|
||||||
TYPE = 'Prior';
|
TYPE = 'Prior';
|
||||||
PATH = [dname '/prior/moments/']
|
PATH = [dname '/prior/moments/'];
|
||||||
end
|
end
|
||||||
|
|
||||||
indx1 = check_name(vartan,var1);
|
indx1 = check_name(vartan,var1);
|
||||||
|
@ -84,7 +84,7 @@ function oo_ = correlation_mc_analysis(SampleSize,type,dname,fname,vartan,nvar,v
|
||||||
ListOfFiles = dir([ PATH fname '_' TYPE 'Correlations*.mat']);
|
ListOfFiles = dir([ PATH fname '_' TYPE 'Correlations*.mat']);
|
||||||
i1 = 1; tmp = zeros(SampleSize,1);
|
i1 = 1; tmp = zeros(SampleSize,1);
|
||||||
for file = 1:length(ListOfFiles)
|
for file = 1:length(ListOfFiles)
|
||||||
load([ PATH fname '_' TYPE 'PosteriorCorrelations' int2str(file) '.mat']);
|
load([ PATH ListOfFiles(file).name ]);
|
||||||
i2 = i1 + rows(Correlation_array) - 1;
|
i2 = i1 + rows(Correlation_array) - 1;
|
||||||
tmp(i1:i2) = Correlation_array(:,indx1,indx2,nar);
|
tmp(i1:i2) = Correlation_array(:,indx1,indx2,nar);
|
||||||
i1 = i2+1;
|
i1 = i2+1;
|
||||||
|
@ -93,7 +93,7 @@ function oo_ = correlation_mc_analysis(SampleSize,type,dname,fname,vartan,nvar,v
|
||||||
if ~isconst(tmp)
|
if ~isconst(tmp)
|
||||||
[p_mean, p_median, p_var, hpd_interval, p_deciles, density] = ...
|
[p_mean, p_median, p_var, hpd_interval, p_deciles, density] = ...
|
||||||
posterior_moments(tmp,1,mh_conf_sig);
|
posterior_moments(tmp,1,mh_conf_sig);
|
||||||
if isfield(oo_,'PosteriorTheoreticalMoments')
|
if isfield(oo_,[ TYPE 'TheoreticalMoments'])
|
||||||
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments;'])
|
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments;'])
|
||||||
if isfield(temporary_structure,'dsge')
|
if isfield(temporary_structure,'dsge')
|
||||||
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge;'])
|
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge;'])
|
||||||
|
|
|
@ -61,7 +61,7 @@ function oo_ = job(type,SampleSize,arg1,arg2,arg3,options_,M_,oo_,nvar,vartan)
|
||||||
[nvar,vartan,NumberOfFiles] = ...
|
[nvar,vartan,NumberOfFiles] = ...
|
||||||
dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,'posterior');
|
dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,'posterior');
|
||||||
end
|
end
|
||||||
oo_ = variance_decomposition_posterior_analysis(SampleSize,M_.dname,M_.fname,...
|
oo_ = variance_decomposition_mc_analysis(SampleSize,'posterior',M_.dname,M_.fname,...
|
||||||
M_.exo_names,arg2,vartan,arg1,options_.mh_conf_sig,oo_);
|
M_.exo_names,arg2,vartan,arg1,options_.mh_conf_sig,oo_);
|
||||||
case OB'correlation'
|
case OB'correlation'
|
||||||
if nargin==narg1
|
if nargin==narg1
|
||||||
|
@ -75,7 +75,7 @@ function oo_ = job(type,SampleSize,arg1,arg2,arg3,options_,M_,oo_,nvar,vartan)
|
||||||
[nvar,vartan,NumberOfFiles] = ...
|
[nvar,vartan,NumberOfFiles] = ...
|
||||||
dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,arg3,M_,options_,oo_,'posterior');
|
dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,arg3,M_,options_,oo_,'posterior');
|
||||||
end
|
end
|
||||||
oo_ = conditional_variance_decomposition_posterior_analysis(SampleSize,M_.dname,M_.fname,...
|
oo_ = conditional_variance_decomposition_mc_analysis(SampleSize,'posterior',M_.dname,M_.fname,...
|
||||||
arg3,M_.exo_names,arg2,vartan,arg1,options_.mh_conf_sig,oo_);
|
arg3,M_.exo_names,arg2,vartan,arg1,options_.mh_conf_sig,oo_);
|
||||||
otherwise
|
otherwise
|
||||||
disp('Not yet implemented')
|
disp('Not yet implemented')
|
||||||
|
|
|
@ -1,47 +1,83 @@
|
||||||
function prior_analysis(var_list)
|
function oo_ = prior_analysis(type,arg1,arg2,arg3,options_,M_,oo_)
|
||||||
|
% Copyright (C) 2009 Dynare Team
|
||||||
% function prior_analysis(var_list)
|
%
|
||||||
% performs stochastic simulations for value of parameters drawn from
|
% This file is part of Dynare.
|
||||||
% the prior
|
%
|
||||||
%
|
% Dynare is free software: you can redistribute it and/or modify
|
||||||
% INPUTS:
|
% it under the terms of the GNU General Public License as published by
|
||||||
% var_list: list of variable names for which results are requested
|
% the Free Software Foundation, either version 3 of the License, or
|
||||||
%
|
% (at your option) any later version.
|
||||||
% OUTPUTS:
|
%
|
||||||
% none
|
% Dynare is distributed in the hope that it will be useful,
|
||||||
%
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
% SPECIAL REQUIREMENTS
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
% none.
|
% GNU General Public License for more details.
|
||||||
%
|
%
|
||||||
|
% You should have received a copy of the GNU General Public License
|
||||||
% Copyright (C) 2006-2008 Dynare Team
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
%
|
|
||||||
% This file is part of Dynare.
|
info = check_prior_analysis_data(type,M_);
|
||||||
%
|
SampleSize = options_.prior_mc;
|
||||||
% Dynare is free software: you can redistribute it and/or modify
|
switch info
|
||||||
% it under the terms of the GNU General Public License as published by
|
case {0,1,2}
|
||||||
% the Free Software Foundation, either version 3 of the License, or
|
MaxMegaBytes = options_.MaximumNumberOfMegaBytes;
|
||||||
% (at your option) any later version.
|
drsize = size_of_the_reduced_form_model(oo_.dr);
|
||||||
%
|
if drsize*SampleSize>MaxMegaBytes
|
||||||
% Dynare is distributed in the hope that it will be useful,
|
drsave=0;
|
||||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
else
|
||||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
drsave=1;
|
||||||
% GNU General Public License for more details.
|
end
|
||||||
%
|
load([M_.dname '/prior/definition.mat']);
|
||||||
% You should have received a copy of the GNU General Public License
|
prior_sampler(drsave,M_,bayestopt_,options_,oo_);
|
||||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
clear('bayestopt_');
|
||||||
|
oo_ = job(type,SampleSize,arg1,arg2,arg3,options_,M_,oo_);
|
||||||
global M_ options_ oo_ estim_params_ bayestopt_
|
case {4,5}
|
||||||
|
oo_ = job(type,SampleSize,arg1,arg2,arg3,options_,M_,oo_);
|
||||||
old_options = options_;
|
case 6
|
||||||
if options_.replic < 100
|
[ivar,vartan] = set_stationary_variables_list;
|
||||||
warning('Prior analysis requires at least 100 replications, preferably many more! options replic reset to 100')
|
nvar = length(ivar);
|
||||||
options_.replic = 100;
|
oo_ = job(type,SampleSize,arg1,arg2,arg3,options_,M_,oo_,nvar,vartan);
|
||||||
end
|
otherwise
|
||||||
|
error(['prior_analysis:: Check_prior_analysis_data gave a meaningless output!'])
|
||||||
options_.order = 1;
|
end
|
||||||
if options_.forecast
|
|
||||||
forcst_unc(oo_.endo_simul(:,1:M_.maximum_lag),var_list);
|
|
||||||
end
|
|
||||||
|
function oo_ = job(type,SampleSize,arg1,arg2,arg3,options_,M_,oo_,nvar,vartan)
|
||||||
options_ = old_options;
|
narg1 = 8;
|
||||||
|
narg2 = 10;
|
||||||
|
if ~(nargin==narg1 || nargin==narg2)
|
||||||
|
error('prior_analysis:: Call to function job is buggy!')
|
||||||
|
end
|
||||||
|
switch type
|
||||||
|
case 'variance'
|
||||||
|
if nargin==narg1
|
||||||
|
[nvar,vartan,NumberOfFiles] = ...
|
||||||
|
dsge_simulated_theoretical_covariance(SampleSize,M_,options_,oo_,'prior');
|
||||||
|
end
|
||||||
|
oo_ = covariance_mc_analysis(SampleSize,'prior',M_.dname,M_.fname,...
|
||||||
|
vartan,nvar,arg1,arg2,options_.mh_conf_sig,oo_);
|
||||||
|
case 'decomposition'
|
||||||
|
if nargin==narg1
|
||||||
|
[nvar,vartan,NumberOfFiles] = ...
|
||||||
|
dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,'prior');
|
||||||
|
end
|
||||||
|
oo_ = variance_decomposition_mc_analysis(SampleSize,'prior',M_.dname,M_.fname,...
|
||||||
|
M_.exo_names,arg2,vartan,arg1,options_.mh_conf_sig,oo_);
|
||||||
|
case 'correlation'
|
||||||
|
if nargin==narg1
|
||||||
|
[nvar,vartan,NumberOfFiles] = ...
|
||||||
|
dsge_simulated_theoretical_correlation(SampleSize,arg3,M_,options_,oo_,'prior');
|
||||||
|
end
|
||||||
|
oo_ = correlation_mc_analysis(SampleSize,'prior',M_.dname,M_.fname,...
|
||||||
|
vartan,nvar,arg1,arg2,arg3,options_.mh_conf_sig,oo_,M_,options_);
|
||||||
|
case 'conditional decomposition'
|
||||||
|
if nargin==narg1
|
||||||
|
[nvar,vartan,NumberOfFiles] = ...
|
||||||
|
dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,arg3,M_,options_,oo_,'prior');
|
||||||
|
end
|
||||||
|
oo_ = conditional_variance_decomposition_mc_analysis(SampleSize,'prior',M_.dname,M_.fname,...
|
||||||
|
arg3,M_.exo_names,arg2,vartan,arg1,options_.mh_conf_sig,oo_);
|
||||||
|
otherwise
|
||||||
|
disp('Not yet implemented')
|
||||||
|
end
|
|
@ -0,0 +1,91 @@
|
||||||
|
function oo_ = variance_decomposition_mc_analysis(NumberOfSimulations,type,dname,fname,exonames,exo,vartan,var,mh_conf_sig,oo_)
|
||||||
|
% This function analyses the (posterior or prior) distribution of the
|
||||||
|
% endogenous variance decomposition.
|
||||||
|
|
||||||
|
% Copyright (C) 2008-2009 Dynare Team
|
||||||
|
%
|
||||||
|
% This file is part of Dynare.
|
||||||
|
%
|
||||||
|
% Dynare is free software: you can redistribute it and/or modify
|
||||||
|
% it under the terms of the GNU General Public License as published by
|
||||||
|
% the Free Software Foundation, either version 3 of the License, or
|
||||||
|
% (at your option) any later version.
|
||||||
|
%
|
||||||
|
% Dynare is distributed in the hope that it will be useful,
|
||||||
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
% GNU General Public License for more details.
|
||||||
|
%
|
||||||
|
% You should have received a copy of the GNU General Public License
|
||||||
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
if strcmpi(type,'posterior')
|
||||||
|
TYPE = 'Posterior';
|
||||||
|
PATH = [dname '/metropolis/'];
|
||||||
|
else
|
||||||
|
TYPE = 'Prior';
|
||||||
|
PATH = [dname '/prior/moments/'];
|
||||||
|
end
|
||||||
|
|
||||||
|
indx = check_name(vartan,var);
|
||||||
|
if isempty(indx)
|
||||||
|
disp([ type '_analysis:: ' var ' is not a stationary endogenous variable!'])
|
||||||
|
return
|
||||||
|
end
|
||||||
|
jndx = check_name(exonames,exo);
|
||||||
|
if isempty(jndx)
|
||||||
|
disp([ type '_analysis:: ' exo ' is not a declared exogenous variable!'])
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
name = [ var '.' exo ];
|
||||||
|
if isfield(oo_, [ TYPE 'TheoreticalMoments'])
|
||||||
|
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments;'])
|
||||||
|
if isfield(temporary_structure,'dsge')
|
||||||
|
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge;'])
|
||||||
|
if isfield(temporary_structure,'VarianceDecomposition')
|
||||||
|
eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge.VarianceDecomposition.mean;'])
|
||||||
|
if isfield(temporary_structure,name)
|
||||||
|
% Nothing to do.
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ListOfFiles = dir([ PATH fname '_' Type 'VarianceDecomposition*.mat']);
|
||||||
|
i1 = 1; tmp = zeros(NumberOfSimulations,1);
|
||||||
|
indice = (indx-1)*rows(exonames)+jndx;
|
||||||
|
for file = 1:length(LengthOfFiles)
|
||||||
|
load([ PATH ListOfFiles(file).name ]);
|
||||||
|
i2 = i1 + rows(Decomposition_array) - 1;
|
||||||
|
tmp(i1:i2) = Decomposition_array(:,indice);
|
||||||
|
i1 = i2+1;
|
||||||
|
end
|
||||||
|
|
||||||
|
t1 = min(tmp); t2 = max(tmp);
|
||||||
|
t3 = t2-t1;% How to normalize ? t1 and t2 may be zero...
|
||||||
|
if t3<1.0e-12
|
||||||
|
if t1<1.0e-12
|
||||||
|
t1 = 0;
|
||||||
|
end
|
||||||
|
if abs(t1-1)<1.0e-12
|
||||||
|
t1 = 1;
|
||||||
|
end
|
||||||
|
p_mean = t1;
|
||||||
|
p_median = t1;
|
||||||
|
p_var = 0;
|
||||||
|
hpd_interval = NaN(2,1);
|
||||||
|
post_deciles = NaN(9,1);
|
||||||
|
density = NaN;
|
||||||
|
else
|
||||||
|
[p_mean, p_median, p_var, hpd_interval, p_deciles, density] = ...
|
||||||
|
posterior_moments(tmp,1,mh_conf_sig);
|
||||||
|
end
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.VarianceDecomposition.mean.' name ' = p_mean;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.VarianceDecomposition.median.' name ' = p_median;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.VarianceDecomposition.variance.' name ' = p_var;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.VarianceDecomposition.hpdinf.' name ' = hpd_interval(1);']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.VarianceDecomposition.hpdsup.' name ' = hpd_interval(2);']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.VarianceDecomposition.deciles.' name ' = p_deciles;']);
|
||||||
|
eval(['oo_.' TYPE 'TheoreticalMoments.dsge.VarianceDecomposition.density.' name ' = density;']);
|
|
@ -1,77 +0,0 @@
|
||||||
function oo_ = variance_decomposition_posterior_analysis(NumberOfSimulations,dname,fname, ...
|
|
||||||
exonames,exo,vartan,var,mh_conf_sig,oo_)
|
|
||||||
|
|
||||||
% Copyright (C) 2008 Dynare Team
|
|
||||||
%
|
|
||||||
% This file is part of Dynare.
|
|
||||||
%
|
|
||||||
% Dynare is free software: you can redistribute it and/or modify
|
|
||||||
% it under the terms of the GNU General Public License as published by
|
|
||||||
% the Free Software Foundation, either version 3 of the License, or
|
|
||||||
% (at your option) any later version.
|
|
||||||
%
|
|
||||||
% Dynare is distributed in the hope that it will be useful,
|
|
||||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
% GNU General Public License for more details.
|
|
||||||
%
|
|
||||||
% You should have received a copy of the GNU General Public License
|
|
||||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
indx = check_name(vartan,var);
|
|
||||||
if isempty(indx)
|
|
||||||
disp(['posterior_analysis:: ' var ' is not a stationary endogenous variable!'])
|
|
||||||
return
|
|
||||||
end
|
|
||||||
jndx = check_name(exonames,exo);
|
|
||||||
if isempty(jndx)
|
|
||||||
disp(['posterior_analysis:: ' exo ' is not a declared exogenous variable!'])
|
|
||||||
return
|
|
||||||
end
|
|
||||||
tmp = dir([ dname '/metropolis/' fname '_PosteriorVarianceDecomposition*.mat']);
|
|
||||||
NumberOfFiles = length(tmp);
|
|
||||||
i1 = 1; tmp = zeros(NumberOfSimulations,1);
|
|
||||||
indice = (indx-1)*rows(exonames)+jndx;
|
|
||||||
for file = 1:NumberOfFiles
|
|
||||||
load([dname '/metropolis/' fname '_PosteriorVarianceDecomposition' int2str(file) '.mat']);
|
|
||||||
i2 = i1 + rows(Decomposition_array) - 1;
|
|
||||||
tmp(i1:i2) = Decomposition_array(:,indice);
|
|
||||||
i1 = i2+1;
|
|
||||||
end
|
|
||||||
name = [ var '.' exo ];
|
|
||||||
if isfield(oo_,'PosteriorTheoreticalMoments')
|
|
||||||
if isfield(oo_.PosteriorTheoreticalMoments,'dsge')
|
|
||||||
if isfield(oo_.PosteriorTheoreticalMoments.dsge,'VarianceDecomposition')
|
|
||||||
if isfield(oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.mean,name)
|
|
||||||
% Nothing to do.
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
t1 = min(tmp); t2 = max(tmp);
|
|
||||||
t3 = t2-t1;% How to normalize ? t1 and t2 may be zero...
|
|
||||||
if t3<1.0e-12
|
|
||||||
if t1<1.0e-12
|
|
||||||
t1 = 0;
|
|
||||||
end
|
|
||||||
if abs(t1-1)<1.0e-12
|
|
||||||
t1 = 1;
|
|
||||||
end
|
|
||||||
post_mean = t1;
|
|
||||||
post_median = t1;
|
|
||||||
post_var = 0;
|
|
||||||
hpd_interval = NaN(2,1);
|
|
||||||
post_deciles = NaN(9,1);
|
|
||||||
density = NaN;
|
|
||||||
else
|
|
||||||
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = ...
|
|
||||||
posterior_moments(tmp,1,mh_conf_sig);
|
|
||||||
end
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.mean.' name ' = post_mean;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.median.' name ' = post_median;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.variance.' name ' = post_var;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.hpdinf.' name ' = hpd_interval(1);']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.hpdsup.' name ' = hpd_interval(2);']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.deciles.' name ' = post_deciles;']);
|
|
||||||
eval(['oo_.PosteriorTheoreticalMoments.dsge.VarianceDecomposition.density.' name ' = density;']);
|
|
Loading…
Reference in New Issue