Home > matlab > covariance_mc_analysis.m

covariance_mc_analysis

PURPOSE ^

This function analyses the (posterior or prior) distribution of the

SYNOPSIS ^

function oo_ = covariance_mc_analysis(NumberOfSimulations,type,dname,fname,vartan,nvar,var1,var2,mh_conf_sig,oo_)

DESCRIPTION ^

 This function analyses the (posterior or prior) distribution of the
 endogenous variables covariance matrix.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function oo_ = covariance_mc_analysis(NumberOfSimulations,type,dname,fname,vartan,nvar,var1,var2,mh_conf_sig,oo_)
0002 % This function analyses the (posterior or prior) distribution of the
0003 % endogenous variables covariance matrix.
0004 
0005 % Copyright (C) 2008-2009 Dynare Team
0006 %
0007 % This file is part of Dynare.
0008 %
0009 % Dynare is free software: you can redistribute it and/or modify
0010 % it under the terms of the GNU General Public License as published by
0011 % the Free Software Foundation, either version 3 of the License, or
0012 % (at your option) any later version.
0013 %
0014 % Dynare is distributed in the hope that it will be useful,
0015 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 % GNU General Public License for more details.
0018 %
0019 % You should have received a copy of the GNU General Public License
0020 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0021 
0022 if strcmpi(type,'posterior')
0023     TYPE = 'Posterior';
0024     PATH = [dname '/metropolis/'];
0025 else
0026     TYPE = 'Prior';
0027     PATH = [dname '/prior/moments/'];
0028 end
0029 
0030 indx1 = check_name(vartan,var1);
0031 if isempty(indx1)
0032     disp([ type '_analysis:: ' var1 ' is not a stationary endogenous variable!'])
0033     return
0034 end
0035 if ~isempty(var2)
0036     indx2 = check_name(vartan,var2);
0037     if isempty(indx2)
0038         disp([ type '_analysis:: ' var2 ' is not a stationary endogenous variable!'])
0039         return
0040     end
0041 else
0042     indx2 = indx1;
0043     var2 = var1;
0044 end
0045 
0046 if isfield(oo_,[ TYPE 'TheoreticalMoments'])
0047     eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments;'])   
0048     if isfield(temporary_structure,'dsge')
0049         eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge;'])
0050         if isfield(temporary_structure,'covariance')
0051             eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge.covariance.mean;'])
0052             if isfield(temporary_structure,var1)
0053                 eval(['temporary_structure_1 = oo_.' TYPE 'TheoreticalMoments.dsge.covariance.mean.' var1 ';'])
0054                 if isfield(temporary_structure_1,var2)
0055                     % Nothing to do (the covariance matrix is symmetric!).
0056                     return
0057                 end
0058             else
0059                 if isfield(temporary_structure,var2)
0060                     eval(['temporary_structure_2 = oo_.' TYPE 'TheoreticalMoments.dsge.covariance.mean.' var2 ';'])
0061                     if isfield(temporary_structure_2,var1)
0062                         % Nothing to do (the covariance matrix is symmetric!).
0063                         return
0064                     end
0065                 end
0066             end
0067         end
0068     end
0069 end
0070 
0071 ListOfFiles = dir([ PATH  fname '_' TYPE '2ndOrderMoments*.mat']);
0072 i1 = 1; tmp = zeros(NumberOfSimulations,1);
0073 for file = 1:length(ListOfFiles)
0074     load([ PATH ListOfFiles(file).name ]);
0075     i2 = i1 + rows(Covariance_matrix) - 1;
0076     tmp(i1:i2) = Covariance_matrix(:,symmetric_matrix_index(indx1,indx2,nvar));
0077     i1 = i2+1;
0078 end
0079 name = [var1 '.' var2];
0080 if ~isconst(tmp)
0081     [p_mean, p_median, p_var, hpd_interval, p_deciles, density] = ...
0082         posterior_moments(tmp,1,mh_conf_sig);
0083     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.mean.' name ' = p_mean;']);
0084     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.median.' name ' = p_median;']);
0085     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.variance.' name ' = p_var;']);
0086     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.hpdinf.' name ' = hpd_interval(1);']);
0087     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.hpdsup.' name ' = hpd_interval(2);']);
0088     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.deciles.' name ' = p_deciles;']);
0089     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.density.' name ' = density;']);
0090 else
0091     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.mean.' name ' = NaN;']);
0092     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.median.' name ' = NaN;']);
0093     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.variance.' name ' = NaN;']);
0094     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.hpdinf.' name ' = NaN;']);
0095     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.hpdsup.' name ' = NaN;']);
0096     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.deciles.' name ' = NaN;']);
0097     eval(['oo_.' TYPE 'TheoreticalMoments.dsge.covariance.density.' name ' = NaN;']);
0098 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005