public double unstandardized(double[] sample1,double[] sample2){
  final int n1=sample1.length, n2=sample2.length, N=n1 + n2;
  final double[] combined=new double[N];
  Arrays.sort(sample1);
  System.arraycopy(sample1,0,combined,0,n1);
  Arrays.sort(sample2);
  System.arraycopy(sample2,0,combined,n1,n2);
  Arrays.sort(combined);
  int m1=0, m2=0;
  double Ak1=0., Ak2=0.;
  for (int j=0; j < N; ) {
    final double x=combined[j++];
    int lj=1;
    while (j < N && combined[j] == x) {
      ++j;
      ++lj;
    }
    final double bi=j - .5 * lj;
{
      assert (m1 >= n1 || sample1[m1] >= x);
      int f1=0;
      while (m1 < n1 && sample1[m1] == x) {
        ++m1;
        ++f1;
      }
      double v=N * (m1 - .5 * f1) - n1 * bi;
      Ak1+=lj * v * v / (bi * (N - bi) - .25 * N * lj);
    }
{
      assert (m2 >= n2 || sample2[m2] >= x);
      int f2=0;
      while (m2 < n2 && sample2[m2] == x) {
        ++m2;
        ++f2;
      }
      double v=N * (m2 - .5 * f2) - n2 * bi;
      Ak2+=lj * v * v / (bi * (N - bi) - .25 * N * lj);
    }
  }
  double A2=Ak1 / n1 + Ak2 / n2;
  A2*=(N - 1.) / (N * N);
  return A2;
}

public double unstandardized ( double [ ] sample1 , double [ ] sample2 ) { final int n1 = sample1 . length , n2 = sample2 . length , N = n1 + n2 ; final double [ ] combined = new double [ N ] ; Arrays . sort ( sample1 ) ; System . arraycopy ( sample1 , 0 , combined , 0 , n1 ) ; Arrays . sort ( sample2 ) ; System . arraycopy ( sample2 , 0 , combined , n1 , n2 ) ; Arrays . sort ( combined ) ; int m1 = 0 , m2 = 0 ; double Ak1 = 0. , Ak2 = 0. ; for ( int j = 0 ; j < N ; ) { final double x = combined [ j ++ ] ; int lj = 1 ; while ( j < N && combined [ j ] == x ) { ++ j ; ++ lj ; } final double bi = j - .5 * lj ; { assert ( m1 >= n1 || sample1 [ m1 ] >= x ) ; int f1 = 0 ; while ( m1 < n1 && sample1 [ m1 ] == x ) { ++ m1 ; ++ f1 ; } double v = N * ( m1 - .5 * f1 ) - n1 * bi ; Ak1 += lj * v * v / ( bi * ( N - bi ) - .25 * N * lj ) ; } { assert ( m2 >= n2 || sample2 [ m2 ] >= x ) ; int f2 = 0 ; while ( m2 < n2 && sample2 [ m2 ] == x ) { ++ m2 ; ++ f2 ; } double v = N * ( m2 - .5 * f2 ) - n2 * bi ; Ak2 += lj * v * v / ( bi * ( N - bi ) - .25 * N * lj ) ; } } double A2 = Ak1 / n1 + Ak2 / n2 ; A2 *= ( N - 1. ) / ( N * N ) ; return A2 ; }
compute the non - standardized a2 test statistic for the k - samples test . this is based on scholz and stephens , equation 7 .
