Class Moments

  • All Implemented Interfaces:
    Statistic

    public class Moments
    extends Object
    implements Statistic
    Compute the central moment of a data set incrementally. The n-th moment is the expected value of the n-th power of the differences from the mean. That is,
    μk = E[(X - E(X))k]
    This implementation uses Pébay's update formula to incrementally compute the new statistic.
    See Also:
    • "Pébay, Philippe, "Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments," Technical Report SAND2008-6212, Sandia National Laboratories, 2008."
    • Wikipedia: Moment (mathematics)
    • Constructor Detail

      • Moments

        public Moments​(int order)
        Construct an empty moment calculator, computing all moments up to and including the order-th moment.
        Parameters:
        order - the number of the highest moment
      • Moments

        public Moments​(int order,
                       double... data)
        Construct a moment calculator, computing all moments up to and including the order-th moment. initialized with a sample.
        Parameters:
        order - the order of the highest moment
        data - a sample
      • Moments

        public Moments​(Moments that)
        Copy constructor.
        Parameters:
        that - a moment calculator
    • Method Detail

      • centralMoment

        public double centralMoment​(int k)
        Get the value of the k-th central moment. This method can be used to compute the lower moments. For example, centralMoment(1) is the mean. Note that higher central moments do not correspond to variance, skew, kurtosis, etc.
        Parameters:
        k - the order of the moment
        Returns:
        the value of the k-th central moment
      • 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
      • value

        public double value()
        Description copied from interface: Statistic
        Get the value of the statistic.
        Specified by:
        value in interface Statistic
        Returns:
        the statistic
      • 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
      • sumsOfPowersOfDifferences

        public static double sumsOfPowersOfDifferences​(int power,
                                                       double mean,
                                                       double... data)
        Compute the power-th moment of an array of data with respect to a mean.
        Parameters:
        power - the power to raise the difference to
        mean - the reference/center of the data, e.g., 0 or the mean
        data - the data array
        Returns:
        the power-th moment of an array of data with respect to a mean