-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmbe_gelmanPlot.m
44 lines (38 loc) · 1.3 KB
/
mbe_gelmanPlot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function mbe_gelmanPlot(mcmcParam)
%% mbe_gelmanPlot
% This plot shows the evolution of Gelman and Rubin's shrink factor as
% the number of iterations increases. More than one chain is needed.
%
% INPUT:
% mcmcParam
% 2d matrix with MCMC parameter as column vector for every chain
%
% EXAMPLE:
% mbe_gelmanPlot(mcmcParam);
% Nils Winter ([email protected])
% Johann-Wolfgang-Goethe University, Frankfurt
% Created: 2016-03-22
% Version: v2.00 (2016-04-13)
%-------------------------------------------------------------------------
nChains = size(mcmcParam,2);
% Shrink factor only works for more than one chain
if nChains > 1
% Create right format for psrf.m
for indChain = 1:nChains
X(:,1,indChain) = mcmcParam(:,indChain);
end
% Calculate shrink factor for increasing number of steps to see evolution
nSteps = size(X,1);
maxBins = 50;
binSize = floor((nSteps-50) / maxBins);
R = [];
for indSteps = 50:binSize:nSteps
R(end+1) = psrf(X(1:indSteps,:,:));
end
% Plot evolution of shrink factor
plot(50:binSize:nSteps,R);
xlabel('last iteration in chain','FontWeight','bold','fontSize',12);
ylabel('shrink factor','FontWeight','bold','fontSize',12);
hold on;
plot(1:nSteps,ones(nSteps,1),'Color','k','LineStyle',':');
end