/** * Returns the mean of an array of numbers. This is equivalent to calling * <code>calculateMean(values, true)</code>. * * @param values the values (<code>null</code> not permitted). * * @return The mean. */ public static double calculateMean(Number[] values) { return calculateMean(values, true); }
/** * Returns the mean of an array of numbers. This is equivalent to calling * {@code calculateMean(values, true)}. * * @param values the values ({@code null} not permitted). * * @return The mean. */ public static double calculateMean(Number[] values) { return calculateMean(values, true); }
/** * Returns the mean of a collection of {@code Number} objects. * * @param values the values ({@code null} not permitted). * * @return The mean. */ public static double calculateMean(Collection values) { return calculateMean(values, true); }
/** * Returns the mean of a collection of <code>Number</code> objects. * * @param values the values (<code>null</code> not permitted). * * @return The mean. */ public static double calculateMean(Collection values) { return calculateMean(values, true); }
/** * Returns the standard deviation of a set of numbers. * * @param data the data (<code>null</code> or zero length array not * permitted). * * @return The standard deviation of a set of numbers. */ public static double getStdDev(Number[] data) { if (data == null) { throw new IllegalArgumentException("Null 'data' array."); } if (data.length == 0) { throw new IllegalArgumentException("Zero length 'data' array."); } double avg = calculateMean(data); double sum = 0.0; for (int counter = 0; counter < data.length; counter++) { double diff = data[counter].doubleValue() - avg; sum = sum + diff * diff; } return Math.sqrt(sum / (data.length - 1)); }
/** * Fits a straight line to a set of (x, y) data, returning the slope and * intercept. * * @param xData the x-data (<code>null</code> not permitted). * @param yData the y-data (<code>null</code> not permitted). * * @return A double array with the intercept in [0] and the slope in [1]. */ public static double[] getLinearFit(Number[] xData, Number[] yData) { if (xData == null) { throw new IllegalArgumentException("Null 'xData' argument."); } if (yData == null) { throw new IllegalArgumentException("Null 'yData' argument."); } if (xData.length != yData.length) { throw new IllegalArgumentException( "Statistics.getLinearFit(): array lengths must be equal."); } double[] result = new double[2]; // slope result[1] = getSlope(xData, yData); // intercept result[0] = calculateMean(yData) - result[1] * calculateMean(xData); return result; }
/** * Returns the standard deviation of a set of numbers. * * @param data the data ({@code null} or zero length array not * permitted). * * @return The standard deviation of a set of numbers. */ public static double getStdDev(Number[] data) { Args.nullNotPermitted(data, "data"); if (data.length == 0) { throw new IllegalArgumentException("Zero length 'data' array."); } double avg = calculateMean(data); double sum = 0.0; for (int counter = 0; counter < data.length; counter++) { double diff = data[counter].doubleValue() - avg; sum = sum + diff * diff; } return Math.sqrt(sum / (data.length - 1)); }
/** * Fits a straight line to a set of (x, y) data, returning the slope and * intercept. * * @param xData the x-data ({@code null} not permitted). * @param yData the y-data ({@code null} not permitted). * * @return A double array with the intercept in [0] and the slope in [1]. */ public static double[] getLinearFit(Number[] xData, Number[] yData) { Args.nullNotPermitted(xData, "xData"); Args.nullNotPermitted(yData, "yData"); if (xData.length != yData.length) { throw new IllegalArgumentException( "Statistics.getLinearFit(): array lengths must be equal."); } double[] result = new double[2]; // slope result[1] = getSlope(xData, yData); // intercept result[0] = calculateMean(yData) - result[1] * calculateMean(xData); return result; }
double mean = Statistics.calculateMean(vlist, false); double median = Statistics.calculateMedian(vlist, false); double q1 = calculateQ1(vlist);
double mean = Statistics.calculateMean(vlist, false); double median = Statistics.calculateMedian(vlist, false); double q1 = calculateQ1(vlist);