Package dev.nm.stat.descriptive.moment
Class Variance
- java.lang.Object
-
- dev.nm.stat.descriptive.moment.Variance
-
- All Implemented Interfaces:
Statistic
public class Variance extends Object implements Statistic
The variance of a sample is the average squared deviations from the sample mean. It measures the amount of variation the sample values have. That is,Var(X) = E[(X - E(X))2]
This implementation uses Chan's update formula to incrementally compute the new statistic. The R equivalent function isvar.- See Also:
- Wikipedia: Variance
- Wikipedia: Algorithms for calculating variance
- "Tony F. Chan, Gene H. Golub, Randall J. LeVeque, "Updating Formulae and a Pairwise Algorithm for Computing Sample Variances," Technical Report STAN-CS-79-773, Department of Computer Science, Stanford University, 1979."
-
-
Constructor Summary
Constructors Constructor Description Variance()Construct an emptyVariancecalculator.Variance(double[] data)Construct an unbiasedVariancecalculator.Variance(double[] data, boolean unbiased)Construct aVariancecalculator, initialized with a sample.Variance(Variance that)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddData(double... data)Recompute the statistic with more data, incrementally if possible.doublemean()Get the sample mean.longN()Get the size of the sample.doublestandardDeviation()Get the standard deviation of the sample, which is the square root of the variance.StringtoString()doublevalue()Get the value of the statistic.
-
-
-
Constructor Detail
-
Variance
public Variance()
Construct an emptyVariancecalculator.
-
Variance
public Variance(double[] data, boolean unbiased)Construct aVariancecalculator, initialized with a sample.- Parameters:
data- a sampleunbiased-trueif the variance calculation uses the unbiased formula
-
Variance
public Variance(double[] data)
Construct an unbiasedVariancecalculator.- Parameters:
data- a sample
-
Variance
public Variance(Variance that)
Copy constructor.- Parameters:
that- aVariancecalculator
-
-
Method Detail
-
standardDeviation
public double standardDeviation()
Get the standard deviation of the sample, which is the square root of the variance.- Returns:
- the standard deviation
-
addData
public void addData(double... data)
Description copied from interface:StatisticRecompute the statistic with more data, incrementally if possible.
-
value
public double value()
Description copied from interface:StatisticGet the value of the statistic.
-
mean
public double mean()
Get the sample mean.- Returns:
- the mean
-
N
public long N()
Description copied from interface:StatisticGet the size of the sample.
-
-