- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
BasicStats.Population
,BasicStats.Sample
This is an abstract class: subclasses provide population and sample variances and standard deviations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
BasicStats specialized to compute a population mean and variance.static class
BasicStats specialized to compute a sample mean and variance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Constructor.protected
BasicStats
(double[] array) Constructor given an array containing all the data used to compute a mean and variance.protected
BasicStats
(double mean, double variance, long n) Constructor given a mean, variance, and data-set size. -
Method Summary
Modifier and TypeMethodDescriptionadd
(double value) Add a new value to the computation of the mean and variance.addAll
(BasicStats stats) Add the values from another BasicStats object.clone()
protected abstract double
Get the correction factor.double
getMean()
Get the mean value.double
getSDev()
Get the standard deviation.double
Get the variance.static double
mean
(double[] data) Compute the mean of a data set.static double
median
(double[] data) Compute the median of a data set.long
size()
Get the number of data points that were entered.static double
trimmedMean
(int D, double[] data) Compute the P-percent trimmed mean of a data set when P = (100)(1/D) for a positive integer D.static double
trimmedMean
(int N, int D, double[] data) Compute the P-percent trimmed mean of a data set when P = 100(N/D) for positive integers N and D.
-
Constructor Details
-
BasicStats
protected BasicStats()Constructor. The methodadd(double)
must be called repeatedly to provide the data used to compute the covariance matrix and mean array. -
BasicStats
protected BasicStats(double mean, double variance, long n) Constructor given a mean, variance, and data-set size. The uncorrected variance is the variance for a population variance. Constructors for subclasses should divide the variance provided by the value thatgetCorrection()
would return.- Parameters:
mean
- the mean valuevariance
- the uncorrected variancen
- the data-set size
-
BasicStats
protected BasicStats(double[] array) Constructor given an array containing all the data used to compute a mean and variance.- Parameters:
array
- an array, each component of which is a value to add to the computation- Throws:
NullPointerException
- the argument was null.
-
-
Method Details
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
getCorrection
protected abstract double getCorrection()Get the correction factor. The variance that is computed will be scaled by a correction factor. This factor should be 1.0 when the data represents a total population. For a sample of a population, the factor is m/(m-1) where m is the sample size (the number of data points).- Returns:
- the correction factor
-
add
Add a new value to the computation of the mean and variance.- Parameters:
value
- the value to add- Returns:
- this object
-
addAll
Add the values from another BasicStats object.- Parameters:
stats
- the BasicStats object whose values should be added- Returns:
- this object
-
size
public long size()Get the number of data points that were entered.- Returns:
- the number of data points that were entered
-
getVariance
Get the variance.- Returns:
- the variance
- Throws:
IllegalStateException
- not enough data to compute a variance
-
getSDev
public double getSDev()Get the standard deviation.- Returns:
- the standard deviation
-
getMean
public double getMean()Get the mean value.- Returns:
- the mean value
-
mean
public static double mean(double[] data) Compute the mean of a data set.- Parameters:
data
- the data whose trimmed is to be computed- Returns:
- the mean of the data set
- Throws:
IllegalArgumentException
- if the length of the array is zeroNullPointerException
- the last argument was null.
-
trimmedMean
public static double trimmedMean(int D, double[] data) Compute the P-percent trimmed mean of a data set when P = (100)(1/D) for a positive integer D. The data will be divided into a number of bins and the mean will be computed ignoring the first and last bin.There are several common cases:
- for a 25% trimmed mean, set the number of bins to 4.
- for a 10% trimmed mean, set the number of bins to 10.
- for a 5% trimmed mean, set the number of bins to 20.
- Parameters:
D
- the number of bins in which to divide the datadata
- the data whose trimmed mean is to be computed- Returns:
- the trimmed mean of the data
- Throws:
IllegalArgumentException
- if D is not a positive integer or the length of the array is zeroNullPointerException
- the last argument was null
-
trimmedMean
public static double trimmedMean(int N, int D, double[] data) Compute the P-percent trimmed mean of a data set when P = 100(N/D) for positive integers N and D. The data will be divided into a number of bins and the mean will be computed ignoring the first and last bin.The data will be divided into bins whose length is the length of the data set multiplied by N/D. Rational numbers are used to represent the fraction trimmed to minimize the dependency of the result on floating-point roundoff errors. A typical choice for D is 100 (in which case N is the percentage trimmed) or 1000 (so that 125, for example, will correspond to 12.5%).
If the data set length is not an integral multiple of the number of bins, The trimmed means are computed given offsets from the initial index (0) and ending index (data.length), repeated twice to bracket the desired value. An esimate is then made by interpolation.
- Parameters:
N
- the numererator of the ratio N/D representing the fraction of the data set trimmed from both endsD
- the denominator of the ratio N/D representing the fraction of the data set trimmed from both endsdata
- the data whose trimmed mean is to be computed- Returns:
- the trimmed mean of the data
- Throws:
IllegalArgumentException
- if N or D is not a positive integer or the length of the array is zeroNullPointerException
- the last argument was null
-
median
public static double median(double[] data) Compute the median of a data set.- Parameters:
data
- the data set- Returns:
- the median of the values stored in argument array
- Throws:
IllegalArgumentException
- if the length of the array is zeroNullPointerException
- the last argument was null.
-