
%
%      Test_Statistic
%
%  Compute the test statistics to determine whether scalar-valued samples from two distributions
%  are drawn from the same distribution.  This must be extended for p-valued samples.
% 

  function test_stat = test_statistic(n1,n2,X,Y);

  sum_XY = 0;
  sum_X = 0;
  sum_Y = 0;
  for i=1:n1
    for j=1:n2
      sum_XY = sum_XY + abs(X(i,1) - Y(j,1));
    end
    for j=1:n1
      sum_X = sum_X + abs(X(i,1) - X(j,1));
    end
  end 
  for i=1:n2
    for j=1:n2
      sum_Y = sum_Y + abs(Y(i,1) - Y(j,1));
    end
  end
  term_XY = (2/(n1*n2))*sum_XY;
  term_X = (1/(n1^2))*sum_X;
  term_Y = (1/(n2^2))*sum_Y;

  test_stat = ((n1*n2)/(n1+n2))*(term_XY - term_X - term_Y);

