r59641 - in /trunk/libstatistics-descriptive-perl: Changes META.yml debian/changelog lib/Statistics/Descriptive.pm t/descr.t

carnil-guest at users.alioth.debian.org carnil-guest at users.alioth.debian.org
Mon Jun 21 05:38:27 UTC 2010


Author: carnil-guest
Date: Mon Jun 21 05:38:19 2010
New Revision: 59641

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=59641
Log:
* New upstream release (3.0102)
* New upstream release (3.0200)

Modified:
    trunk/libstatistics-descriptive-perl/Changes
    trunk/libstatistics-descriptive-perl/META.yml
    trunk/libstatistics-descriptive-perl/debian/changelog
    trunk/libstatistics-descriptive-perl/lib/Statistics/Descriptive.pm
    trunk/libstatistics-descriptive-perl/t/descr.t

Modified: trunk/libstatistics-descriptive-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libstatistics-descriptive-perl/Changes?rev=59641&op=diff
==============================================================================
--- trunk/libstatistics-descriptive-perl/Changes (original)
+++ trunk/libstatistics-descriptive-perl/Changes Mon Jun 21 05:38:19 2010
@@ -1,4 +1,9 @@
 Revision history for Perl extension Statistics::Descriptive.
+
+3.0200      June 18, 2010
+    - Added skewness and kurtosis
+        - https://rt.cpan.org/Ticket/Display.html?id=58187
+        - Thanks to Shawn Laffan.
 
 3.0102      June 15, 2010
     - Add the $VERSION variable to Statistics::Descriptive::Sparse and

Modified: trunk/libstatistics-descriptive-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libstatistics-descriptive-perl/META.yml?rev=59641&op=diff
==============================================================================
--- trunk/libstatistics-descriptive-perl/META.yml (original)
+++ trunk/libstatistics-descriptive-perl/META.yml Mon Jun 21 05:38:19 2010
@@ -26,13 +26,13 @@
 provides:
   Statistics::Descriptive:
     file: lib/Statistics/Descriptive.pm
-    version: 3.0102
+    version: 3.0200
   Statistics::Descriptive::Full:
     file: lib/Statistics/Descriptive.pm
-    version: 3.0102
+    version: 3.0200
   Statistics::Descriptive::Sparse:
     file: lib/Statistics/Descriptive.pm
-    version: 3.0102
+    version: 3.0200
 requires:
   Carp: 0
   POSIX: 0
@@ -43,4 +43,4 @@
   homepage: http://web-cpan.berlios.de/modules/Statistics-Descriptive/
   license: http://dev.perl.org/licenses/
   repository: http://svn.berlios.de/svnroot/repos/web-cpan/Statistics-Descriptive/
-version: 3.0102
+version: 3.0200

Modified: trunk/libstatistics-descriptive-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libstatistics-descriptive-perl/debian/changelog?rev=59641&op=diff
==============================================================================
--- trunk/libstatistics-descriptive-perl/debian/changelog (original)
+++ trunk/libstatistics-descriptive-perl/debian/changelog Mon Jun 21 05:38:19 2010
@@ -1,12 +1,15 @@
-libstatistics-descriptive-perl (3.0102-1) UNRELEASED; urgency=low
-
-  IGNORE-VERSION: 3.0102-1
-  Removed one test; add $VERSION to make CPAN indexer happy
+libstatistics-descriptive-perl (3.0200-1) UNRELEASED; urgency=low
 
   [ Ryan Niebur ]
   * Update ryan52's email address
 
- -- Ansgar Burchardt <ansgar at 43-1.org>  Fri, 18 Jun 2010 15:39:35 +0900
+  [Ansgar Burchardt ]
+  * New upstream release (3.0102)
+
+  [ Salvatore Bonaccorso ]
+  * New upstream release (3.0200)
+
+ -- Salvatore Bonaccorso <salvatore.bonaccorso at gmail.com>  Mon, 21 Jun 2010 07:37:10 +0200
 
 libstatistics-descriptive-perl (3.0100-1) unstable; urgency=low
 

Modified: trunk/libstatistics-descriptive-perl/lib/Statistics/Descriptive.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libstatistics-descriptive-perl/lib/Statistics/Descriptive.pm?rev=59641&op=diff
==============================================================================
--- trunk/libstatistics-descriptive-perl/lib/Statistics/Descriptive.pm (original)
+++ trunk/libstatistics-descriptive-perl/lib/Statistics/Descriptive.pm Mon Jun 21 05:38:19 2010
@@ -10,7 +10,7 @@
 		  ##Perl5.  01-03 weren't bug free.
 use vars (qw($VERSION $Tolerance));
 
-$VERSION = '3.0102';
+$VERSION = '3.0200';
 
 $Tolerance = 0.0;
 
@@ -18,7 +18,7 @@
 
 use vars qw($VERSION);
 
-$VERSION = '3.0102';
+$VERSION = '3.0200';
 
 use vars qw(%fields);
 use Carp;
@@ -234,7 +234,7 @@
 
 use vars qw($VERSION);
 
-$VERSION = '3.0102';
+$VERSION = '3.0200';
 
 use Carp;
 
@@ -255,6 +255,7 @@
 __PACKAGE__->_make_private_accessors(
     [qw(data frequency geometric_mean harmonic_mean 
         least_squares_fit median mode
+        skewness kurtosis
        )
     ]
 );
@@ -606,6 +607,71 @@
 
     return $self->_geometric_mean();
 }
+
+sub skewness {
+    my $self = shift;
+
+    if (!defined($self->_skewness()))
+    {
+        my $n    = $self->count();
+        my $sd   = $self->standard_deviation();
+        
+        my $skew;
+        
+        #  skip if insufficient records
+        if ( $sd && $n > 2) {
+            
+            my $mean = $self->mean();
+            
+            my $sum_pow3;
+            
+            foreach my $rec ( $self->get_data ) {
+                my $value  = (($rec - $mean) / $sd);
+                $sum_pow3 +=  $value ** 3;
+            }
+            
+            my $correction = $n / ( ($n-1) * ($n-2) );
+            
+            $skew = $correction * $sum_pow3;
+        }
+
+        $self->_skewness($skew);
+    }
+
+    return $self->_skewness();
+}
+
+sub kurtosis {
+    my $self = shift;
+
+    if (!defined($self->_kurtosis()))
+    {
+        my $kurt;
+        
+        my $n  = $self->count();
+        my $sd   = $self->standard_deviation();
+        
+        if ( $sd && $n > 3) {
+
+            my $mean = $self->mean();
+            
+            my $sum_pow4;
+            foreach my $rec ( $self->get_data ) {
+                $sum_pow4 += ( ($rec - $mean ) / $sd ) ** 4;
+            }
+            
+            my $correction1 = ( $n * ($n+1) ) / ( ($n-1) * ($n-2) * ($n-3) );
+            my $correction2 = ( 3  * ($n-1) ** 2) / ( ($n-2) * ($n-3) );
+            
+            $kurt = ( $correction1 * $sum_pow4 ) - $correction2;
+        }
+        
+        $self->_kurtosis($kurt);
+    }
+
+    return $self->_kurtosis();
+}
+
 
 sub frequency_distribution_ref
 {
@@ -903,6 +969,19 @@
 is called.  Calling the method without an argument returns the value of
 the flag.
 
+=item $stat->skewness();
+
+Returns the skewness of the data. 
+A value of zero is no skew, negative is a left skewed tail,
+positive is a right skewed tail. 
+This is consistent with Excel.
+
+=item $stat->kurtosis();
+
+Returns the kurtosis of the data.
+Positive is peaked, negative is flattened.
+
+
 =item $x = $stat->percentile(25);
 
 =item ($x, $index) = $stat->percentile(25);
@@ -1174,80 +1253,4 @@
 This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.
 
-=head1 REVISION HISTORY
-
-=over 4
-
-=item v2.3
-
-Rolled into November 1998
-
-Code provided by Andrea Spinelli to prevent division by zero and to
-make consistent return values for undefined behavior.  Andrea also
-provided a test bench for the module.
-
-A bug fix for the calculation of frequency distributions.  Thanks to Nick
-Tolli for alerting this to me.
-
-Added 4 lines of code to Makefile.PL to make it easier for the ActiveState
-installation tool to use.  Changes work fine in perl5.004_04, haven't
-tested them under perl5.005xx yet.
-
-=item v2.2
-
-Rolled into March 1998.
-
-Fixed problem with sending 0's and -1's as data.  The old 0 : true ? false
-thing.  Use defined to fix.
-
-Provided a fix for AUTOLOAD/DESTROY/Carp bug.  Very strange.
-
-=item v2.1
-
-August 1997
-
-Fixed errors in statistics algorithms caused by changing the
-interface.
-
-=item v2.0
-
-August 1997
-
-Fixed errors in removing cached values (they weren't being removed!)
-and added sort_data and presorted methods.
-
-June 1997
-
-Transferred ownership of the module from Jason to Colin.
-
-Rewrote OO interface, modified function distribution, added mindex,
-maxdex.
-
-=item v1.1
-
-April 1995
-
-Added LeastSquaresFit and FrequencyDistribution.
-
-=item v1.0 
-
-March 1995
-
-Released to comp.lang.perl and placed on archive sites.
-
-=item v.20
-
-December 1994
-
-Complete rewrite after extensive and invaluable e-mail 
-correspondence with Anno Siegel.
-
-=item v.10
-
-December 1994
-
-Initital concept, released to perl5-porters list.
-
-=back
-
 =cut

Modified: trunk/libstatistics-descriptive-perl/t/descr.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libstatistics-descriptive-perl/t/descr.t?rev=59641&op=diff
==============================================================================
--- trunk/libstatistics-descriptive-perl/t/descr.t (original)
+++ trunk/libstatistics-descriptive-perl/t/descr.t Mon Jun 21 05:38:19 2010
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 22;
+use Test::More tests => 28;
 
 use Benchmark;
 use Statistics::Descriptive;
@@ -346,3 +346,70 @@
     )
 }
 
+{
+    my $stat = Statistics::Descriptive::Full->new();
+    my $expected;
+    
+    $stat->add_data(1 .. 9, 100);
+
+    # TEST
+    $expected = 3.11889574523909;
+    is_between ($stat->skewness(),
+        $expected - 1E-13,
+        $expected + 1E-13,
+        "Skewness of $expected +/- 1E-13"
+    );
+
+    # TEST
+    $expected = 9.79924471616366;
+    is_between ($stat->kurtosis(),
+        $expected - 1E-13,
+        $expected + 1E-13,
+        "Kurtosis of $expected +/- 1E-13"
+    );
+    
+    $stat->add_data(100 .. 110);
+    
+    #  now check that cached skew and kurt values are recalculated
+    
+    # TEST
+    $expected = -0.306705104889384;
+    is_between ($stat->skewness(),
+        $expected - 1E-13,
+        $expected + 1E-13,
+        "Skewness of $expected +/- 1E-13"
+    );
+
+    # TEST
+    $expected = -2.09839497356215;
+    is_between ($stat->kurtosis(),
+        $expected - 1E-13,
+        $expected + 1E-13,
+        "Kurtosis of $expected +/- 1E-13"
+    );
+}
+
+{
+    my $stat = Statistics::Descriptive::Full->new();
+
+    $stat->add_data(1,2);
+    my $def;
+
+    # TEST
+    $def = defined $stat->skewness() ? 1 : 0;
+    is ($def,
+        0,
+        'Skewness is undef for 2 samples'
+    );
+
+    $stat->add_data (1);
+
+    # TEST
+    $def = defined $stat->kurtosis() ? 1 : 0;
+    is ($def,
+        0,
+        'Kurtosis is undef for 3 samples'
+    );
+
+}
+




More information about the Pkg-perl-cvs-commits mailing list