Skip Menu |
 

This queue is for tickets about the Statistics-Descriptive CPAN distribution.

Report information
The Basics
Id: 11308
Status: resolved
Priority: 0/
Queue: Statistics-Descriptive

People
Owner: Nobody in particular
Requestors: daniel.maloney [...] bms.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 2.4
  • 2.6
Fixed in: (no value)



Subject: Problem in least_squares_fit() for specific Y values
Download (untitled) / with headers
text/plain 1.6k
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";'
On Tue Feb 01 11:13:21 2005, guest wrote: Show quoted text
> 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";'
This is caused by the fact that 0.74 is not easily expressible as a binary fraction and as a resultt here are rounding errors that cause the calculation to be inaccurate. On the other hand, 0.75 is 3/4 which is 3/(2**2) and so is more accurately calculated. I don't see a lot that we can do about it. Regards, Shlomi Fish
Resolving.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.