SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.descriptive.moment
Class Moments

java.lang.Object
  extended by com.numericalmethod.suanshu.stats.descriptive.moment.Moments
All Implemented Interfaces:
Statistic

public class Moments
extends java.lang.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.

 μk = E[(X - E(X))k]
 

This implementation uses Pébay's update formula to incrementally compute the new statistic.

See Also:

Field Summary
 int order
          the highest moment to compute
 
Constructor Summary
Moments(int order)
          Construct an instance to compute all moments up to the order-th moment.
Moments(int order, double... data)
          Construct an instance to compute all moments up to the order-th moment, initialized with a sample.
Moments(Moments that)
          Copy constructor.
 
Method Summary
 void addData(double... data)
          Recompute the statistic, incrementally if possible.
 double centralMoment(int k)
          Get the value of the k-th central moment.
 long N()
          Get the size of the sample.
 java.lang.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
 

Field Detail

order

public final int order
the highest moment to compute

Constructor Detail

Moments

public Moments(int order)
Construct an instance to compute all moments up to the order-th moment.

Parameters:
order - the number of the highest moment

Moments

public Moments(int order,
               double... data)
Construct an instance to compute all moments up to the order-th moment, initialized with a sample.

Parameters:
order - the number of the highest moment
data - a sample

Moments

public Moments(Moments that)
Copy constructor.

Parameters:
that - another Moments object
Method Detail

addData

public void addData(double... data)
Description copied from interface: Statistic
Recompute the statistic, 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

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. For higher central moments, they do not correspond to variance, skew, kurtosis, etc.

Parameters:
k - the order of the moment
Returns:
the value of the k-th central moment

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.