Home > matlab > mh_autocorrelation_function.m

mh_autocorrelation_function

PURPOSE ^

This function plots the autocorrelation of the sampled draws in the

SYNOPSIS ^

function mh_autocorrelation_function(options_,M_,estim_params_,type,blck,name1,name2)

DESCRIPTION ^

 This function plots the autocorrelation of the sampled draws in the
 posterior distribution.
 

 INPUTS 

   options_        [structure]    Dynare structure.
   M_              [structure]    Dynare structure (related to model definition).
   estim_params_   [structure]    Dynare structure (related to estimation).
   type            [string]       'DeepParameter', 'MeasurementError' (for measurement equation error) or 'StructuralShock' (for structural shock).
   blck            [integer]      Number of the mh chain.
   name1           [string]       Object name.
   name2           [string]       Object name. 
    
 OUTPUTS 
   None
        
 SPECIAL REQUIREMENTS

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mh_autocorrelation_function(options_,M_,estim_params_,type,blck,name1,name2)
0002 % This function plots the autocorrelation of the sampled draws in the
0003 % posterior distribution.
0004 %
0005 %
0006 % INPUTS
0007 %
0008 %   options_        [structure]    Dynare structure.
0009 %   M_              [structure]    Dynare structure (related to model definition).
0010 %   estim_params_   [structure]    Dynare structure (related to estimation).
0011 %   type            [string]       'DeepParameter', 'MeasurementError' (for measurement equation error) or 'StructuralShock' (for structural shock).
0012 %   blck            [integer]      Number of the mh chain.
0013 %   name1           [string]       Object name.
0014 %   name2           [string]       Object name.
0015 %
0016 % OUTPUTS
0017 %   None
0018 %
0019 % SPECIAL REQUIREMENTS
0020 
0021 % Copyright (C) 2003-2009 Dynare Team
0022 %
0023 % This file is part of Dynare.
0024 %
0025 % Dynare is free software: you can redistribute it and/or modify
0026 % it under the terms of the GNU General Public License as published by
0027 % the Free Software Foundation, either version 3 of the License, or
0028 % (at your option) any later version.
0029 %
0030 % Dynare is distributed in the hope that it will be useful,
0031 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0032 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0033 % GNU General Public License for more details.
0034 %
0035 % You should have received a copy of the GNU General Public License
0036 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0037 
0038 % Cet the column index:
0039 if nargin<7    
0040     column = name2index(options_, M_, estim_params_, type, name1);
0041 else
0042     column = name2index(options_, M_, estim_params_, type, name1, name2);
0043 end
0044 
0045 if isempty(column)
0046     return
0047 end
0048 
0049 % Get informations about the posterior draws:
0050 DirectoryName = CheckPath('metropolis',M_.dname);
0051 try
0052     load([DirectoryName '/' M_.fname '_mh_history.mat']); 
0053 catch
0054     disp(['trace_plot:: I can''t find ' M_.fname '_results.mat !'])
0055     disp(['trace_plot:: Did you run a metropolis?'])
0056     return
0057 end
0058 
0059 FirstMhFile = record.KeepedDraws.FirstMhFile;
0060 FirstLine = record.KeepedDraws.FirstLine; ifil = FirstLine;
0061 TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
0062 TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
0063 NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
0064 clear record;
0065 
0066 % Get all the posterior draws:
0067 PosteriorDraws = GetAllPosteriorDraws(column, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws, blck);
0068 
0069 % Compute the autocorrelation function:
0070 [autocov,autocor] = sample_autocovariance(PosteriorDraws,options_.mh_autocorrelation_function_size);
0071 
0072 % Plot the posterior draws:
0073 
0074 if strcmpi(type,'DeepParameter')
0075     TYPE = 'parameter ';
0076 elseif strcmpi(type,'StructuralShock')
0077     if nargin<7
0078         TYPE = 'the standard deviation of structural shock ';
0079     else
0080         TYPE = 'the correlation between structural shocks ';
0081     end
0082 elseif strcmpi(type,'MeasurementError')
0083     if nargin<7
0084         TYPE = 'the standard deviation of measurement error ';
0085     else
0086         TYPE = 'the correlation between measurement errors ';
0087     end
0088 end
0089 
0090 if nargin<7
0091     FigureName = ['autocorrelogram for ' TYPE name1];
0092 else
0093     FigureName = ['autocorrelogram for ' TYPE name1 ' and ' name2];
0094 end
0095 
0096 if options_.mh_nblck>1
0097     FigureName = [ FigureName , ' (block number' int2str(blck)  ').']; 
0098 end
0099 
0100 
0101 figure('Name',FigureName)
0102 bar(0:options_.mh_autocorrelation_function_size,autocor,'k');
0103 axis tight

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005