From f5ae32413af5a85466e2953e4acc942962a3e85e Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Sat, 20 Mar 2004 23:55:19 +0000 Subject: [PATCH] Corrected javadoc, minor improvment to computation. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141131 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/stat/univariate/moment/Skewness.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java b/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java index 2457219a8..fe44208f8 100644 --- a/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java +++ b/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java @@ -20,7 +20,15 @@ import java.io.Serializable; import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic; /** - * @version $Revision: 1.17 $ $Date: 2004/03/04 04:25:09 $ + * Computes Skewness. + *

+ * We use the following formula to define skewness: + *

+ * skewness = [n / (n -1) (n - 2)] sum[(x_i - mean)^3] / std^3 + *

+ * where n is the number of values, mean is the {@link Mean} and std is the {@link StandardDeviation} + * + * @version $Revision: 1.18 $ $Date: 2004/03/20 23:55:19 $ */ public class Skewness extends AbstractStorelessUnivariateStatistic implements Serializable { @@ -64,7 +72,9 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se } /** - * @see org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult() + * Returns the value of the statistic based on the values that have been added. + *

+ * See {@link Skewness} for the definition used in the computation. */ public double getResult() { if (n < moment.n) { @@ -110,16 +120,10 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se 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 - * - * corrected two pass formula (14.1.8), and also referenced in + * Returns the Skewness of the values array. *

- * "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. - *

+ * See {@link 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 @@ public class Skewness extends AbstractStorelessUnivariateStatistic implements Se 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;