Example usage for org.apache.commons.math.stat.descriptive DescriptiveStatistics getElement

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

Introduction

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

Prototype

public double getElement(int index) 

Source Link

Document

Returns the element at the specified index

Usage

From source file:cs.cirg.cida.analysis.MannWhitneyUTest.java

@Override
public DataTable performTest(String... variableNames) {
    if (this.getExperiments().size() < 2) {
        return null;
    }//from  w  w w .  j  av  a 2 s.  c o m
    IExperiment experiment1 = this.getExperiments().get(0);
    IExperiment experiment2 = this.getExperiments().get(1);

    DescriptiveStatistics stats1 = experiment1.getBottomRowStatistics(variableNames[0]);
    DescriptiveStatistics stats2 = experiment2.getBottomRowStatistics(variableNames[0]);

    double[] xA = new double[(int) stats1.getN()];
    double[] xB = new double[(int) stats2.getN()];
    for (int i = 0; i < xA.length; i++) {
        xA[i] = stats1.getElement(i);
        xB[i] = stats2.getElement(i);
    }

    MannWhitneyTest mannWhitneyTest = new MannWhitneyTest(xA, xB, alternativeHypothesis, 0.0, false);

    results = new StandardDataTable<StringType>();

    ArrayList<StringType> row = new ArrayList<StringType>();
    row.add(new StringType("N_A"));
    row.add(new StringType(stats1.getN() + ""));
    results.addRow(row);

    row = new ArrayList<StringType>();
    row.add(new StringType("N_B"));
    row.add(new StringType(stats2.getN() + ""));
    results.addRow(row);

    row = new ArrayList<StringType>();
    row.add(new StringType("P value"));
    row.add(new StringType(mannWhitneyTest.exactSP() + ""));
    results.addRow(row);

    row = new ArrayList<StringType>();
    row.add(new StringType("Approx P value"));
    row.add(new StringType(mannWhitneyTest.approxSP() + ""));
    results.addRow(row);

    row = new ArrayList<StringType>();
    row.add(new StringType("Ranks Sum A"));
    row.add(new StringType(mannWhitneyTest.getRankSumA() + ""));
    results.addRow(row);

    row = new ArrayList<StringType>();
    row.add(new StringType("Ranks Sum B"));
    row.add(new StringType(mannWhitneyTest.getRankSumB() + ""));
    results.addRow(row);

    row = new ArrayList<StringType>();
    row.add(new StringType("U"));
    row.add(new StringType(mannWhitneyTest.getStatistic() + ""));
    results.addRow(row);

    row = new ArrayList<StringType>();
    row.add(new StringType("Z"));
    row.add(new StringType(mannWhitneyTest.getZ() + ""));
    results.addRow(row);

    results.setColumnName(0, "Statistic");
    results.setColumnName(1, "Value");

    return this.getResults();
}

From source file:playground.johannes.gsv.synPop.analysis.ActivityDistanceTruncatedTask.java

@Override
protected DescriptiveStatistics statistics(Collection<ProxyPerson> persons, String purpose, String mode) {
    DescriptiveStatistics stats = super.statistics(persons, purpose, mode);

    if (threshold > 0) {
        DescriptiveStatistics newStats = new DescriptiveStatistics();
        for (int i = 0; i < stats.getN(); i++) {
            double val = stats.getElement(i);
            if (val >= threshold) {
                newStats.addValue(val);
            }/*w w w  . j  a  va2 s  .  c o  m*/
        }

        return newStats;
    } else {
        return stats;
    }
}