public static double rho(ExampleSet eSet,Attribute a,Attribute b,double f) throws OperatorException {
  ExampleSet e=extract(eSet,a,b);
  double[] ranka=rank(e,a,null,f);
  double[] rankb=rank(e,b,a,f);
  int nObs=ranka.length;
  double mu2=nObs * (nObs + 1.0d) * (nObs + 1.0d) / 4.0d;
  double prod=0;
  double a2=0;
  double b2=0;
  for (int i=0; i < nObs; i++) {
    prod+=ranka[i] * rankb[i];
    a2+=ranka[i] * ranka[i];
    b2+=rankb[i] * rankb[i];
  }
  double value=Math.sqrt((a2 - mu2) * (b2 - mu2));
  if (value != 0) {
    return (prod - mu2) / value;
  }
 else {
    return 0;
  }
}

public static double rho ( ExampleSet eSet , Attribute a , Attribute b , double f ) throws OperatorException { ExampleSet e = extract ( eSet , a , b ) ; double [ ] ranka = rank ( e , a , null , f ) ; double [ ] rankb = rank ( e , b , a , f ) ; int nObs = ranka . length ; double mu2 = nObs * ( nObs + 1.0d ) * ( nObs + 1.0d ) / 4.0d ; double prod = 0 ; double a2 = 0 ; double b2 = 0 ; for ( int i = 0 ; i < nObs ; i ++ ) { prod += ranka [ i ] * rankb [ i ] ; a2 += ranka [ i ] * ranka [ i ] ; b2 += rankb [ i ] * rankb [ i ] ; } double value = Math . sqrt ( ( a2 - mu2 ) * ( b2 - mu2 ) ) ; if ( value != 0 ) { return ( prod - mu2 ) / value ; } else { return 0 ; } }
calculates the spearman rank correlation between two attributes .
