psteitz 2004/03/20 15:55:19
Modified: math/src/java/org/apache/commons/math/stat/univariate/moment
Skewness.java
Log:
Corrected javadoc, minor improvment to computation.
Revision Changes Path
1.18 +19 -18
jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java
Index: Skewness.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Skewness.java 4 Mar 2004 04:25:09 -0000 1.17
+++ Skewness.java 20 Mar 2004 23:55:19 -0000 1.18
@@ -20,6 +20,14 @@
import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic;
/**
+ * Computes Skewness.
+ * <p>
+ * We use the following formula to define skewness:
+ * <p>
+ * skewness = [n / (n -1) (n - 2)] sum[(x_i - mean)^3] / std^3
+ * <p>
+ * where n is the number of values, mean is the [EMAIL PROTECTED] Mean} and std is
the [EMAIL PROTECTED] StandardDeviation}
+ *
* @version $Revision$ $Date$
*/
public class Skewness extends AbstractStorelessUnivariateStatistic implements
Serializable {
@@ -64,7 +72,9 @@
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
+ * Returns the value of the statistic based on the values that have been added.
+ * <p>
+ * See [EMAIL PROTECTED] Skewness} for the definition used in the computation.
*/
public double getResult() {
if (n < moment.n) {
@@ -110,16 +120,10 @@
Mean mean = new Mean();
/**
- * Returns the skewness of a collection of values. Skewness is a
- * measure of the assymetry of a given distribution.
- * This algorithm uses a corrected two pass algorithm of the following
- * <a href="http://lib-www.lanl.gov/numerical/bookcpdf/c14-1.pdf">
- * corrected two pass formula (14.1.8)</a>, and also referenced in
+ * Returns the Skewness of the values array.
* <p>
- * "Algorithms for Computing the Sample Variance: Analysis and
- * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
- * 1983, American Statistician, vol. 37, pp. 242?247.
- * </p>
+ * See [EMAIL PROTECTED] Skewness} for the definition used in the computation.
+ *
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length the number of elements to include
@@ -151,17 +155,14 @@
accum += Math.pow((values[i] - m), 2.0);
accum2 += (values[i] - m);
}
- double stdDev =
- Math.sqrt(
- (accum - (Math.pow(accum2, 2) / ((double) length))) /
- (double) (length - 1));
+ double stdDev = Math.sqrt((accum - (Math.pow(accum2, 2) / ((double)
length))) /
+ (double) (length - 1));
- // Calculate the skew as the sum the cubes of the distance
- // from the mean divided by the standard deviation.
double accum3 = 0.0;
for (int i = begin; i < begin + length; i++) {
- accum3 += Math.pow((values[i] - m) / stdDev, 3.0);
+ accum3 += Math.pow(values[i] - m, 3.0d);
}
+ accum3 /= Math.pow(stdDev, 3.0d);
// Get N
double n0 = length;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]