Home > matlab > correlation_mc_analysis.m

correlation_mc_analysis

PURPOSE ^

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

SYNOPSIS ^

function oo_ = correlation_mc_analysis(SampleSize,type,dname,fname,vartan,nvar,var1,var2,nar,mh_conf_sig,oo_,M_,options_)

DESCRIPTION ^

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function oo_ = correlation_mc_analysis(SampleSize,type,dname,fname,vartan,nvar,var1,var2,nar,mh_conf_sig,oo_,M_,options_)
0002 % This function analyses the (posterior or prior) distribution of the
0003 % endogenous variables correlation function.
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,'correlation')
0051             eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge.correlation.mean;'])
0052             if isfield(temporary_structure,var1)
0053                 eval(['temporary_structure_1 = oo_.' TYPE 'TheoreticalMoments.dsge.correlation.mean.' var1 ';']) 
0054                 if isfield(temporary_structure_1,var2)
0055                     eval(['temporary_structure_2 = temporary_structure_1.' var2 ';'])
0056                     l1 = length(temporary_structure_2);
0057                     if l1<nar
0058                         % INITIALIZATION:
0059                         oo_ = initialize_output_structure(var1,var2,nar,type,oo_);
0060                         delete([PATH fname '_' TYPE 'Correlations*'])
0061                         [nvar,vartan,NumberOfFiles] = ...
0062                             dsge_simulated_theoretical_correlation(SampleSize,nar,M_,options_,oo_,type);
0063                     else
0064                         if ~isnan(temporary_structure_2(nar))
0065                             %Nothing to do.
0066                             return
0067                         end
0068                     end
0069                 else
0070                     oo_ = initialize_output_structure(var1,var2,nar,TYPE,oo_);
0071                 end
0072             else
0073                 oo_ = initialize_output_structure(var1,var2,nar,TYPE,oo_);
0074             end
0075         else
0076             oo_ = initialize_output_structure(var1,var2,nar,TYPE,oo_);
0077         end
0078     else
0079         oo_ = initialize_output_structure(var1,var2,nar,TYPE,oo_);
0080     end
0081 else
0082     oo_ = initialize_output_structure(var1,var2,nar,TYPE,oo_);
0083 end
0084 ListOfFiles = dir([ PATH  fname '_' TYPE 'Correlations*.mat']);
0085 i1 = 1; tmp = zeros(SampleSize,1);
0086 for file = 1:length(ListOfFiles)
0087     load([ PATH  ListOfFiles(file).name ]);
0088     i2 = i1 + rows(Correlation_array) - 1;
0089     tmp(i1:i2) = Correlation_array(:,indx1,indx2,nar);
0090     i1 = i2+1;
0091 end
0092 name = [ var1 '.' var2 ];
0093 if ~isconst(tmp)
0094     [p_mean, p_median, p_var, hpd_interval, p_deciles, density] = ...
0095         posterior_moments(tmp,1,mh_conf_sig);
0096     if isfield(oo_,[ TYPE 'TheoreticalMoments'])
0097         eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments;'])
0098         if isfield(temporary_structure,'dsge')
0099             eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge;'])
0100             if isfield(temporary_structure,'correlation')
0101                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'mean',nar,p_mean);
0102                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'median',nar,p_median);
0103                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'variance',nar,p_var);
0104                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'hpdinf',nar,hpd_interval(1));
0105                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'hpdsup',nar,hpd_interval(2));
0106                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'deciles',nar,p_deciles);
0107                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'density',nar,density);
0108             end
0109         end
0110     end
0111 else
0112     if isfield(oo_,'PosteriorTheoreticalMoments')
0113         eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments;'])
0114         if isfield(temporary_structure,'dsge')
0115             eval(['temporary_structure = oo_.' TYPE 'TheoreticalMoments.dsge;'])
0116             if isfield(temporary_structure,'correlation')
0117                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'mean',nar,NaN);
0118                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'median',nar,NaN);
0119                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'variance',nar,NaN);
0120                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'hpdinf',nar,NaN);
0121                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'hpdsup',nar,NaN);
0122                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'deciles',nar,NaN);
0123                 oo_ = fill_output_structure(var1,var2,TYPE,oo_,'density',nar,NaN);
0124             end
0125         end
0126     end
0127 end
0128 
0129 function oo_ = initialize_output_structure(var1,var2,nar,type,oo_)
0130 name = [ var1 '.' var2 ];
0131 eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.mean.' name ' = NaN(' int2str(nar) ',1);']);
0132 eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.median.' name ' = NaN(' int2str(nar) ',1);']);
0133 eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.variance.' name ' = NaN(' int2str(nar) ',1);']);
0134 eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.hpdinf.' name ' = NaN(' int2str(nar) ',1);']);
0135 eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.hpdsup.' name ' = NaN(' int2str(nar) ',1);']);
0136 eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.deciles.' name ' = cell(' int2str(nar) ',1);']);
0137 eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.density.' name ' = cell(' int2str(nar) ',1);']);
0138 for i=1:nar
0139     eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.density.' name '(' int2str(i) ',1) = {NaN};']);
0140     eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.deciles.' name '(' int2str(i) ',1) = {NaN};']);
0141 end
0142 
0143 function oo_ = fill_output_structure(var1,var2,type,oo_,moment,lag,result)
0144 name = [ var1 '.' var2 ];
0145 switch moment
0146   case {'mean','median','variance','hpdinf','hpdsup'} 
0147     eval(['oo_.' type  'TheoreticalMoments.dsge.correlation.' moment '.' name '(' int2str(lag) ',1) = result;']);
0148   case {'deciles','density'}
0149     eval(['oo_.' type 'TheoreticalMoments.dsge.correlation.' moment '.' name '(' int2str(lag) ',1) = {result};']);
0150   otherwise
0151     disp('fill_output_structure:: Unknown field!')
0152 end

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