private double unstandardized(double[][] samples,int N){
  final int k=samples.length;
  final double[] combined=new double[N];
{
    int p=0;
    for (    double[] samp : samples) {
      Arrays.sort(samp);
      System.arraycopy(samp,0,combined,p,samp.length);
      p+=samp.length;
    }
    assert (p == N);
  }
  Arrays.sort(combined);
  int[] m=new int[k];
  double[] Ak=new double[k];
  for (int j=0; j < N; ) {
    final double x=combined[j++];
    int lj=1;
    while (j < N && combined[j] == x) {
      ++j;
      ++lj;
    }
    for (int i=0; i < k; i++) {
      final double[] sam=samples[i];
      int mi=m[i];
      assert (mi >= sam.length || sam[mi] >= x);
      int fi=0;
      while (mi < sam.length && sam[mi] == x) {
        ++mi;
        ++fi;
      }
      if (fi > 0) {
        assert (m[i] + fi == mi);
        m[i]=mi;
      }
      double bi=j - .5 * lj;
      double v=N * (mi - .5 * fi) - sam.length * bi;
      Ak[i]+=lj * v * v / (bi * (N - bi) - .25 * N * lj);
    }
  }
  double A2=0.;
  for (int j=0; j < k; j++) {
    A2+=Ak[j] / samples[j].length;
  }
  A2*=(N - 1.) / (N * N);
  return A2;
}

private double unstandardized ( double [ ] [ ] samples , int N ) { final int k = samples . length ; final double [ ] combined = new double [ N ] ; { int p = 0 ; for ( double [ ] samp : samples ) { Arrays . sort ( samp ) ; System . arraycopy ( samp , 0 , combined , p , samp . length ) ; p += samp . length ; } assert ( p == N ) ; } Arrays . sort ( combined ) ; int [ ] m = new int [ k ] ; double [ ] Ak = new double [ k ] ; for ( int j = 0 ; j < N ; ) { final double x = combined [ j ++ ] ; int lj = 1 ; while ( j < N && combined [ j ] == x ) { ++ j ; ++ lj ; } for ( int i = 0 ; i < k ; i ++ ) { final double [ ] sam = samples [ i ] ; int mi = m [ i ] ; assert ( mi >= sam . length || sam [ mi ] >= x ) ; int fi = 0 ; while ( mi < sam . length && sam [ mi ] == x ) { ++ mi ; ++ fi ; } if ( fi > 0 ) { assert ( m [ i ] + fi == mi ) ; m [ i ] = mi ; } double bi = j - .5 * lj ; double v = N * ( mi - .5 * fi ) - sam . length * bi ; Ak [ i ] += lj * v * v / ( bi * ( N - bi ) - .25 * N * lj ) ; } } double A2 = 0. ; for ( int j = 0 ; j < k ; j ++ ) { A2 += Ak [ j ] / samples [ j ] . length ; } 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 .
