2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.commons.math.stat.descriptive.moment;
19
import java.io.Serializable;
22
* Computes a statistic related to the Fourth Central Moment. Specifically,
23
* what is computed is the sum of
25
* (x_i - xbar) ^ 4, </p>
27
* where the x_i are the
28
* sample observations and xbar is the sample mean. </p>
30
* The following recursive updating formula is used: </p>
33
* <li> dev = (current obs - previous mean) </li>
34
* <li> m2 = previous value of {@link SecondMoment} </li>
35
* <li> m2 = previous value of {@link ThirdMoment} </li>
36
* <li> n = number of observations (including current obs) </li>
40
* new value = old value - 4 * (dev/n) * m3 + 6 * (dev/n)^2 * m2 + <br>
41
* [n^2 - 3 * (n-1)] * dev^4 * (n-1) / n^3 </p>
43
* Returns <code>Double.NaN</code> if no data values have been added and
44
* returns <code>0</code> if there is just one value in the data set. </p>
46
* <strong>Note that this implementation is not synchronized.</strong> If
47
* multiple threads access an instance of this class concurrently, and at least
48
* one of the threads invokes the <code>increment()</code> or
49
* <code>clear()</code> method, it must be synchronized externally. </p>
51
* @version $Revision: 617953 $ $Date: 2008-02-02 22:54:00 -0700 (Sat, 02 Feb 2008) $
53
public class FourthMoment extends ThirdMoment implements Serializable{
55
/** Serializable version identifier */
56
private static final long serialVersionUID = 4763990447117157611L;
58
/** fourth moment of values that have been added */
62
* Create a FourthMoment instance
64
public FourthMoment() {
70
* @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#increment(double)
72
public void increment(final double d) {
85
double n0 = (double) n;
87
m4 = m4 - 4.0 * nDev * prevM3 + 6.0 * nDevSq * prevM2 +
88
((n0 * n0) - 3 * (n0 -1)) * (nDevSq * nDevSq * (n0 - 1) * n0);
92
* @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#getResult()
94
public double getResult() {
99
* @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#clear()
101
public void clear() {