- All Implemented Interfaces:
- Serializable, StorelessUnivariateStatistic, UnivariateStatistic, WeightedEvaluation, MathArrays.Function
public class Varianceextends AbstractStorelessUnivariateStatisticimplements Serializable, WeightedEvaluationComputes the variance of the available values. By default, the unbiased "sample variance" definitional formula is used:
variance = sum((x_i - mean)^2) / (n - 1)
where mean is the
nis the number of sample observations.
The definitional formula does not have good numerical properties, so this implementation does not compute the statistic using the definitional formula.
getResultmethod computes the variance using updating formulas based on West's algorithm, as described in Chan, T. F. and J. G. Lewis 1979, Communications of the ACM, vol. 22 no. 9, pp. 526-531.
evaluatemethods leverage the fact that they have the full array of values in memory to execute a two-pass algorithm. Specifically, these methods use the "corrected two-pass algorithm" from Chan, Golub, Levesque, Algorithms for Computing the Sample Variance, American Statistician, vol. 37, no. 3 (1983) pp. 242-247.
incrementAlland then executing
getResultwill sometimes give a different, less accurate, result than executing
evaluatewith the full array of values. The former approach should only be used when the full array of values is not available.
The "population variance" ( sum((x_i - mean)^2) / n ) can also be computed using this statistic. The
isBiasCorrectedproperty determines whether the "population" or "sample" value is returned by the
getResultmethods. To compute population variances, set this property to
Note that this implementation is not synchronized. If multiple threads access an instance of this class concurrently, and at least one of the threads invokes the
clear()method, it must be synchronized externally.
- See Also:
- Serialized Form