-
Notifications
You must be signed in to change notification settings - Fork 1
/
gewekeTest.m
41 lines (32 loc) · 1.04 KB
/
gewekeTest.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
% Published & implemented by Marko Laine (2006) - used by Ballnus et al.
% (2017). Performs a Geweke test on a chain using the first a fraction and
% the last b fraction of it for comparison. Returns test value z and p
% value p.
function [z,p]=gewekeTest(chain,a,b)
%GEWEKE Geweke's MCMC convergence diagnostic
% [z,p] = geweke(chain,a,b)
% Test for equality of the means of the first a% (default 10%) and
% last b% (50%) of a Markov chain.
% See:
% Stephen P. Brooks and Gareth O. Roberts.
% Assessing convergence of Markov chain Monte Carlo algorithms.
% Statistics and Computing, 8:319--335, 1998.
% ML, 2002
% $Revision: 1.3 $ $Date: 2003/05/07 12:22:19 $
[nsimu,~]=size(chain);
if nargin<3
a = 0.1;
b = 0.5;
end
na = floor(a*nsimu);
nb = nsimu-floor(b*nsimu)+1;
if (na+nb-1)/nsimu > 1
error('Error with na and nb');
end
m1 = mean(chain(1:na,:));
m2 = mean(chain(nb:end,:));
%%% Spectral estimates for variance
sa = spectrum0(chain(1:na,:));
sb = spectrum0(chain(nb:end,:));
z = (m1-m2)./(sqrt(sa/na+sb/(nsimu-nb+1)));
p = 2*(1-nordf(abs(z)));