Retrive the quartile value from an array
import java.util.Arrays;
/**
* <p>Static methods for doing useful math</p><hr>
*
* @author : $Author: brian $
* @version : $Revision: 1.1 $
*
* <hr><p><font size="-1" color="#336699"><a href="http://www.mbari.org">
* The Monterey Bay Aquarium Research Institute (MBARI)</a> provides this
* documentation and code "as is", with no warranty, express or
* implied, of its quality or consistency. It is provided without support and
* without obligation on the part of MBARI to assist in its use, correction,
* modification, or enhancement. This information should not be published or
* distributed to third parties without specific written permission from
* MBARI.</font></p><br>
*
* <font size="-1" color="#336699">Copyright 2002 MBARI.<br>
* MBARI Proprietary Information. All rights reserved.</font><br><hr><br>
*
*/
public class Util{
/**
* Retrive the quartile value from an array
* .
* @param values THe array of data
* @param lowerPercent The percent cut off. For the lower quartile use 25,
* for the upper-quartile use 75
* @return
*/
public static double quartile(double[] values, double lowerPercent) {
if (values == null || values.length == 0) {
throw new IllegalArgumentException("The data array either is null or does not contain any data.");
}
// Rank order the values
double[] v = new double[values.length];
System.arraycopy(values, 0, v, 0, values.length);
Arrays.sort(v);
int n = (int) Math.round(v.length * lowerPercent / 100);
return v[n];
}
}
Related examples in the same category