Example usage for org.apache.commons.math3.stat.descriptive SummaryStatistics getMean

List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics getMean

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive SummaryStatistics getMean.

Prototype

public double getMean() 

Source Link

Document

Returns the mean of the values that have been added.

Usage

From source file:wsattacker.plugin.intelligentdos.StatisticTest.java

private static void statistics(double[] x, double[] y) {

    DecimalFormat df = new DecimalFormat("#.######");

    SummaryStatistics statisticsX = new SummaryStatistics();
    for (double value : x) {
        statisticsX.addValue(value);/*from   w  ww . j  ava2  s .c  om*/
    }

    SummaryStatistics statisticsY = new SummaryStatistics();
    for (double value : y) {
        statisticsY.addValue(value);
    }

    // t = -0.5331
    double t = TestUtils.t(statisticsX, statisticsY);
    // df = 18
    long degreesOfFreedom = statisticsX.getN() + statisticsY.getN() - 2;
    // p-value = 0.3002
    TDistribution tDistribution = new TDistribution(degreesOfFreedom);
    double pValue = tDistribution.cumulativeProbability(t);

    // t = -0.5331, df = 18, p-value = 0.3002
    System.out.print("t = " + df.format(t));
    System.out.print(", df = " + degreesOfFreedom);
    System.out.println(", p-value = " + df.format(pValue));

    System.out.println("mean of x mean of y");
    System.out.println(df.format(statisticsX.getMean()) + " - " + df.format(statisticsY.getMean()));

    // Calculate 95% confidence interval
    double ci = calcMeanCI(statisticsY, 0.95);
    System.out.println(String.format("Confidence inteval 95%%: %f", ci));
}