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

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

Introduction

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

Prototype

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

Source Link

Document

<p>Returns the <i>observed significance level</i>, or <a href= "http://www.cas.lancs.ac.uk/glossary_v1.1/hyptest.html#pvalue"> p-value</a>, associated with a G-Value (Log-Likelihood Ratio) for two sample test comparing bin frequency counts in observed1 and observed2 .</p> <p>The number returned is the smallest significance level at which one can reject the null hypothesis that the observed counts conform to the same distribution.

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  .ja va  2  s. co m*/

    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);
}