Example usage for org.apache.commons.math.stat.descriptive StatisticalSummaryValues StatisticalSummaryValues

List of usage examples for org.apache.commons.math.stat.descriptive StatisticalSummaryValues StatisticalSummaryValues

Introduction

In this page you can find the example usage for org.apache.commons.math.stat.descriptive StatisticalSummaryValues StatisticalSummaryValues.

Prototype

public StatisticalSummaryValues(double mean, double variance, long n, double max, double min, double sum) 

Source Link

Document

Constructor

Usage

From source file:geogebra.kernel.statistics.AlgoTTest.java

protected final void compute() {

    if (!(tail.getTextString().equals("<") || tail.getTextString().equals(">")
            || tail.getTextString().equals("!=") || tail.getTextString().equals(""))) {
        result.setUndefined();//from  ww w .j  av a2  s.c om
        return;
    }

    // sample data input
    if (input.length == 3) {

        int size = geoList.size();
        if (!geoList.isDefined() || size < 2) {
            result.setUndefined();
            return;
        }

        val = new double[size];

        for (int i = 0; i < size; i++) {
            GeoElement geo = geoList.get(i);
            if (geo.isNumberValue()) {
                NumberValue num = (NumberValue) geo;
                val[i] = num.getDouble();

            } else {
                result.setUndefined();
                return;
            }
        }

        try {

            // get the test statistic and p
            if (tTestImpl == null)
                tTestImpl = new TTestImpl();
            testStat = tTestImpl.t(hypMean.getDouble(), val);
            p = tTestImpl.tTest(hypMean.getDouble(), val);
            p = adjustedPValue(p, testStat);

            // put these results into the output list
            result.clear();
            result.add(new GeoNumeric(cons, p));
            result.add(new GeoNumeric(cons, testStat));

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (MathException e) {
            e.printStackTrace();
        }

        // sample statistics input 
    } else {

        // check for valid standard deviation and sample size
        if (sd.getDouble() < 0 || n.getDouble() < 2) {
            result.setUndefined();
            return;
        }
        StatisticalSummaryValues sumStats = new StatisticalSummaryValues(mean.getDouble(),
                sd.getDouble() * sd.getDouble(), (long) n.getDouble(), -1, -1, -1);

        try {

            // get the test statistic and p
            if (tTestImpl == null)
                tTestImpl = new TTestImpl();
            testStat = tTestImpl.t(hypMean.getDouble(), sumStats);
            p = tTestImpl.tTest(hypMean.getDouble(), sumStats);
            p = adjustedPValue(p, testStat);

            // put these results into the output list
            result.clear();
            result.add(new GeoNumeric(cons, p));
            result.add(new GeoNumeric(cons, testStat));

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (MathException e) {
            e.printStackTrace();
        }

    }

}

From source file:geogebra.common.kernel.statistics.AlgoTTest.java

@Override
public final void compute() {

    if (!(StringUtil.isInequality(tail.getTextString()))) {
        result.setUndefined();/*w  w  w  .  jav a2  s .co m*/
        return;
    }

    // sample data input
    if (input.length == 3) {

        int size = geoList.size();
        if (!geoList.isDefined() || size < 2) {
            result.setUndefined();
            return;
        }

        val = new double[size];

        for (int i = 0; i < size; i++) {
            GeoElement geo = geoList.get(i);
            if (geo instanceof NumberValue) {
                NumberValue num = (NumberValue) geo;
                val[i] = num.getDouble();

            } else {
                result.setUndefined();
                return;
            }
        }

        try {

            // get the test statistic and p
            if (tTestImpl == null)
                tTestImpl = new TTestImpl();
            testStat = tTestImpl.t(hypMean.getDouble(), val);
            p = tTestImpl.tTest(hypMean.getDouble(), val);
            p = adjustedPValue(p, testStat);

            // put these results into the output list
            result.clear();
            result.add(new GeoNumeric(cons, p));
            result.add(new GeoNumeric(cons, testStat));

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (MathException e) {
            e.printStackTrace();
        }

        // sample statistics input
    } else {

        // check for valid standard deviation and sample size
        if (sd.getDouble() < 0 || n.getDouble() < 2) {
            result.setUndefined();
            return;
        }

        try {
            StatisticalSummaryValues sumStats = new StatisticalSummaryValues(mean.getDouble(),
                    sd.getDouble() * sd.getDouble(), (long) n.getDouble(), -1, -1, -1);

            // get the test statistic and p
            if (tTestImpl == null)
                tTestImpl = new TTestImpl();
            testStat = tTestImpl.t(hypMean.getDouble(), sumStats);
            p = tTestImpl.tTest(hypMean.getDouble(), sumStats);
            p = adjustedPValue(p, testStat);

            // put these results into the output list
            result.clear();
            result.add(new GeoNumeric(cons, p));
            result.add(new GeoNumeric(cons, testStat));

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            result.setUndefined();
            return;

        } catch (MathException e) {
            e.printStackTrace();
            result.setUndefined();
            return;
        }

    }

}

From source file:geogebra.kernel.statistics.AlgoTTest2.java

protected final void compute() {

    if (!(tail.getTextString().equals("<") || tail.getTextString().equals(">")
            || tail.getTextString().equals("!=") || tail.getTextString().equals(""))) {
        result.setUndefined();//from  w  w w .  java2  s . c o  m
        return;
    }

    double p, testStat;

    // sample data input
    if (input.length == 4) {

        int size0 = geoList0.size();
        if (!geoList0.isDefined() || size0 < 2) {
            result.setUndefined();
            return;
        }

        int size1 = geoList1.size();
        if (!geoList1.isDefined() || size1 < 2) {
            result.setUndefined();
            return;
        }

        val0 = new double[size0];
        val1 = new double[size1];
        // load array from first sample
        for (int i = 0; i < size0; i++) {
            GeoElement geo0 = geoList0.get(i);
            if (geo0.isNumberValue()) {
                NumberValue num = (NumberValue) geo0;
                val0[i] = num.getDouble();

            } else {
                result.setUndefined();
                return;
            }
        }
        // load array from second sample
        for (int i = 0; i < size1; i++) {
            GeoElement geo1 = geoList1.get(i);
            if (geo1.isNumberValue()) {
                NumberValue num = (NumberValue) geo1;
                val1[i] = num.getDouble();

            } else {
                result.setUndefined();
                return;
            }
        }

        try {

            // get the test statistic and p
            if (tTestImpl == null)
                tTestImpl = new TTestImpl();

            if (pooled.getBoolean()) {
                testStat = tTestImpl.homoscedasticT(val0, val1);
                p = tTestImpl.homoscedasticTTest(val0, val1);
                p = adjustedPValue(p, testStat);
            } else {
                testStat = tTestImpl.t(val0, val1);
                p = tTestImpl.tTest(val0, val1);
                p = adjustedPValue(p, testStat);
            }

            // put these results into the output list
            result.clear();
            result.add(new GeoNumeric(cons, p));
            result.add(new GeoNumeric(cons, testStat));

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (MathException e) {
            e.printStackTrace();
        }

        // sample statistics input 
    } else {

        // check for valid stand. deviation and sample size
        if (sd0.getDouble() < 0 || sd1.getDouble() < 0 || n0.getDouble() < 2 || n1.getDouble() < 2) {
            result.setUndefined();
            return;
        }

        StatisticalSummaryValues sumStats0 = new StatisticalSummaryValues(mean0.getDouble(),
                sd0.getDouble() * sd0.getDouble(), (long) n0.getDouble(), -1, -1, -1);
        StatisticalSummaryValues sumStats1 = new StatisticalSummaryValues(mean1.getDouble(),
                sd1.getDouble() * sd1.getDouble(), (long) n1.getDouble(), -1, -1, -1);

        try {

            // get the test statistic and p
            if (tTestImpl == null)
                tTestImpl = new TTestImpl();

            if (pooled.getBoolean()) {
                testStat = tTestImpl.homoscedasticT(sumStats0, sumStats1);
                p = tTestImpl.homoscedasticTTest(sumStats0, sumStats1);
                p = adjustedPValue(p, testStat);
            } else {
                testStat = tTestImpl.t(sumStats0, sumStats1);
                p = tTestImpl.tTest(sumStats0, sumStats1);
                p = adjustedPValue(p, testStat);
            }

            // put these results into the output list
            result.clear();
            result.add(new GeoNumeric(cons, p));
            result.add(new GeoNumeric(cons, testStat));

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (MathException e) {
            e.printStackTrace();
        }

    }

}

From source file:geogebra.common.kernel.statistics.AlgoTTest2.java

@Override
public final void compute() {

    if (!(StringUtil.isInequality(tail.getTextString()))) {
        result.setUndefined();/*from w w w  .  j a  va2 s  .  c  o  m*/
        return;
    }

    double p, testStat;

    // sample data input
    if (input.length == 4) {

        int size0 = geoList0.size();
        if (!geoList0.isDefined() || size0 < 2) {
            result.setUndefined();
            return;
        }

        int size1 = geoList1.size();
        if (!geoList1.isDefined() || size1 < 2) {
            result.setUndefined();
            return;
        }

        val0 = new double[size0];
        val1 = new double[size1];
        // load array from first sample
        for (int i = 0; i < size0; i++) {
            GeoElement geo0 = geoList0.get(i);
            if (geo0 instanceof NumberValue) {
                NumberValue num = (NumberValue) geo0;
                val0[i] = num.getDouble();

            } else {
                result.setUndefined();
                return;
            }
        }
        // load array from second sample
        for (int i = 0; i < size1; i++) {
            GeoElement geo1 = geoList1.get(i);
            if (geo1 instanceof NumberValue) {
                NumberValue num = (NumberValue) geo1;
                val1[i] = num.getDouble();

            } else {
                result.setUndefined();
                return;
            }
        }

        try {

            // get the test statistic and p
            if (tTestImpl == null)
                tTestImpl = new TTestImpl();

            if (pooled.getBoolean()) {
                testStat = tTestImpl.homoscedasticT(val0, val1);
                p = tTestImpl.homoscedasticTTest(val0, val1);
                p = adjustedPValue(p, testStat);
            } else {
                testStat = tTestImpl.t(val0, val1);
                p = tTestImpl.tTest(val0, val1);
                p = adjustedPValue(p, testStat);
            }

            // put these results into the output list
            result.clear();
            result.add(new GeoNumeric(cons, p));
            result.add(new GeoNumeric(cons, testStat));

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (MathException e) {
            e.printStackTrace();
        }

        // sample statistics input
    } else {

        // check for valid stand. deviation and sample size
        if (sd0.getDouble() < 0 || sd1.getDouble() < 0 || n0.getDouble() < 2 || n1.getDouble() < 2) {
            result.setUndefined();
            return;
        }

        StatisticalSummaryValues sumStats0 = new StatisticalSummaryValues(mean0.getDouble(),
                sd0.getDouble() * sd0.getDouble(), (long) n0.getDouble(), -1, -1, -1);
        StatisticalSummaryValues sumStats1 = new StatisticalSummaryValues(mean1.getDouble(),
                sd1.getDouble() * sd1.getDouble(), (long) n1.getDouble(), -1, -1, -1);

        try {

            // get the test statistic and p
            if (tTestImpl == null)
                tTestImpl = new TTestImpl();

            if (pooled.getBoolean()) {
                testStat = tTestImpl.homoscedasticT(sumStats0, sumStats1);
                p = tTestImpl.homoscedasticTTest(sumStats0, sumStats1);
                p = adjustedPValue(p, testStat);
            } else {
                testStat = tTestImpl.t(sumStats0, sumStats1);
                p = tTestImpl.tTest(sumStats0, sumStats1);
                p = adjustedPValue(p, testStat);
            }

            // put these results into the output list
            result.clear();
            result.add(new GeoNumeric(cons, p));
            result.add(new GeoNumeric(cons, testStat));

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (MathException e) {
            e.printStackTrace();
        }

    }

}

From source file:org.openehealth.ipf.commons.test.performance.processingtime.ProcessingTimeDescriptiveStatistics.java

/**
 * Returns statistical summary of all the data.
 * /*from  w  w w  .  j  a  v  a2s. c  o m*/
 * @return a <code>StatisticalSummary</code> object
 */
@Override
public StatisticalSummary getStatisticalSummaryByName(String name) {
    DescriptiveStatistics stats = statisticsByMeasurementName.get(name);

    return new StatisticalSummaryValues(stats.getMean(), stats.getVariance(), stats.getN(), stats.getMax(),
            stats.getMin(), stats.getSum());
}