SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.descriptive.moment.weighted

Class WeightedVariance

• java.lang.Object
• com.numericalmethod.suanshu.stats.descriptive.moment.weighted.WeightedVariance
• All Implemented Interfaces:
Statistic

public class WeightedVariance
extends Object
implements Statistic
The weighted sample variance is defined as follows. The biased sample variance is: $\sigma^2 = \frac{\sum_{i=1}^N w_i \left(x_i - \mu^*\right)^2 }{V_1}$ where $$V_1 = \sum_{i=1}^N w_i$$ and $$\mu^*$$ is the weighted mean. The unbiased sample variance is (assuming each $$x_i$$ is drawn from a Gaussian distribution with variance $$1 / w_i$$): $s^2\ = \frac {V_1} {V_1^2-V_2} \sum_{i=1}^N w_i \left(x_i - \mu^*\right)^2$ where $$V_2 = \sum_{i=1}^N {w_i^2}$$.
Wikipedia: Weighted mean - Weighted sample variance
• Constructor Summary

Constructors
Constructor and Description
WeightedVariance()
WeightedVariance(boolean unbiased)
WeightedVariance(double[] data, double[] weights)
WeightedVariance(double[] data, double[] weights, boolean unbiased)
• Method Summary

All Methods
Modifier and Type Method and Description
void addData(double... data)
Recompute the statistic with more data, incrementally if possible.
void addData(double[] data, double[] weights)
long N()
Get the size of the sample.
double stdev()
double value()
Get the value of the statistic.
• Methods inherited from class java.lang.Object

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

• WeightedVariance

public WeightedVariance()
• WeightedVariance

public WeightedVariance(boolean unbiased)
• WeightedVariance

public WeightedVariance(double[] data,
double[] weights)
• WeightedVariance

public WeightedVariance(double[] data,
double[] weights,
boolean unbiased)
• Method Detail

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

public void addData(double[] data,
double[] weights)
• 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
• value

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

public double stdev()