Java Code Examples for org.apache.commons.math3.stat.StatUtils#percentile()
The following examples show how to use
org.apache.commons.math3.stat.StatUtils#percentile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatsUtil.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns an estimate of the pth percentile of the values in the array along an axis. * @param a Input array * @param p The percentile value to compute * @param axis The axis * @return The pth percentile * @throws InvalidRangeException */ public static Array percentile(Array a, double p, int axis) throws InvalidRangeException{ int[] dataShape = a.getShape(); int[] shape = new int[dataShape.length - 1]; int idx; for (int i = 0; i < dataShape.length; i++) { idx = i; if (idx == axis) { continue; } else if (idx > axis) { idx -= 1; } shape[idx] = dataShape[i]; } Array r = Array.factory(DataType.DOUBLE, shape); Index indexr = r.getIndex(); int[] current; for (int i = 0; i < r.getSize(); i++) { current = indexr.getCurrentCounter(); List<Range> ranges = new ArrayList<>(); for (int j = 0; j < dataShape.length; j++) { if (j == axis) { ranges.add(new Range(0, dataShape[j] - 1, 1)); } else { idx = j; if (idx > axis) { idx -= 1; } ranges.add(new Range(current[idx], current[idx], 1)); } } Array aa = ArrayMath.section(a, ranges); double[] v = (double[])aa.get1DJavaArray(Double.class); double q = StatUtils.percentile(v, p); r.setDouble(i, q); indexr.incr(); } return r; }
Example 2
Source File: QQPlot.java From tablesaw with Apache License 2.0 | 5 votes |
/** * Returns a double array, whose values are quantiles from the given source, based on the given * size. The idea is to produce size elements that represent the quantiles of source array * * @param source The array to whose quantiles are calculated * @param size The size of the array to return */ private static double[] interpolate(double[] source, int size) { double[] interpolatedData = new double[size]; for (int i = 0; i < size; i++) { double value = ((i + .5) / (double) size) * 100; interpolatedData[i] = StatUtils.percentile(source, value); } return interpolatedData; }
Example 3
Source File: TukeyMeanDifferencePlot.java From tablesaw with Apache License 2.0 | 5 votes |
/** * Returns a double array, whose values are quantiles from the given source, based on the given * size. The idea is to produce size elements that represent the quantiles of source array * * @param source The array to whose quantiles are calculated * @param size The size of the array to return */ private static double[] interpolate(double[] source, int size) { double[] interpolatedData = new double[size]; for (int i = 0; i < size; i++) { double value = ((i + .5) / (double) size) * 100; interpolatedData[i] = StatUtils.percentile(source, value); } return interpolatedData; }
Example 4
Source File: QQPlot.java From tablesaw with Apache License 2.0 | 5 votes |
/** * Returns a double array, whose values are quantiles from the given source, based on the given * size. The idea is to produce size elements that represent the quantiles of source array * * @param source The array to whose quantiles are calculated * @param size The size of the array to return */ private static double[] interpolate(double[] source, int size) { double[] interpolatedData = new double[size]; for (int i = 0; i < size; i++) { double value = ((i + .5) / (double) size) * 100; interpolatedData[i] = StatUtils.percentile(source, value); } return interpolatedData; }
Example 5
Source File: TukeyMeanDifferencePlot.java From tablesaw with Apache License 2.0 | 5 votes |
/** * Returns a double array, whose values are quantiles from the given source, based on the given * size. The idea is to produce size elements that represent the quantiles of source array * * @param source The array to whose quantiles are calculated * @param size The size of the array to return */ private static double[] interpolate(double[] source, int size) { double[] interpolatedData = new double[size]; for (int i = 0; i < size; i++) { double value = ((i + .5) / (double) size) * 100; interpolatedData[i] = StatUtils.percentile(source, value); } return interpolatedData; }
Example 6
Source File: StatsUtil.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
/** * Returns an estimate of the pth percentile of the values in the array. * @param a Input array * @param p The percentile value to compute * @return The pth percentile */ public static double percentile(Array a, double p){ double[] v = (double[])a.get1DJavaArray(Double.class); double r = StatUtils.percentile(v, p); return r; }
Example 7
Source File: KnoxShellTable.java From knox with Apache License 2.0 | 2 votes |
/** * Calculates the median of specified column * @param colName the column for which the median will be calculated * @return median */ public double median(String colName) { return StatUtils.percentile(toDoubleArray(colName), 50); }