0001 function trace_plot(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 if nargin<7
0039 column = name2index(options_, M_, estim_params_, type, name1);
0040 else
0041 column = name2index(options_, M_, estim_params_, type, name1, name2);
0042 end
0043
0044 if isempty(column)
0045 return
0046 end
0047
0048
0049 DirectoryName = CheckPath('metropolis',M_.dname);
0050 try
0051 load([DirectoryName '/' M_.fname '_mh_history.mat']);
0052 catch
0053 disp(['trace_plot:: I can''t find ' M_.fname '_results.mat !'])
0054 disp(['trace_plot:: Did you run a metropolis?'])
0055 return
0056 end
0057
0058 FirstMhFile = 1;
0059 FirstLine = 1;
0060 TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
0061 TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
0062 clear record;
0063
0064
0065 PosteriorDraws = GetAllPosteriorDraws(column, FirstMhFile, FirstLine, TotalNumberOfMhFiles, TotalNumberOfMhDraws, blck);
0066
0067
0068
0069
0070 if strcmpi(type,'DeepParameter')
0071 TYPE = 'parameter ';
0072 elseif strcmpi(type,'StructuralShock')
0073 if nargin<7
0074 TYPE = 'the standard deviation of structural shock ';
0075 else
0076 TYPE = 'the correlation between structural shocks ';
0077 end
0078 elseif strcmpi(type,'MeasurementError')
0079 if nargin<7
0080 TYPE = 'the standard deviation of measurement error ';
0081 else
0082 TYPE = 'the correlation between measurement errors ';
0083 end
0084 end
0085
0086 if nargin<7
0087 FigureName = ['trace plot for ' TYPE name1];
0088 else
0089 FigureName = ['trace plot for ' TYPE name1 ' and ' name2];
0090 end
0091
0092 if options_.mh_nblck>1
0093 FigureName = [ FigureName , ' (block number' int2str(blck) ').'];
0094 end
0095
0096
0097 figure('Name',FigureName)
0098 plot(1:TotalNumberOfMhDraws,PosteriorDraws,'Color',[.8 .8 .8]);
0099
0100
0101
0102
0103 N = options_.trace_plot_ma;
0104 MovingAverage = NaN(TotalNumberOfMhDraws,1);
0105 first = N+1;
0106 last = TotalNumberOfMhDraws-N;
0107
0108 for t=first:last
0109 MovingAverage(t) = mean(PosteriorDraws(t-N:t+N));
0110 end
0111
0112 hold on
0113 plot(1:TotalNumberOfMhDraws,MovingAverage,'-k','linewidth',2)
0114 hold off
0115 axis tight