Package dev.nm.stat.descriptive.moment
Class Moments
- java.lang.Object
-
- dev.nm.stat.descriptive.moment.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 Summary
Constructors Constructor Description Moments(int order)
Construct an empty moment calculator, computing all moments up to and including theorder
-th moment.Moments(int order, double... data)
Construct a moment calculator, computing all moments up to and including theorder
-th moment.Moments(Moments that)
Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 thepower
-th moment of an array ofdata
with respect to amean
.String
toString()
double
value()
Get the value of the statistic.
-
-
-
Constructor Detail
-
Moments
public Moments(int order)
Construct an empty moment calculator, computing all moments up to and including theorder
-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 theorder
-th moment. initialized with a sample.- Parameters:
order
- the order of the highest momentdata
- 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.
-
value
public double value()
Description copied from interface:Statistic
Get the value of the statistic.
-
N
public long N()
Description copied from interface:Statistic
Get the size of the sample.
-
sumsOfPowersOfDifferences
public static double sumsOfPowersOfDifferences(int power, double mean, double... data)
Compute thepower
-th moment of an array ofdata
with respect to amean
.- Parameters:
power
- the power to raise the difference tomean
- the reference/center of the data, e.g., 0 or the meandata
- the data array- Returns:
- the
power
-th moment of an array ofdata
with respect to amean
-
-