Win has asked for the wisdom of the Perl Monks concerning the following question:
sub correlation { my ($x_ref, $y_ref) = @_; my @array_of_x_values = @$x_ref; my @array_of_y_values = @$y_ref; my $output = "output_test.txt"; open (OUTPUT_TEST, ">$output"); print OUTPUT_TEST Dumper ($x_ref, $y_ref); #print Dumper length($x_ref); #print Dumper length($y_ref); 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 $number_of_elements_in_array = 0; my @x_values_for_points_above_the_trend_line; my @y_values_for_points_above_the_trend_line; my @x_values_for_points_below_the_trend_line; my @y_values_for_points_below_the_trend_line; my @x_values_for_points_on_the_trend_line; my @y_values_for_points_on_the_trend_line; foreach (@array_of_x_values){ $number_of_elements_in_array++; my $x_point = $_; if ($array_of_y_values[$number_of_elements_in_array] > $intercept ++ ($x_point * $slope)){ #points are above the trend line push (@x_values_for_points_above_the_trend_line, $x_point); push (@y_values_for_points_above_the_trend_line, $array_of_y_val +ues[$number_of_elements_in_array]); } elsif ($array_of_y_values[$number_of_elements_in_array] < $interce +pt + ($x_point * $slope)){ #points are below the trend line # $y_values_for_points_below_the_trend_line = push (@x_values_for_points_below_the_trend_line, $x_point); push (@y_values_for_points_below_the_trend_line, $array_of_y_val +ues[$number_of_elements_in_array]); } else { push (@x_values_for_points_on_the_trend_line, $x_point); push (@y_values_for_points_on_the_trend_line, $array_of_y_values +[$number_of_elements_in_array]); } } return $hashref, \@x_values_for_points_above_the_trend_line, \@y_val +ues_for_points_above_the_trend_line, \@x_values_for_points_below_the_ +trend_line, \@y_values_for_points_below_the_trend_line, \@x_values_fo +r_points_on_the_trend_line, \@y_values_for_points_on_the_trend_line; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Positioning in relation to trend line
by GrandFather (Saint) on Dec 05, 2007 at 20:26 UTC | |
|
Re: Positioning in relation to trend line
by moritz (Cardinal) on Dec 05, 2007 at 20:04 UTC |