%Speckmann Example
marr = [17 1 7; 1 66 6; 9 6 151];


   nb12 =(marr(1,2) + marr(2,1))/2;
   nb13 =(marr(1,3) + marr(3,1))/2;
   nb23 =(marr(2,3) + marr(3,2))/2;
   
   n1d = marr(1,1) + marr(1,2) + marr(1,3);
   n2d = marr(2,1) + marr(2,2) + marr(2,3);
   n3d = marr(3,1) + marr(3,2) + marr(3,3);
   
   nd1 = marr(1,1) + marr(2,1) + marr(3,1);
   nd2 = marr(1,2) + marr(2,2) + marr(3,2);
   nd3 = marr(1,3) + marr(2,3) + marr(3,3);
   
   chi2num = nb23 * (nd1 - n1d)^2 + nb13 * (nd2 - n2d)^2 + nb12 * (nd3 - n3d)^2
   chi2denom = 2 * (nb12 * nb13 + nb12 * nb23 + nb13*nb23 )
   
   chi2 = chi2num/chi2denom
   
   pval = 1-chi2cdf(chi2,2)
   
   