#---------------------------------------------------------- # FOR SLOPE #---------------------------------------------------------- my $mean_score = &average(\@allscores); $mean_score= sprintf("%.0f",$mean_score); my $stdev_score = &stdev(\@allscores); $stdev_score= sprintf("%.3f",$stdev_score); my @list_of_x; my @list_of_y; my @list_of_z; my $num_scores = @allscores; # Get list of x # since each date is just ... yeah... 1 my $dates = 1; foreach ($i=0; $i<$num_scores; $i++){ @list_of_x[$i] = ($dates-$mean_score)/$stdev_score; @list_of_x[$i]= sprintf("%.2f",@list_of_x[$i]); $dates++; } # Get list of y foreach ($i=0; $i<$num_scores; $i++){ @list_of_y[$i] = (@allscores[$i]-$mean_score)/$stdev_score; @list_of_y[$i]= sprintf("%.2f",@list_of_y[$i]); } # Get the list of z-scores for($i=0; $i<$num_scores; $i++){ @list_of_z[$i]= (@list_of_x[$i] * @list_of_y[$i]); @list_of_z[$i]= sprintf("%.2f",@list_of_z[$i]); } # add up the z-scores my $sigma = 0; for($i=0; $i<$num_scores; $i++){ $sigma = ($sigma + @list_of_z[$i]); } # get the correlation my $correl = $sigma/($num_scores-1); # get the slope my $stdev_x = &stdev(\@list_of_x); my $stdev_y = &stdev(\@list_of_y); my $slope = $correl * ($stdev_x / $stdev_y); $slope= sprintf("%.2f",$slope); # add slope to each y ... y is each score my @trendline; for($i=0; $i<$num_scores; $i++){ @trendline[$i] = @allscores[$i]+$slope; @trendline[$i] = sprintf("%.4f",@trendline[$i]); } #create the data for transfer to the graph program $trendlineString = join(',',@trendline);