private double computeCorrelationCoefficient(int[] x,double[] y,int n){
  double sumX=0;
  double sumY=0;
  double sumXY=0;
  double sumX2=0;
  double sumY2=0;
  for (int i=0; i < n; i++) {
    sumX+=x[i];
    sumY+=y[i];
    sumXY+=x[i] * y[i];
    sumX2+=x[i] * x[i];
    sumY2+=y[i] * y[i];
  }
  final double bottom=Math.sqrt((n * sumX2 - sumX * sumX) * (n * sumY2 - sumY * sumY));
  if (bottom == 0)   return 0;
  final double top=n * sumXY - sumX * sumY;
  return top / bottom;
}

private double computeCorrelationCoefficient ( int [ ] x , double [ ] y , int n ) { double sumX = 0 ; double sumY = 0 ; double sumXY = 0 ; double sumX2 = 0 ; double sumY2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sumX += x [ i ] ; sumY += y [ i ] ; sumXY += x [ i ] * y [ i ] ; sumX2 += x [ i ] * x [ i ] ; sumY2 += y [ i ] * y [ i ] ; } final double bottom = Math . sqrt ( ( n * sumX2 - sumX * sumX ) * ( n * sumY2 - sumY * sumY ) ) ; if ( bottom == 0 ) return 0 ; final double top = n * sumXY - sumX * sumY ; return top / bottom ; }
computes the correlation coefficient
