org.jfree.data.statistics
Class Statistics
java.lang.Object
org.jfree.data.statistics.Statistics
A utility class that provides some simple statistical functions.
static double | calculateMean(Collection values) - Returns the mean of a collection of
Number objects.
|
static double | calculateMean(Number[] values) - Returns the mean of an array of numbers.
|
static double | calculateMedian(List values) - Calculates the median for a list of values (
Number objects).
|
static double | calculateMedian(List values, boolean copyAndSort) - Calculates the median for a list of values (
Number objects)
that are assumed to be in ascending order.
|
static double | calculateMedian(List values, int start, int end) - Calculates the median for a sublist within a list of values
(
Number objects).
|
static double | calculateMedian(List values, int start, int end, boolean copyAndSort) - Calculates the median for a sublist within a list of values
(
Number objects).
|
static double | getCorrelation(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 double | getSlope(Number[] xData, Number[] yData) - Finds the slope of a regression line using least squares.
|
static double | getStdDev(Number[] data) - Returns the standard deviation of a set of numbers.
|
calculateMean
public static double calculateMean(Collection values)
Returns the mean of a collection of Number
objects.
values
- the values (null
permitted, returns
Double.NaN
).
calculateMean
public static double calculateMean(Number[] values)
Returns the mean of an array of numbers.
values
- the values (null
permitted, returns
Double.NaN
).
calculateMedian
public static double calculateMedian(List values)
Calculates the median for a list of values (Number
objects).
The list of values will be sorted first.
calculateMedian
public static double calculateMedian(List values,
boolean copyAndSort)
Calculates the median for a list of values (Number
objects)
that are assumed to be in ascending order.
values
- the values.copyAndSort
- a flag that controls whether the list of values is
copied and sorted.
calculateMedian
public static double calculateMedian(List values,
int start,
int end)
Calculates the median for a sublist within a list of values
(Number
objects).
values
- the values (in any order).start
- the start index.end
- the end index.
calculateMedian
public static double calculateMedian(List values,
int start,
int end,
boolean copyAndSort)
Calculates the median for a sublist within a list of values
(
Number
objects). The entire list will be sorted if the
ascending
false
.
values
- the values.start
- the start index.end
- the end index.copyAndSort
- a flag that that controls whether the list of values
is copied and sorted.
getCorrelation
public static double getCorrelation(Number[] data1,
Number[] data2)
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
data1
- the first dataset.data2
- the second dataset.
getLinearFit
public static double[] getLinearFit(Number[] xData,
Number[] yData)
Fits a straight line to a set of (x, y) data, returning the slope and
intercept.
xData
- the x-data.yData
- the y-data.
- A double array with the intercept in [0] and the slope in [1].
getMovingAverage
public static double[][] getMovingAverage(Number[] xData,
Number[] yData,
int period)
Returns a data set for a moving average on the data set passed in.
xData
- an array of the x data.yData
- an array of the y data.period
- the number of data points to average
- A double[][] the length of the data set in the first dimension,
with two doubles for x and y in the second dimension
getSlope
public static double getSlope(Number[] xData,
Number[] yData)
Finds the slope of a regression line using least squares.
xData
- an array of Numbers (the x values).yData
- an array of Numbers (the y values).
getStdDev
public static double getStdDev(Number[] data)
Returns the standard deviation of a set of numbers.
- The standard deviation of a set of numbers.