Dear Monks,


I'm concerned that I'm going to get myself in a pickle with this. Please can someone point me in the right direction? I want to get the sub to return distance from the trend line (by y axis) as well as whether each point is above or below the trend line.
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 = -1; 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){ #chomp; $number_of_elements_in_array++; my $x_point = $_; # print "\n$array_of_y_values[$number_of_elements_in_array] > $inte +rcept + ($x_point * $slope)\n\n"; if (defined($x_point)){ if ($array_of_y_values[$number_of_elements_in_array] > $intercep +t + ($x_point * $slope)){ #points are above the trend line #### my $Distance_above_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_value +s[$number_of_elements_in_array]); } elsif ($array_of_y_values[$number_of_elements_in_array] < $inter +cept + ($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_value +s[$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; }

In reply to returning distance from trendline by Win

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.