java.lang.Object
org.bzdev.math.stats.BasicStats
org.bzdev.math.stats.BasicStats.Sample
- All Implemented Interfaces:
Cloneable
- Enclosing class:
- BasicStats
BasicStats specialized to compute a sample mean and variance.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.math.stats.BasicStats
BasicStats.Population, BasicStats.Sample
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected double
Get the correction factor.static final org.bzdev.math.stats.BasicStats.Sample.Identity
identity()
Get an instance of Sample that serves as an identity forStream.reduce(Object,BiFunction,BinaryOperator)
.Methods inherited from class org.bzdev.math.stats.BasicStats
add, addAll, clone, getMean, getSDev, getVariance, mean, median, size, trimmedMean, trimmedMean
-
Constructor Details
-
Sample
public Sample()Constructor. The methodBasicStats.add(double)
must be called repeatedly to provide the data used to compute the covariance matrix and mean array. -
Sample
public Sample(double mean, double variance, long n) Constructor given a mean, variance, and data-set size.- Parameters:
mean
- the mean valuevariance
- the sample variancen
- the data-set size
-
Sample
public Sample(double[] array) Constructor given an array containing all the data used to compute a covariance matrix.- Parameters:
array
- an array, each component of which is an array containing the values for n variables
-
-
Method Details
-
identity
public static final org.bzdev.math.stats.BasicStats.Sample.Identity identity()Get an instance of Sample that serves as an identity forStream.reduce(Object,BiFunction,BinaryOperator)
. An identity implementation will not store any data, but will return an appropriate instance of BasicStats that does store the data added, but with no history of previously added values.If rv is a random variable that returns a stream of double values, the following example shows a typical use of this method:
The method mapToObj is needed because the reduce method is a method ofBasicStats stats = rv.parallelStream(1000000) .mapToObj(Double::valueOf) .reduce(BasicStats.Sample.identity(), BasicStats::add, BasicStats::addAll);
Stream
but notDoubleStream
. When used with a parallel stream, the mapToObj method;'s argument will typically be a lambda expression that peforms significantly more compuation: otherwise the cost of threading can result in the parallel version performing worse than the sequential version.- Returns:
- an instance of BasicStat that can be used as an idenity in a "reduce" method.
-
getCorrection
protected double getCorrection()Description copied from class:BasicStats
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).- Specified by:
getCorrection
in classBasicStats
- Returns:
- the correction factor
-