org.apache.commons.math3.stat.correlation.KendallsCorrelation Java Examples

The following examples show how to use org.apache.commons.math3.stat.correlation.KendallsCorrelation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatsUtil.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Calculates Kendall's tau, a correlation measure for ordinal data.
 *
 * @param x X data
 * @param y Y data
 * @return Kendall's tau correlation.
 */
public static double kendalltau(Array x, Array y) {
    double[] xd = (double[]) ArrayUtil.copyToNDJavaArray_Double(x);
    double[] yd = (double[]) ArrayUtil.copyToNDJavaArray_Double(y);
    KendallsCorrelation kc = new KendallsCorrelation();
    double r = kc.correlation(xd, yd);
    return r;
}
 
Example #2
Source File: NumberColumnTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
public void testCorrelation() {
  double[] x = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  double[] y = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

  DoubleColumn xCol = DoubleColumn.create("x", x);
  DoubleColumn yCol = DoubleColumn.create("y", y);

  double resultP = xCol.pearsons(yCol);
  double resultS = xCol.spearmans(yCol);
  double resultK = xCol.kendalls(yCol);
  assertEquals(new PearsonsCorrelation().correlation(x, y), resultP, 0.0001);
  assertEquals(new SpearmansCorrelation().correlation(x, y), resultS, 0.0001);
  assertEquals(new KendallsCorrelation().correlation(x, y), resultK, 0.0001);
}
 
Example #3
Source File: NumberColumnTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
public void testCorrelation2() {
  double[] x = new double[] {1, 2, 3, 4, 5, 6, 7, NaN, 9, 10};
  double[] y = new double[] {1, 2, 3, NaN, 5, 6, 7, 8, 9, 10};

  DoubleColumn xCol = DoubleColumn.create("x", x);
  DoubleColumn yCol = DoubleColumn.create("y", y);

  double resultP = xCol.pearsons(yCol);
  double resultK = xCol.kendalls(yCol);
  assertEquals(new PearsonsCorrelation().correlation(x, y), resultP, 0.0001);
  assertEquals(new KendallsCorrelation().correlation(x, y), resultK, 0.0001);
}
 
Example #4
Source File: NumberColumnTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
public void testCorrelation() {
  double[] x = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  double[] y = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

  DoubleColumn xCol = DoubleColumn.create("x", x);
  DoubleColumn yCol = DoubleColumn.create("y", y);

  double resultP = xCol.pearsons(yCol);
  double resultS = xCol.spearmans(yCol);
  double resultK = xCol.kendalls(yCol);
  assertEquals(new PearsonsCorrelation().correlation(x, y), resultP, 0.0001);
  assertEquals(new SpearmansCorrelation().correlation(x, y), resultS, 0.0001);
  assertEquals(new KendallsCorrelation().correlation(x, y), resultK, 0.0001);
}
 
Example #5
Source File: NumberColumnTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
public void testCorrelation2() {
  double[] x = new double[] {1, 2, 3, 4, 5, 6, 7, NaN, 9, 10};
  double[] y = new double[] {1, 2, 3, NaN, 5, 6, 7, 8, 9, 10};

  DoubleColumn xCol = DoubleColumn.create("x", x);
  DoubleColumn yCol = DoubleColumn.create("y", y);

  double resultP = xCol.pearsons(yCol);
  double resultK = xCol.kendalls(yCol);
  assertEquals(new PearsonsCorrelation().correlation(x, y), resultP, 0.0001);
  assertEquals(new KendallsCorrelation().correlation(x, y), resultK, 0.0001);
}
 
Example #6
Source File: EvaluationUtils.java    From AILibs with GNU Affero General Public License v3.0 4 votes vote down vote up
public static double rankKendallsTau(final double[] ranking1, final double[] ranking2) {
	KendallsCorrelation kendalsCorr = new KendallsCorrelation();
	return kendalsCorr.correlation(ranking1, ranking2);
}
 
Example #7
Source File: NumericColumn.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
/** Returns the Kendall's Tau Rank correlation between the receiver and the otherColumn */
default double kendalls(NumericColumn<?> otherColumn) {
  double[] x = asDoubleArray();
  double[] y = otherColumn.asDoubleArray();
  return new KendallsCorrelation().correlation(x, y);
}
 
Example #8
Source File: NumericColumn.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
/** Returns the Kendall's Tau Rank correlation between the receiver and the otherColumn */
default double kendalls(NumericColumn<?> otherColumn) {
  double[] x = asDoubleArray();
  double[] y = otherColumn.asDoubleArray();
  return new KendallsCorrelation().correlation(x, y);
}