# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.descriptive.moment

## Class Variance

• java.lang.Object
• com.numericalmethod.suanshu.stats.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 is var.

• ### Constructor Summary

Constructors
Constructor and Description
Variance()
Construct an empty Variance calculator.
Variance(double[] data)
Construct an unbiased Variance calculator.
Variance(double[] data, boolean unbiased)
Construct a Variance calculator, initialized with a sample.
Variance(Variance that)
Copy constructor.
• ### Method Summary

All Methods
Modifier and Type Method and Description
void addData(double... data)
Recompute the statistic with more data, incrementally if possible.
double mean()
Get the sample mean.
long N()
Get the size of the sample.
double standardDeviation()
Get the standard deviation of the sample, which is the square root of the variance.
String toString()
double value()
Get the value of the statistic.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
• ### Constructor Detail

• #### Variance

public Variance()
Construct an empty Variance calculator.
• #### Variance

public Variance(double[] data,
boolean unbiased)
Construct a Variance calculator, initialized with a sample.
Parameters:
data - a sample
unbiased - true if the variance calculation uses the unbiased formula
• #### Variance

public Variance(double[] data)
Construct an unbiased Variance calculator.
Parameters:
data - a sample
• #### Variance

public Variance(Variance that)
Copy constructor.
Parameters:
that - a Variance calculator
• ### 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

public void addData(double... data)
Description copied from interface: Statistic
Recompute the statistic with more data, incrementally if possible.
Specified by:
addData in interface Statistic
Parameters:
data - an array of new items
• #### value

public double value()
Description copied from interface: Statistic
Get the value of the statistic.
Specified by:
value in interface Statistic
Returns:
the statistic
• #### mean

public double mean()
Get the sample mean.
Returns:
the mean
• #### N

public long N()
Description copied from interface: Statistic
Get the size of the sample.
Specified by:
N in interface Statistic
Returns:
the sample size
• #### toString

public String toString()
Overrides:
toString in class Object