Class 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}\).
    See Also:
    Wikipedia: Weighted mean - Weighted sample variance
    • 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

      • addData

        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
      • addData

        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()