Commit e3043c41 authored by stepan's avatar stepan
Browse files

+ Changed dsge_simulated_theoretical_*.m files. They can be used to compute the prior distribution

  of second order moments and variance decompositions.
+ Changed calls to dsge_simulated_theoretical_* functions.
+ Fixed headers.
+ Cosmetic changes.


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2759 ac1d8469-bf42-47a9-8791-bf33cf982152
parent b04e6519
function DirectoryName = CheckPath(type)
% Creates the subfolder "./M_.dname/type" if it does not exist yet.
%
% INPUTS
......
function [nvar,vartan,NumberOfConditionalDecompFiles] = ...
dsge_posterior_theoretical_conditional_variance_decomposition(SampleSize,Steps,M_,options_,oo_)
% This function estimates the posterior distribution of the conditional variance
dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,Steps,M_,options_,oo_,type)
% This function computes the posterior or prior distribution of the conditional variance
% decomposition of the endogenous variables (or a subset of the endogenous variables).
%
% INPUTS
% SampleSize [integer] scalar, number of draws in the posterior distribution.
% Steps [integer] 1*h vector of dates.
%
% OUTPUTS
% nvar [integer] scalar, number of endogenous variables.
% vartan [string] array, list of endogenous variables.
% NumberOfConditionalDecompFiles [integer] scalar.
% SampleSize [integer] scalar, number of simulations.
% M_ [structure] Dynare structure describing the model.
% options_ [structure] Dynare structure defining global options.
% oo_ [structure] Dynare structure where the results are saved.
% type [string] 'prior' or 'posterior'
%
%
% OUTPUTS
% nvar [integer] nvar is the number of stationary variables.
% vartan [char] array of characters (with nvar rows).
% NumberOfConditionalDecompFiles [integer] scalar, number of prior or posterior data files (for covariance).
% Copyright (C) 2009 Dynare Team
%
......@@ -29,8 +33,6 @@ function [nvar,vartan,NumberOfConditionalDecompFiles] = ...
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
type = 'posterior';% To be defined as a input argument later...
% Set varlist (vartan)
[ivar,vartan] = set_stationary_variables_list;
nvar = length(ivar);
......@@ -40,7 +42,17 @@ nar = options_.ar;
options_.ar = 0;
% Get informations about the _posterior_draws files.
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
if strcmpi(type,'posterior')
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
posterior = 0;
else
disp('dsge_simulated_theoretical_conditional_variance_decomposition:: Unknown type!')
error()
end
NumberOfDrawsFiles = length(DrawsFiles);
NumberOfDrawsFiles = rows(DrawsFiles);
......@@ -74,7 +86,11 @@ aux(k,2) = aux(k,2) + oo_.dr.nfwrd;
linea = 0;
for file = 1:NumberOfDrawsFiles
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
if posterior
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
else
load([M_.dname '/prior/draws/' DrawsFiles(file).name ]);
end
isdrsaved = columns(pdraws)-1;
NumberOfDraws = rows(pdraws);
for linee = 1:NumberOfDraws
......@@ -91,8 +107,13 @@ for file = 1:NumberOfDrawsFiles
clear('dr');
Conditional_decomposition_array(:,:,:,linea) = conditional_variance_decomposition(StateSpaceModel, Steps, ivar);
if linea == NumberOfConditionalDecompLines
save([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
'Conditional_decomposition_array');
if posterior
save([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
'Conditional_decomposition_array');
else
save([M_.dname '/prior/moments/' M_.fname '_PriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
'Conditional_decomposition_array');
end
ConditionalDecompFileNumber = ConditionalDecompFileNumber + 1;
linea = 0;
test = ConditionalDecompFileNumber-NumberOfConditionalDecompFiles;
......
function [nvar,vartan,CorrFileNumber] = dsge_posterior_theoretical_correlation(SampleSize,nar,M_,options_,oo_)
%function [nvar,vartan,CorrFileNumber] = dsge_posterior_theoretical_correlation(SampleSize,nar,M_,options_,oo_)
% This function estimates the posterior density of the endogenous
function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(SampleSize,nar,M_,options_,oo_,type)
% This function computes the posterior or prior distribution of the endogenous
% variables second order moments.
%
% INPUTS
% SampleSize [integer]
%
%
% nar [integer]
% M_ [structure]
% options_ [structure]
% oo_ [structure]
% type [string]
%
% OUTPUTS
% None.
%
% SPECIAL REQUIREMENTS
% 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
% nvar [integer]
% vartan [char]
% CorrFileNumber [integer]
% Copyright (C) 2007-2009 Dynare Team
%
......@@ -37,7 +32,6 @@ function [nvar,vartan,CorrFileNumber] = dsge_posterior_theoretical_correlation(S
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
type = 'posterior';
nodecomposition = 1;
% Set varlist (vartan)
......@@ -49,7 +43,16 @@ oldnar = options_.ar;
options_.ar = nar;
% Get informations about the _posterior_draws files.
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
if strcmpi(type,'posterior')
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
posterior = 0;
else
disp('dsge_simulated_theoretical_correlation:: Unknown type!');
error()
end
NumberOfDrawsFiles = length(DrawsFiles);
% Number of lines in posterior data files.
......@@ -67,10 +70,14 @@ end
NumberOfCorrLines = rows(Correlation_array);
CorrFileNumber = 1;
% Compute 2nd order moments and save them in *_PosteriorCorrelations* files
% Compute 2nd order moments and save them in *_[Posterior, Prior]Correlations* files
linea = 0;
for file = 1:NumberOfDrawsFiles
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
if posterior
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
else
load([M_.dname '/prior/draws/' DrawsFiles(file).name]);
end
NumberOfDraws = rows(pdraws);
isdrsaved = columns(pdraws)-1;
for linee = 1:NumberOfDraws
......@@ -86,7 +93,11 @@ for file = 1:NumberOfDrawsFiles
Correlation_array(linea,:,:,i) = tmp{i+1};
end
if linea == NumberOfCorrLines
save([ M_.dname '/metropolis/' M_.fname '_PosteriorCorrelations' int2str(CorrFileNumber) '.mat' ],'Correlation_array');
if posterior
save([ M_.dname '/metropolis/' M_.fname '_PosteriorCorrelations' int2str(CorrFileNumber) '.mat' ],'Correlation_array');
else
save([ M_.dname '/prior/moments/' M_.fname '_PriorCorrelations' int2str(CorrFileNumber) '.mat' ],'Correlation_array');
end
CorrFileNumber = CorrFileNumber + 1;
linea = 0;
test = CorrFileNumber-NumberOfCorrFiles;
......
function [nvar,vartan,CovarFileNumber] = dsge_posterior_theoretical_covariance(SampleSize,M_,options_,oo_)
% This function estimates the posterior density of the endogenous
function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(SampleSize,M_,options_,oo_,type)
% This function computes the posterior or prior distribution of the endogenous
% variables second order moments.
%
% INPUTS
% SampleSize [integer]
%
% SampleSize [integer] scalar, number of simulations.
% M_ [structure] Dynare structure describing the model.
% options_ [structure] Dynare structure defining global options.
% oo_ [structure] Dynare structure where the results are saved.
% type [string] 'prior' or 'posterior'
%
%
% OUTPUTS
% None.
%
% SPECIAL REQUIREMENTS
% 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
% OUTPUTS
% nvar [integer] nvar is the number of stationary variables.
% vartan [char] array of characters (with nvar rows).
% CovarFileNumber [integer] scalar, number of prior or posterior data files (for covariance).
% Copyright (C) 2007-2009 Dynare Team
%
......@@ -36,7 +32,6 @@ function [nvar,vartan,CovarFileNumber] = dsge_posterior_theoretical_covariance(S
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
type = 'posterior';
nodecomposition = 1;
% Set varlist (vartan)
......@@ -48,7 +43,16 @@ nar = options_.ar;
options_.ar = 0;
% Get informations about the _posterior_draws files.
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
if strcmpi(type,'posterior')
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
posterior = 0;
else
disp('dsge_simulated_theoretical_covariance:: Unknown type!')
error();
end
NumberOfDrawsFiles = length(DrawsFiles);
% Number of lines in posterior data files.
......@@ -66,10 +70,14 @@ end
NumberOfCovarLines = rows(Covariance_matrix);
CovarFileNumber = 1;
% Compute 2nd order moments and save them in *_Posterior2ndOrderMoments* files
% Compute 2nd order moments and save them in *_[Posterior, Prior]2ndOrderMoments* files
linea = 0;
for file = 1:NumberOfDrawsFiles
load([M_.dname '/metropolis/' DrawsFiles(file).name ],'pdraws');
if posterior
load([M_.dname '/metropolis/' DrawsFiles(file).name ],'pdraws');
else
load([M_.dname '/prior/draws/' DrawsFiles(file).name ],'pdraws');
end
NumberOfDraws = rows(pdraws);
isdrsaved = columns(pdraws)-1;
for linee = 1:NumberOfDraws
......@@ -87,7 +95,11 @@ for file = 1:NumberOfDrawsFiles
end
end
if linea == NumberOfCovarLines
save([ M_.dname '/metropolis/' M_.fname '_Posterior2ndOrderMoments' int2str(CovarFileNumber) '.mat' ],'Covariance_matrix');
if posterior
save([ M_.dname '/metropolis/' M_.fname '_Posterior2ndOrderMoments' int2str(CovarFileNumber) '.mat' ],'Covariance_matrix');
else
save([ M_.dname '/prior/moments/' M_.fname '_Prior2ndOrderMoments' int2str(CovarFileNumber) '.mat' ],'Covariance_matrix');
end
CovarFileNumber = CovarFileNumber + 1;
linea = 0;
test = CovarFileNumber-NumberOfCovarFiles;
......
function [nvar,vartan,NumberOfDecompFiles] = ...
dsge_posterior_theoretical_variance_decomposition(SampleSize,M_,options_,oo_)
% This function estimates the posterior distribution of the variance
dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,type)
% This function computes the posterior or prior distribution of the variance
% decomposition of the observed endogenous variables.
%
% INPUTS
% None.
%
% OUTPUTS
% None.
% SampleSize [integer] scalar, number of simulations.
% M_ [structure] Dynare structure describing the model.
% options_ [structure] Dynare structure defining global options.
% oo_ [structure] Dynare structure where the results are saved.
% type [string] 'prior' or 'posterior'
%
% SPECIAL REQUIREMENTS
% 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
%
% OUTPUTS
% nvar [integer] nvar is the number of stationary variables.
% vartan [char] array of characters (with nvar rows).
% CovarFileNumber [integer] scalar, number of prior or posterior data files (for covariance).
% Copyright (C) 2007-2009 Dynare Team
%
......@@ -35,7 +33,6 @@ function [nvar,vartan,NumberOfDecompFiles] = ...
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
type = 'posterior';% To be defined as a input argument later...
nodecomposition = 0;
% Set varlist (vartan)
......@@ -47,7 +44,16 @@ nar = options_.ar;
options_.ar = 0;
% Get informations about the _posterior_draws files.
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
if strcmpi(type,'posterior')
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
posterior = 1;
elseif strcmpi(type,'prior')
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
posterior = 0;
else
disp('dsge_simulated_theoretical_variance_decomposition:: Unknown type!')
error()
end
NumberOfDrawsFiles = length(DrawsFiles);
nexo = M_.exo_nbr;
......@@ -68,12 +74,15 @@ end
NumberOfDecompLines = rows(Decomposition_array);
DecompFileNumber = 1;
% Compute total variances (covariances are not saved) and variances
% implied by each structural shock.
linea = 0;
for file = 1:NumberOfDrawsFiles
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
if posterior
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
else
load([M_.dname '/prior/draws/' DrawsFiles(file).name ]);
end
isdrsaved = columns(pdraws)-1;
NumberOfDraws = rows(pdraws);
for linee = 1:NumberOfDraws
......@@ -91,7 +100,11 @@ for file = 1:NumberOfDrawsFiles
end
end
if linea == NumberOfDecompLines
save([M_.dname '/metropolis/' M_.fname '_PosteriorVarianceDecomposition' int2str(DecompFileNumber) '.mat' ],'Decomposition_array');
if posterior
save([M_.dname '/metropolis/' M_.fname '_PosteriorVarianceDecomposition' int2str(DecompFileNumber) '.mat' ],'Decomposition_array');
else
save([M_.dname '/prior/moments/' M_.fname '_PriorVarianceDecomposition' int2str(DecompFileNumber) '.mat' ],'Decomposition_array');
end
DecompFileNumber = DecompFileNumber + 1;
linea = 0;
test = DecompFileNumber-NumberOfDecompFiles;
......
......@@ -52,28 +52,28 @@ function oo_ = job(type,SampleSize,arg1,arg2,arg3,options_,M_,oo_,nvar,vartan)
case 'variance'
if nargin==narg1
[nvar,vartan,NumberOfFiles] = ...
dsge_posterior_theoretical_covariance(SampleSize,M_,options_,oo_);
dsge_simulated_theoretical_covariance(SampleSize,M_,options_,oo_,'posterior');
end
oo_ = covariance_posterior_analysis(SampleSize,M_.dname,M_.fname,...
vartan,nvar,arg1,arg2,options_.mh_conf_sig,oo_);
case 'decomposition'
if nargin==narg1
[nvar,vartan,NumberOfFiles] = ...
dsge_posterior_theoretical_variance_decomposition(SampleSize,M_,options_,oo_);
dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,'posterior');
end
oo_ = variance_decomposition_posterior_analysis(SampleSize,M_.dname,M_.fname,...
M_.exo_names,arg2,vartan,arg1,options_.mh_conf_sig,oo_);
case 'correlation'
if nargin==narg1
[nvar,vartan,NumberOfFiles] = ...
dsge_posterior_theoretical_correlation(SampleSize,arg3,M_,options_,oo_);
dsge_simulated_theoretical_correlation(SampleSize,arg3,M_,options_,oo_,'posterior');
end
oo_ = correlation_posterior_analysis(SampleSize,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_posterior_theoretical_conditional_variance_decomposition(SampleSize,arg3,M_,options_,oo_);
dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,arg3,M_,options_,oo_,'posterior');
end
oo_ = conditional_variance_decomposition_posterior_analysis(SampleSize,M_.dname,M_.fname,...
arg3,M_.exo_names,arg2,vartan,arg1,options_.mh_conf_sig,oo_);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment