%Example
s = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(s);

  a1 = binornd(1,0.5, [1024 512]);
  a2 = binornd(1,0.51, [1024 512]);
a =[a1 a2];
[h Q p]=cochrant(a)
% h = 1
% Q = 1.1984e+003
% p = 1.1233e-004
close all force
colormap gray
imagesc(a)
hold on
plot([512 512],[1 1024],'w-')
print -depsc 'C:\Brani\Courses\bmestatu\Spring2012\Activities\cochranmap.eps'

%
%Cochran's Test is Equivalent to McNemar's Test  if c=2.
b = binornd(1, 0.5, [200 2]);
[h Q p]=cochrant(b)
n11 = 0; n12=0; n21=0; n22=0;
for i = 1:r
    if ( b(i,1)+b(i,2) == 2) n11=n11+1;
    elseif  ( b(i,1)+b(i,2) == 0) n22=n22+1;
    elseif ( b(i,1) > b(i,2) )  n12=n12+1;
    else  n21=n21+1;
    end
end
[h chi2 pval] = mcnemart([n11 n12; n21 n22])

