java.lang.Object
org.bzdev.math.stats.BasicStatsMV
- Direct Known Subclasses:
BasicStatsMV.Population
,BasicStatsMV.Sample
Class to compute the mean and variance for multiple values..
This class provides the variances for a vector of measurements
or random variables measured or evaluated multiple times. The inner
classes are subclasses of this class:
-
Sample
is used to compute the variances for the case in which the dataset whose variances are computed is a representative sample. -
Population
is used to compute the variances for the case where the dataset represents every case being computed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Class to compute the variance for a total set of values, as opposed to a sample of values.static class
Class to compute a sample variance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BasicStatsMV
(double[][] arrays, int n) Constructor given an array containing the initial dataset used to compute a variance.protected
BasicStatsMV
(double[] means, double[] variances, long m) Constructor given means, uncorrected variances, and a data-set sizeprotected
BasicStatsMV
(int n) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionadd
(double[] values) Add a new vector of values.addAll
(BasicStatsMV stats) Add the values from another BasicStatsMV object.protected abstract double
The elements of the variances array that is computed will be scaled by a correction factor.double[]
getMeans()
Get a the mean values.double[]
getMeans
(double[] results) Get a the mean values.double[]
getSDevs()
Get the standard deviations.double[]
getSDevs
(double[] results) Get the standard deviations.double[]
Get the variances.double[]
getVariances
(double[] results) Get the variances.int
length()
Get the number of variables.long
size()
Get the number of data-point arrays that were entered.
-
Constructor Details
-
BasicStatsMV
protected BasicStatsMV(int n) Constructor. The methodadd(double[])
must be called repeatedly to provide the dataset used to compute the variance and mean array.- Parameters:
n
- the number of variables
-
BasicStatsMV
protected BasicStatsMV(double[] means, double[] variances, long m) Constructor given means, uncorrected variances, and a data-set size- Parameters:
means
- an array of length n containing the mean values for n variablesvariances
- an array of length n containing the variances for n variablesm
- the data-set size- Throws:
IllegalArgumentException
- the array lengths differ
-
BasicStatsMV
Constructor given an array containing the initial dataset used to compute a variance. Note: More data can be added using theadd(double[])
method.- Parameters:
arrays
- an array, each component of which is an array containing the values for n variablesn
- the number of variables- Throws:
IllegalArgumentException
- the arrays argument was too short
-
-
Method Details
-
size
public long size()Get the number of data-point arrays that were entered.- Returns:
- the number of data-point tarrays that were entered
-
length
public int length()Get the number of variables. This is the length of each array that will be entered (if an array is longer than this value, only the first n elements will be used.- Returns:
- the number of variables.
-
getCorrection
protected abstract double getCorrection()The elements of the variances array that is computed will be scaled by a correction factor. This factor should be 1.0 when the dataset 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 factors.- Returns:
- the correction factor; Double.NaN if the factor cannot be computed due to too few entries
-
add
Add a new vector of values. The vector's length must be at least n, where n is the number of variables.- Parameters:
values
- a vector of values (the first n entries will be used)- Returns:
- this object
- Throws:
IllegalArgumentException
- the argument array was too short
-
addAll
Add the values from another BasicStatsMV object.- Parameters:
stats
- the BasicStats object whose values should be added- Returns:
- this object
-
getVariances
Get the variances.- Returns:
- the variances
- Throws:
IllegalStateException
- the data set was too small or missing
-
getVariances
Get the variances. If the argument array is too short or is null, a new array will be allocated. The returned value will be the argument array if that is long enough or a newly allocated array otherwise.- Parameters:
results
- an array to hold the variances- Returns:
- the variances
- Throws:
IllegalStateException
- the data set was too small or missing
-
getSDevs
Get the standard deviations.- Returns:
- the standard deviations
- Throws:
IllegalStateException
- the data set was too small or missing
-
getSDevs
Get the standard deviations. If the argument array is too short or is null, a new array will be allocated. The returned value will be the argument array if that is long enough or a newly allocated array otherwise.- Parameters:
results
- an array to hold the standard deviations- Returns:
- the standard deviations
- Throws:
IllegalStateException
- the data set was too small or missing
-
getMeans
Get a the mean values.- Returns:
- the mean values
- Throws:
IllegalStateException
- the data set was too small or missing
-
getMeans
Get a the mean values. If the argument array is too short or is null, a new array will be allocated. The returned value will be the argument array if that is long enough or a newly allocated array otherwise.- Parameters:
results
- an array to hold the means- Returns:
- the mean values
- Throws:
IllegalStateException
- the data set was too small or missing
-