Top Description Fields Constructors Methods
org.apache.commons.math3.stat.descriptive.moment

public Class SecondMoment

extends FirstMoment
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.apache.commons.math3.stat.descriptive.moment.ThirdMoment
Imports
java.io.Serializable, org.apache.commons.math3.exception.NullArgumentException, org.apache.commons.math3.util.MathUtils

Computes a statistic related to the Second Central Moment. Specifically, what is computed is the sum of squared deviations from the sample mean.

The following recursive updating formula is used:

Let

Then

new value = old value + dev^2 * (n -1) / n.

Returns Double.NaN if no data values have been added and returns 0 if there is just one value in the data set. Note that Double.NaN may also be returned if the input includes NaN and / or infinite values.

Note that this implementation is not synchronized. If multiple threads access an instance of this class concurrently, and at least one of the threads invokes the increment() or clear() method, it must be synchronized externally.

Field Summary

Modifier and TypeField and Description
protected double
m2

second moment of values that have been added

private static final long
Inherited from org.apache.commons.math3.stat.descriptive.moment.FirstMoment:
devm1nnDev

Constructor Summary

AccessConstructor and Description
public
SecondMoment()

Create a SecondMoment instance

public
SecondMoment(SecondMoment
the SecondMoment instance to copy
original
)

Copy constructor, creates a new SecondMoment identical to the original

Method Summary

Modifier and TypeMethod and Description
public void
public SecondMoment
public static void
copy(SecondMoment
SecondMoment to copy
source
,
SecondMoment
SecondMoment to copy to
dest
)

Copies source to dest.

public double
public void
increment(final double
the new value.
d
)

Overrides org.apache.commons.math3.stat.descriptive.moment.FirstMoment.increment.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

Updates the internal state of the statistic to reflect the addition of the new value.

Inherited from org.apache.commons.math3.stat.descriptive.moment.FirstMoment:
copygetN

Field Detail

m2back to summary
protected double m2

second moment of values that have been added

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.math3.stat.descriptive.moment.FirstMoment.serialVersionUID.

Serializable version identifier

Constructor Detail

SecondMomentback to summary
public SecondMoment()

Create a SecondMoment instance

SecondMomentback to summary
public SecondMoment(SecondMoment original) throws NullArgumentException

Copy constructor, creates a new SecondMoment identical to the original

Parameters
original:SecondMoment

the SecondMoment instance to copy

Exceptions
NullArgumentException:
if original is null

Method Detail

clearback to summary
public void clear()

Overrides org.apache.commons.math3.stat.descriptive.moment.FirstMoment.clear.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.clear.

Doc from org.apache.commons.math3.stat.descriptive.moment.FirstMoment.clear.

Clears the internal state of the Statistic

Annotations
@Override
copyback to summary
public SecondMoment copy()

Overrides org.apache.commons.math3.stat.descriptive.moment.FirstMoment.copy.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.copy, org.apache.commons.math3.stat.descriptive.UnivariateStatistic.copy.

Doc from org.apache.commons.math3.stat.descriptive.moment.FirstMoment.copy.

Returns a copy of the statistic with the same internal state.

Returns:SecondMoment

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.copy.

a copy of the statistic

Annotations
@Override
copyback to summary
public static void copy(SecondMoment source, SecondMoment dest) throws NullArgumentException

Copies source to dest.

Neither source nor dest can be null.

Parameters
source:SecondMoment

SecondMoment to copy

dest:SecondMoment

SecondMoment to copy to

Exceptions
NullArgumentException:
if either source or dest is null
getResultback to summary
public double getResult()

Overrides org.apache.commons.math3.stat.descriptive.moment.FirstMoment.getResult.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getResult.

Doc from org.apache.commons.math3.stat.descriptive.moment.FirstMoment.getResult.

Returns the current value of the Statistic.

Returns:double

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.getResult.

value of the statistic, Double.NaN if it has been cleared or just instantiated.

Annotations
@Override
incrementback to summary
public void increment(final double d)

Overrides org.apache.commons.math3.stat.descriptive.moment.FirstMoment.increment.

Implements org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

Doc from org.apache.commons.math3.stat.descriptive.moment.FirstMoment.increment.

Updates the internal state of the statistic to reflect the addition of the new value.

Parameters
d:double

Doc from org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic.increment.

the new value.

Annotations
@Override