function val=Geweke_Conv(X)
n=length(X);
n1 = ceil(0.1*n); n2 = ceil(0.5*n);
X1 = X(1:n1); X2 = X((n2+1):n);
m1 = mean(X1); m2 = mean(X2);
[var1,c1] = CI_est(X1); [var2,c2] = CI_est(X2);
sqvar = sqrt(n)*sqrt((1/0.1)*var1 +(1/0.5)*var2);
stat = (m1-m2)/sqvar;
val = [stat<3.77, stat<4.78];
end


function [var, CI] = CI_est(X)
qtile = 4.78;
n=length(X);
cov=xcov(X,n)/n;
cov=cov((n+1):(2*n+1));

var = cov(1);
for i=2:(n+1)
    var=var+2*(1-((i-1)/n))*cov(i);
end

m = mean(X);
CI_1 = m - qtile * sqrt(var/n);
CI_2 = m + qtile * sqrt(var/n);

CI = [CI_1 m CI_2];

end
