Example usage for org.jfree.data.statistics Statistics calculateMedian

List of usage examples for org.jfree.data.statistics Statistics calculateMedian

Introduction

In this page you can find the example usage for org.jfree.data.statistics Statistics calculateMedian.

Prototype

public static double calculateMedian(List values, int start, int end) 

Source Link

Document

Calculates the median for a sublist within a list of values ( Number objects).

Usage

From source file:org.jfree.data.statistics.BoxAndWhiskerCalculator.java

/**
 * Calculates the first quartile for a list of numbers in ascending order.
 * If the items in the list are not in ascending order, the result is
 * unspecified.  If the list contains items that are <code>null</code>, not
 * an instance of <code>Number</code>, or equivalent to
 * <code>Double.NaN</code>, the result is unspecified.
 *
 * @param values  the numbers in ascending order (<code>null</code> not
 *     permitted)./*from w w w .j  av  a 2  s.co  m*/
 *
 * @return The first quartile.
 */
public static double calculateQ1(List values) {
    ParamChecks.nullNotPermitted(values, "values");

    double result = Double.NaN;
    int count = values.size();
    if (count > 0) {
        if (count % 2 == 1) {
            if (count > 1) {
                result = Statistics.calculateMedian(values, 0, count / 2);
            } else {
                result = Statistics.calculateMedian(values, 0, 0);
            }
        } else {
            result = Statistics.calculateMedian(values, 0, count / 2 - 1);
        }

    }
    return result;
}

From source file:org.jfree.data.statistics.BoxAndWhiskerCalculator.java

/**
 * Calculates the third quartile for a list of numbers in ascending order.
 * If the items in the list are not in ascending order, the result is
 * unspecified.  If the list contains items that are <code>null</code>, not
 * an instance of <code>Number</code>, or equivalent to
 * <code>Double.NaN</code>, the result is unspecified.
 *
 * @param values  the list of values (<code>null</code> not permitted).
 *
 * @return The third quartile./*from   ww w  .  jav  a 2  s  . co m*/
 */
public static double calculateQ3(List values) {
    ParamChecks.nullNotPermitted(values, "values");
    double result = Double.NaN;
    int count = values.size();
    if (count > 0) {
        if (count % 2 == 1) {
            if (count > 1) {
                result = Statistics.calculateMedian(values, count / 2, count - 1);
            } else {
                result = Statistics.calculateMedian(values, 0, 0);
            }
        } else {
            result = Statistics.calculateMedian(values, count / 2, count - 1);
        }
    }
    return result;
}