sub correlation { my( $x_ref, $y_ref ) = @_; my @x_values = @$x_ref; my @y_values = @$y_ref; my $output = "output_test.txt"; open OUTPUT_TEST, ">$output" or die "can't write $output - $!"; print OUTPUT_TEST Dumper ($x_ref, $y_ref); close OUTPUT_TEST; my $lfit = Statistics::LineFit->new(); $lfit->setData( $x_ref, $y_ref ); my( $intercept, $slope ) = $lfit->coefficients(); my $rSquared = $lfit->rSquared(); my $hashref = { a => $intercept, b => $slope, c => $rSquared }; my( @x_values_for_points_above_the_trend_line, @y_values_for_points_above_the_trend_line, @distances_above_the_trend_line, @x_values_for_points_below_the_trend_line, @y_values_for_points_below_the_trend_line, @distances_below_the_trend_line, @x_values_for_points_on_the_trend_line, @y_values_for_points_on_the_trend_line, ); for ( 0 .. $#x_values ) { my( $x, $y ) = ( $x_values[$_], $y_values[$_] ); my $fx = $intercept + ( $x * $slope ); if ( $y > $fx ) { push @x_values_for_points_above_the_trend_line, $x; push @y_values_for_points_above_the_trend_line, $y; push @distances_above_trend_line, $y - $fx; } elsif ( $y < $fx ) { push @x_values_for_points_below_the_trend_line, $x; push @y_values_for_points_below_the_trend_line, $y; push @distances_below_trend_line, $fx - $y; } else { push @x_values_for_points_on_the_trend_line, $x; push @y_values_for_points_on_the_trend_line, $y; } } return( $hashref, \@x_values_for_points_above_the_trend_line, \@y_values_for_points_above_the_trend_line, \@distances_above_the_trend_line, \@x_values_for_points_below_the_trend_line, \@y_values_for_points_below_the_trend_line, \@distances_below_the_trend_line, \@x_values_for_points_on_the_trend_line, \@y_values_for_points_on_the_trend_line, ); }