Package org.jfree.data.statistics
Class Statistics
java.lang.Object
org.jfree.data.statistics.Statistics
A utility class that provides some common statistical functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecalculateMean(Number[] values) Returns the mean of an array of numbers.static doublecalculateMean(Number[] values, boolean includeNullAndNaN) Returns the mean of an array of numbers.static doublecalculateMean(Collection values) Returns the mean of a collection ofNumberobjects.static doublecalculateMean(Collection values, boolean includeNullAndNaN) Returns the mean of a collection ofNumberobjects.static doublecalculateMedian(List values) Calculates the median for a list of values (Numberobjects).static doublecalculateMedian(List values, boolean copyAndSort) Calculates the median for a list of values (Numberobjects).static doublecalculateMedian(List values, int start, int end) Calculates the median for a sublist within a list of values (Numberobjects).static doublecalculateMedian(List values, int start, int end, boolean copyAndSort) Calculates the median for a sublist within a list of values (Numberobjects).static doublegetCorrelation(Number[] data1, Number[] data2) Calculates the correlation between two datasets.static double[]getLinearFit(Number[] xData, Number[] yData) Fits a straight line to a set of (x, y) data, returning the slope and intercept.static double[][]getMovingAverage(Number[] xData, Number[] yData, int period) Returns a data set for a moving average on the data set passed in.static doubleFinds the slope of a regression line using least squares.static doubleReturns the standard deviation of a set of numbers.
-
Constructor Details
-
Statistics
public Statistics()
-
-
Method Details
-
calculateMean
Returns the mean of an array of numbers. This is equivalent to callingcalculateMean(values, true).- Parameters:
values- the values (nullnot permitted).- Returns:
- The mean.
-
calculateMean
Returns the mean of an array of numbers.- Parameters:
values- the values (nullnot permitted).includeNullAndNaN- a flag that controls whether or notnullandDouble.NaNvalues are included in the calculation (if either is present in the array, the result isDouble.NaN).- Returns:
- The mean.
-
calculateMean
Returns the mean of a collection ofNumberobjects.- Parameters:
values- the values (nullnot permitted).- Returns:
- The mean.
-
calculateMean
Returns the mean of a collection ofNumberobjects.- Parameters:
values- the values (nullnot permitted).includeNullAndNaN- a flag that controls whether or notnullandDouble.NaNvalues are included in the calculation (if either is present in the array, the result isDouble.NaN).- Returns:
- The mean.
-
calculateMedian
Calculates the median for a list of values (Numberobjects). The list of values will be copied, and the copy sorted, before calculating the median. To avoid this step (if your list of values is already sorted), use thecalculateMedian(List, boolean)method.- Parameters:
values- the values (nullpermitted).- Returns:
- The median.
-
calculateMedian
Calculates the median for a list of values (Numberobjects). IfcopyAndSortisfalse, the list is assumed to be presorted in ascending order by value.- Parameters:
values- the values (nullpermitted).copyAndSort- a flag that controls whether the list of values is copied and sorted.- Returns:
- The median.
-
calculateMedian
Calculates the median for a sublist within a list of values (Numberobjects).- Parameters:
values- the values, in any order (nullnot permitted).start- the start index.end- the end index.- Returns:
- The median.
-
calculateMedian
Calculates the median for a sublist within a list of values (Numberobjects). The entire list will be sorted if theascendingargument isfalse.- Parameters:
values- the values (nullnot permitted).start- the start index.end- the end index.copyAndSort- a flag that that controls whether the list of values is copied and sorted.- Returns:
- The median.
-
getStdDev
Returns the standard deviation of a set of numbers.- Parameters:
data- the data (nullor zero length array not permitted).- Returns:
- The standard deviation of a set of numbers.
-
getLinearFit
Fits a straight line to a set of (x, y) data, returning the slope and intercept.- Parameters:
xData- the x-data (nullnot permitted).yData- the y-data (nullnot permitted).- Returns:
- A double array with the intercept in [0] and the slope in [1].
-
getSlope
Finds the slope of a regression line using least squares.- Parameters:
xData- the x-values (nullnot permitted).yData- the y-values (nullnot permitted).- Returns:
- The slope.
-
getCorrelation
Calculates the correlation between two datasets. Both arrays should contain the same number of items. Null values are treated as zero.Information about the correlation calculation was obtained from: http://trochim.human.cornell.edu/kb/statcorr.htm
- Parameters:
data1- the first dataset.data2- the second dataset.- Returns:
- The correlation.
-
getMovingAverage
Returns a data set for a moving average on the data set passed in.- Parameters:
xData- an array of the x data.yData- an array of the y data.period- the number of data points to average- Returns:
- A double[][] the length of the data set in the first dimension, with two doubles for x and y in the second dimension
-