Subject: | Problem in least_squares_fit() for specific Y values |
Hi --
I found something puzzling in version 2.4 and 2.6 of
Statistics::Descriptive. When I try to get a linear regression for the
following data:
x y
0 0.74
1.0166 0.74
2.0166 0.74
3.0166 0.74
4.0166 0.74
5.0166 0.74
I get this error: Can't take sqrt of -7.80867e-15 at
/usr/lib/perl5/site_perl/5.005/Statistics/Descriptive.pm line 364 (line
364 in version 2.4; I think the equivalent line in 2.6 is 403). Now I
know that the slope of the line these data represent is pretty boring,
but that's what I have to deal with in the app - sometimes, the y data
are all identical. Normally, the Stats:Desc handles this gracefully by
returning the empty list, and I deal with that in the code. But
everything dies when I come up against this.
Funny thing is, if I replace all the 0.74's with 0.75, say, it works the
way I expect it to - returns the empty list. What's so special about
0.74 that causes this? Any help appreciated. BTW, this happened with
both Perl 5.005_03 (Stats::Desc v 2.4) on Linux, and Active State Perl
5.86 (Stats::Desc 2.6) on XP. And thanks for an overall great module - a
real workhorse in my shop!
Dan Maloney
here are the one-liners I used to test:
perl -MStatistics::Descriptive -e
'$s=Statistics::Descriptive::Full->new();$s->add_data(0.74,0.74,0.74,
0.74,0.74,0.74);
@tmp=$s->least_squares_fit([0,1.0166,2.0166,3.01666,4.0166,5.0166]);
print (join ",", @tmp), "\n";'
perl -MStatistics::Descriptive -e
'$s=Statistics::Descriptive::Full->new();$s->add_data(0.75,0.75,0.75,0.75,0.75,0.75);
@tmp=$s->least_squares_fit([0,1.0166,2.0166,3.0166,4.0166,5.0166]);
print (join ",", @tmp), "\n";'