Example usage for org.apache.commons.math3.stat.inference TTest pairedT

List of usage examples for org.apache.commons.math3.stat.inference TTest pairedT

Introduction

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

Prototype

public double pairedT(final double[] sample1, final double[] sample2)
        throws NullArgumentException, NoDataException, DimensionMismatchException, NumberIsTooSmallException 

Source Link

Document

Computes a paired, 2-sample t-statistic based on the data in the input arrays.

Usage

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

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

    TTest tTest = new TTest();
    Map map = new HashMap();
    Tuple tuple = new Tuple(map);
    if (value1 instanceof List) {
        List<Number> values1 = (List<Number>) value1;
        double[] samples1 = new double[values1.size()];

        for (int i = 0; i < samples1.length; i++) {
            samples1[i] = values1.get(i).doubleValue();
        }//from   w  ww .  j  a  va 2  s . c om

        if (value2 instanceof List) {
            List<Number> values2 = (List<Number>) value2;
            double[] samples2 = new double[values2.size()];

            for (int i = 0; i < samples2.length; i++) {
                samples2[i] = values2.get(i).doubleValue();
            }

            double tstat = tTest.pairedT(samples1, samples2);
            double pval = tTest.pairedTTest(samples1, samples2);
            tuple.put("t-statistic", tstat);
            tuple.put("p-value", pval);
            return tuple;
        } else {
            throw new IOException("Second parameter for pairedTtest must be a double array");
        }
    } else {
        throw new IOException("First parameter for pairedTtest must be a double array");
    }
}