Subject: | division by zero when the regression has no error |
I tried to regress the function y = 2x + 5.
The input is simple:
$reg->include( 9, [ 1.0, 2 ] );
$reg->include( 13, [ 1.0, 4 ] );
$reg->include( 17, [ 1.0, 6 ] );
It reports error:
Illegal division by zero at .../Regression.pm line 438
This line of code is:
printf "%7.2f", ($theta->[$i]/$standarderrors[$i]);
It's clear that $standarderrors[$i] is 0 (a perfect regression).
therefore we got the 'division by zero' error.
I made a quick fix:
printf "%7.2f", $standarderrors[$i] ? ($theta->[$i]/$standarderrors[$i])
: 0;