in reply to Positioning in relation to trend line

Looks pretty bad to me:

I'd rework it to look something like:

sub correlation { my ($x_ref, $y_ref) = @_; my $lfit = Statistics::LineFit->new (); $lfit->setData ($x_ref, $y_ref); my ($intercept, $slope) = $lfit->coefficients (); my $rSquared = $lfit->rSquared (); my %results = (intercept => $intercept, slope => $slope, rSquared => $rSquar +ed); foreach my $index (0 .. $#$x_ref) { my ($xPoint, $yPoint) = ($x_ref->[$index], $y_ref->[$index]); if ($yPoint > $intercept + ($xPoint * $slope)) { push @{$results{above}}, [$xPoint, $yPoint]; } elsif ($yPoint < $intercept + ($xPoint * $slope)) { push @{$results{below}}, [$xPoint, $yPoint]; } else { push @{$results{on}}, [$xPoint, $yPoint]; } } return \%results; }

Perl is environmentally friendly - it saves trees