0001 function mh_autocorrelation_function(options_,M_,estim_params_,type,blck,name1,name2)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
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
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
0067 PosteriorDraws = GetAllPosteriorDraws(column, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws, blck);
0068
0069
0070 [autocov,autocor] = sample_autocovariance(PosteriorDraws,options_.mh_autocorrelation_function_size);
0071
0072
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