Example usage for org.apache.commons.math3.stat.inference GTest gDataSetsComparison

List of usage examples for org.apache.commons.math3.stat.inference GTest gDataSetsComparison

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.inference GTest gDataSetsComparison.

Prototype

public double gDataSetsComparison(final long[] observed1, final long[] observed2)
        throws DimensionMismatchException, NotPositiveException, ZeroException 

Source Link

Document

Computes a G (Log-Likelihood Ratio) two sample test statistic for independence comparing frequency counts in observed1 and observed2 .

Usage

From source file:org.apache.solr.client.solrj.io.eval.GTestDataSetEvaluator.java

@Override
public Object doWork(Object value1, Object value2) throws IOException {

    List<Number> listA = (List<Number>) value1;
    List<Number> listB = (List<Number>) value2;

    long[] sampleA = new long[listA.size()];
    long[] sampleB = new long[listB.size()];

    for (int i = 0; i < sampleA.length; i++) {
        sampleA[i] = listA.get(i).longValue();
    }/*from   w  w  w.j  a  va 2  s  . com*/

    for (int i = 0; i < sampleB.length; i++) {
        sampleB[i] = listB.get(i).longValue();
    }

    GTest gTest = new GTest();
    double g = gTest.gDataSetsComparison(sampleA, sampleB);
    double p = gTest.gTestDataSetsComparison(sampleA, sampleB);

    Map<String, Number> m = new HashMap<>();
    m.put("G-statistic", g);
    m.put("p-value", p);
    return new Tuple(m);
}