# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.descriptive.moment

## 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.
• "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 Summary

Constructors
Constructor and Description
Moments(int order)
Construct an empty moment calculator, computing all moments up to and including the order-th moment.
Moments(int order, double... data)
Construct a moment calculator, computing all moments up to and including the order-th moment.
Moments(Moments 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 centralMoment(int k)
Get the value of the k-th central moment.
long N()
Get the size of the sample.
static double sumsOfPowersOfDifferences(int power, double mean, double... data)
Compute the power-th moment of an array of data with respect to a mean.
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

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

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
• #### toString

public String toString()
Overrides:
toString in class Object
• #### 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