[Kst] kdeextragear-2/kst/plugins/statistics

Andrew Walker arwalker at sumusltd.com
Fri Jan 30 20:42:18 CET 2004


CVS commit by arwalker: 

Added absolute deviation, skewness, and kurtosis


  M +26 -7     statistics.cpp   1.2
  M +12 -0     statistics.xml   1.2


--- kdeextragear-2/kst/plugins/statistics/statistics.cpp  #1.1:1.2
@@ -79,4 +79,8 @@ int statistics( const double *const inAr
   double        dMinimum = 0.0;
   double dMaximum = 0.0;
+  double dVariance = 0.0;
+  double dAbsoluteDeviation = 0.0;
+  double dSkewness = 0.0;
+  double dKurtosis = 0.0;
   int iLength;
   int iRetVal = -1;
@@ -104,16 +108,27 @@ int statistics( const double *const inAr
     if( iLength > 1 )
     {
-      dStandardDeviation  = 1.0 / ( (double)iLength - 1.0 );
-      dStandardDeviation *= dSquaredTotal - ( dTotal * dTotal / (double)iLength ); 
-      if( dStandardDeviation > 0.0 )
+      dVariance  = 1.0 / ( (double)iLength - 1.0 );
+      dVariance *= dSquaredTotal - ( dTotal * dTotal / (double)iLength ); 
+      if( dVariance > 0.0 )
       {
-        dStandardDeviation = sqrt( dStandardDeviation );
+        dStandardDeviation = sqrt( dVariance );
       }
       else
       {
+        dVariance = 0.0;
         dStandardDeviation = 0.0;
       }
     }            
     
+    for( i=0; i<iLength; i++ ) {
+      dAbsoluteDeviation += fabs( inArrays[0][i] - dMean );
+      dSkewness                            += pow( inArrays[0][i] - dMean, 3.0 );
+      dKurtosis                            += pow( inArrays[0][i] - dMean, 4.0 );
+    }
+    dAbsoluteDeviation /= (double)iLength;
+    dSkewness                              /= (double)iLength * pow( dStandardDeviation, 3.0 );
+    dKurtosis                              /= (double)iLength * pow( dStandardDeviation, 4.0 );
+    dKurtosis                              -= 3.0;
+    
     /*
     sort by phase...
@@ -132,6 +147,10 @@ int statistics( const double *const inAr
     outScalars[1] = dMinimum;
     outScalars[2] = dMaximum;
-    outScalars[3] = dStandardDeviation;
-    outScalars[4] = dMedian;
+    outScalars[3] = dVariance;
+    outScalars[4] = dStandardDeviation;
+    outScalars[5] = dMedian;
+    outScalars[6] = dAbsoluteDeviation;
+    outScalars[7] = dSkewness;
+    outScalars[8] = dKurtosis;
     
     iRetVal = 0;

--- kdeextragear-2/kst/plugins/statistics/statistics.xml  #1.1:1.2
@@ -25,4 +25,7 @@
 </output>
 <output>
+<float type="float" name="Variance" descr="The variance of the data values." />
+</output>
+<output>
 <float type="float" name="Standard deviation" descr="The standard deviation of the data values." />
 </output>
@@ -30,4 +33,13 @@
 <float type="float" name="Median" descr="The median of the data values." />
 </output>
+<output>
+<float type="float" name="Absolute deviation" descr="The absolute deviation of the data values." />
+</output>
+<output>
+<float type="float" name="Skewness" descr="The skewness of the data values." />
+</output>
+<output>
+<float type="float" name="Kurtosis" descr="The kurtosis of the data values." />
+</output>
 </interface>
 </module>





More information about the Kst mailing list