r36648 - in /branches/upstream/libstatistics-basic-perl/current: Basic.pm Basic/Vector.pm Changes MANIFEST META.yml Makefile.PL lib/Statistics/Basic.pod t/75_filtered_missings.t
ryan52-guest at users.alioth.debian.org
ryan52-guest at users.alioth.debian.org
Fri May 29 15:04:55 UTC 2009
Author: ryan52-guest
Date: Fri May 29 15:04:47 2009
New Revision: 36648
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=36648
Log:
[svn-upgrade] Integrating new upstream version, libstatistics-basic-perl (1.6500)
Added:
branches/upstream/libstatistics-basic-perl/current/t/75_filtered_missings.t
Modified:
branches/upstream/libstatistics-basic-perl/current/Basic.pm
branches/upstream/libstatistics-basic-perl/current/Basic/Vector.pm
branches/upstream/libstatistics-basic-perl/current/Changes
branches/upstream/libstatistics-basic-perl/current/MANIFEST
branches/upstream/libstatistics-basic-perl/current/META.yml
branches/upstream/libstatistics-basic-perl/current/Makefile.PL
branches/upstream/libstatistics-basic-perl/current/lib/Statistics/Basic.pod
Modified: branches/upstream/libstatistics-basic-perl/current/Basic.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libstatistics-basic-perl/current/Basic.pm?rev=36648&op=diff
==============================================================================
--- branches/upstream/libstatistics-basic-perl/current/Basic.pm (original)
+++ branches/upstream/libstatistics-basic-perl/current/Basic.pm Fri May 29 15:04:47 2009
@@ -17,7 +17,7 @@
use Statistics::Basic::Vector;
use Statistics::Basic::ComputedVector;
-our $VERSION = 1.6007;
+our $VERSION = '1.6500';
our $fmt = new Number::Format;
$ENV{DEBUG} ||= 0;
@@ -39,6 +39,7 @@
covariance cov
correlation cor corr
leastsquarefit LSF lsf
+ handle_missing_values
));
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
@@ -57,6 +58,24 @@
sub correlation { my $r = eval { Statistics::Basic::Correlation->new( $_[0],$_[1] ) }; croak $@ if $@; $r}
sub leastsquarefit { my $r = eval { Statistics::Basic::LeastSquareFit->new( $_[0],$_[1] ) }; croak $@ if $@; $r}
+sub handle_missing_values {
+ my ($v1,$v2) = @_;
+ my $v3 = eval { computed($v1) }; croak $@ if $@;
+ my $v4 = eval { computed($v2) }; croak $@ if $@;
+
+ $v3->set_filter(sub {
+ my @v = $v2->query;
+ map {$_[$_]} grep { defined $v[$_] and defined $_[$_] } 0 .. $#_;
+ });
+
+ $v4->set_filter(sub {
+ my @v = $v1->query;
+ map {$_[$_]} grep { defined $v[$_] and defined $_[$_] } 0 .. $#_;
+ });
+
+ return ($v3,$v4);
+}
+
*average = *mean;
*avg = *mean;
*var = *variance;
Modified: branches/upstream/libstatistics-basic-perl/current/Basic/Vector.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libstatistics-basic-perl/current/Basic/Vector.pm?rev=36648&op=diff
==============================================================================
--- branches/upstream/libstatistics-basic-perl/current/Basic/Vector.pm (original)
+++ branches/upstream/libstatistics-basic-perl/current/Basic/Vector.pm Fri May 29 15:04:47 2009
@@ -15,7 +15,7 @@
'""' => sub {
my $this = $_[0];
local $" = ", ";
- my @r = map { $Statistics::Basic::fmt->format_number($_, $ENV{IPRES}) } $this->query;
+ my @r = map { defined $_ ? $Statistics::Basic::fmt->format_number($_, $ENV{IPRES}) : "_" } $this->query;
$ENV{DEBUG} ? "vector-$this->{tag}:[@r]" : "[@r]";
},
fallback => 1; # tries to do what it would have done if this wasn't present.
Modified: branches/upstream/libstatistics-basic-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libstatistics-basic-perl/current/Changes?rev=36648&op=diff
==============================================================================
--- branches/upstream/libstatistics-basic-perl/current/Changes (original)
+++ branches/upstream/libstatistics-basic-perl/current/Changes Fri May 29 15:04:47 2009
@@ -1,3 +1,7 @@
+1.6500: Fri May 29 07:00:10 EDT 2009
+ - I get asked, "does S::B handle missing values?" quite a lot.
+ - YES IT DOES! (now)
+
1.6007: Sat May 2 07:09:12 EDT 2009
- fixed copyright information on request
- fixed various docbugs
Modified: branches/upstream/libstatistics-basic-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libstatistics-basic-perl/current/MANIFEST?rev=36648&op=diff
==============================================================================
--- branches/upstream/libstatistics-basic-perl/current/MANIFEST (original)
+++ branches/upstream/libstatistics-basic-perl/current/MANIFEST Fri May 29 15:04:47 2009
@@ -1,44 +1,45 @@
-MANIFEST
-Basic.pm
-t/05_load_them.t
-t/07_vector.t
-t/10_mean.t
-t/15_variance.t
-t/15_covariance.t
-t/17_stddev.t
-t/20_correlation.t
-t/20_LSF.t
-Makefile.PL
-Changes
-Basic/Vector.pm
+Basic/ComputedVector.pm
+Basic/Correlation.pm
+Basic/Covariance.pm
+Basic/LeastSquareFit.pm
Basic/Mean.pm
Basic/Median.pm
Basic/Mode.pm
+Basic.pm
+Basic/StdDev.pm
Basic/Variance.pm
-Basic/StdDev.pm
-Basic/Covariance.pm
-Basic/Correlation.pm
-Basic/LeastSquareFit.pm
-t/10_median.t
-t/10_mode.t
-t/53_persistance.t
-t/53_co_persistance.t
-lib/Statistics/Basic.pod
-lib/Statistics/Basic/LeastSquareFit.pod
+Basic/Vector.pm
+Changes
+lib/Statistics/Basic/ComputedVector.pod
lib/Statistics/Basic/Correlation.pod
lib/Statistics/Basic/Covariance.pod
+lib/Statistics/Basic/LeastSquareFit.pod
lib/Statistics/Basic/Mean.pod
lib/Statistics/Basic/Median.pod
lib/Statistics/Basic/Mode.pod
+lib/Statistics/Basic.pod
lib/Statistics/Basic/StdDev.pod
lib/Statistics/Basic/Variance.pod
lib/Statistics/Basic/Vector.pod
+Makefile.PL
+MANIFEST
+README
+t/05_load_them.t
+t/07_vector.t
+t/08_cvec.t
+t/08_filter_outliers.t
+t/10_mean.t
+t/10_median.t
+t/10_mode.t
+t/15_covariance.t
+t/15_variance.t
+t/17_stddev.t
+t/19_combo.t
+t/20_correlation.t
+t/20_LSF.t
+t/53_co_persistance.t
+t/53_persistance.t
t/54_doc_example.t
-t/19_combo.t
-README
-t/08_cvec.t
-Basic/ComputedVector.pm
-t/08_filter_outliers.t
-lib/Statistics/Basic/ComputedVector.pod
t/60_bigfloats.t
+t/75_filtered_missings.t
META.yml Module meta-data (added by MakeMaker)
Modified: branches/upstream/libstatistics-basic-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libstatistics-basic-perl/current/META.yml?rev=36648&op=diff
==============================================================================
--- branches/upstream/libstatistics-basic-perl/current/META.yml (original)
+++ branches/upstream/libstatistics-basic-perl/current/META.yml Fri May 29 15:04:47 2009
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: Statistics-Basic
-version: 1.6007
+version: 1.6500
abstract: ~
author: []
license: LGPL
@@ -11,7 +11,7 @@
ExtUtils::MakeMaker: 0
requires:
Number::Format: 1.61
- perl: 5.008
+ perl: 5.008001
Scalar::Util: 0
resources:
repository: http://github.com/jettero/statistics--basic
Modified: branches/upstream/libstatistics-basic-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libstatistics-basic-perl/current/Makefile.PL?rev=36648&op=diff
==============================================================================
--- branches/upstream/libstatistics-basic-perl/current/Makefile.PL (original)
+++ branches/upstream/libstatistics-basic-perl/current/Makefile.PL Fri May 29 15:04:47 2009
@@ -15,7 +15,7 @@
},
($ExtUtils::MakeMaker::VERSION ge '6.48'?
- (MIN_PERL_VERSION => 5.008,
+ (MIN_PERL_VERSION => 5.008001,
META_MERGE => {
keywords => ['stats','statistics', 'mean', 'average', 'correlation'],
resources=> {
Modified: branches/upstream/libstatistics-basic-perl/current/lib/Statistics/Basic.pod
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libstatistics-basic-perl/current/lib/Statistics/Basic.pod?rev=36648&op=diff
==============================================================================
--- branches/upstream/libstatistics-basic-perl/current/lib/Statistics/Basic.pod (original)
+++ branches/upstream/libstatistics-basic-perl/current/lib/Statistics/Basic.pod Fri May 29 15:04:47 2009
@@ -158,7 +158,13 @@
=item C<computed()>
-Argument must be a blessed vector object.
+Argument must be a blessed vector object. See the section on
+L<COMPUTED VECTORS> for more information on this.
+
+=item C<handle_missing_values()>
+
+This function should be two vector arguments. See the section on
+L<MISSING VALUES> for further information on this function.
=back
@@ -191,6 +197,52 @@
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 15]
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
+
+=head1 MISSING VALUES
+
+Something I get asked about quite a lot is, "can S::B handle missing values?"
+The answer used to be, "that really depends on your data set, use
+L<grep|perlfunc/grep>," but I recently decided (5/29/09) that it was time to
+just go ahead and add this feature.
+
+Strictly speaking, the feature was already there. You simply need to add a
+couple filters to your data. See C<t/75_filtered_missings.t> for the test
+example.
+
+This is what people usually mean when they ask if S::B can "handle" missing
+data:
+
+ my $v1 = vector(1,2,3,undef,4);
+ my $v2 = vector(1,2,3,4, undef);
+ my $v3 = computed($v1);
+ my $v4 = computed($v2);
+
+ $v3->set_filter(sub {
+ my @v = $v2->query;
+ map {$_[$_]} grep { defined $v[$_] and defined $_[$_] } 0 .. $#_;
+ });
+
+ $v4->set_filter(sub {
+ my @v = $v1->query;
+ map {$_[$_]} grep { defined $v[$_] and defined $_[$_] } 0 .. $#_;
+ });
+
+But I've made it even simpler. Since this is such a common request, I have
+provided a helper function to build the filters automatically:
+
+ my $v1 = vector(1,2,3,undef,4);
+ my $v2 = vector(1,2,3,4, undef);
+
+ my ($f1, $f2) = filter_missing_values($v1, $v2);
+
+Note that in practice, you would still manipulate (insert, and shift) C<$v1> and
+C<$v2>, I<not> the computed vectors! But for correlations and the like, you
+would use C<$f1> and C<$f2>.
+
+ $v1->insert(5);
+ $v2->insert(6);
+
+ my $correlation = correlation($f1, $f2);
=head1 REUSE DETAILS
Added: branches/upstream/libstatistics-basic-perl/current/t/75_filtered_missings.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libstatistics-basic-perl/current/t/75_filtered_missings.t?rev=36648&op=file
==============================================================================
--- branches/upstream/libstatistics-basic-perl/current/t/75_filtered_missings.t (added)
+++ branches/upstream/libstatistics-basic-perl/current/t/75_filtered_missings.t Fri May 29 15:04:47 2009
@@ -1,0 +1,37 @@
+
+use Test;
+use Statistics::Basic qw(:all);
+
+plan tests => 8;
+
+$SIG{__WARN__} = sub { die " FATAL WARNING: $_[0] " };
+
+my $v1 = vector(1,2,3,undef,4);
+ok("$v1", "[1, 2, 3, _, 4]");
+
+my $v2 = vector(1,2,3,4, undef);
+ok("$v2", "[1, 2, 3, 4, _]");
+
+my $v3 = computed($v1);
+my $v4 = computed($v2);
+
+ok("$v3", "[1, 2, 3, _, 4]");
+ok("$v4", "[1, 2, 3, 4, _]");
+
+$v3->set_filter(sub {
+ my @v = $v2->query;
+ map {$_[$_]} grep { defined $v[$_] and defined $_[$_] } 0 .. $#_;
+});
+
+$v4->set_filter(sub {
+ my @v = $v1->query;
+ map {$_[$_]} grep { defined $v[$_] and defined $_[$_] } 0 .. $#_;
+});
+
+ok("$v3", "[1, 2, 3]");
+ok("$v4", "[1, 2, 3]");
+
+my ($v5, $v6) = handle_missing_values($v1, $v2);
+
+ok("$v5", "$v3");
+ok("$v6", "$v4");
More information about the Pkg-perl-cvs-commits
mailing list