Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I have a set of test scores with dates that I can graph. I would like to be able to include a trendline on the graph. What I wrote is not quite right -- the line just follows the original - it's not straight. I would be extremely grateful for any help.

I calculated the slope thus (some subs not included):

#---------------------------------------------------------- # 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);

And the graphing script does this:

my @data = ([@alldates], [@allScores], [@trendline] ); my $mygraph = GD::Graph::lines->new(600, 300); $mygraph->set( x_label => 'Assessments', y_label => 'Score', title => 'Progress Monitoring Report for '.$student, y_max_value => 100, y_min_value => 0, show_values => 1, # Show the grid long_ticks => 1, #line_types => [1, 2, 4], line_types => [1], # Set the thickness of line line_width => 4, # Set colors for datasets #dclrs => ['blue', 'green', 'red'], dclrs => ['blue','red'], ) or warn $mygraph->error; $mygraph->set_legend_font(GD::gdMediumBoldFont); my $myimage = $mygraph->plot(\@data) or die $mygraph->error; print "Content-type: image/png\n\n"; print $myimage->png;

In reply to How to graph trendline by djones

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [M4ver1k]: Anyone have time to help me with something? I've made a thread here - https://www. node_id=1209704
    [choroba]: 1. Learn to link: [id://1209704]Strings/Numbers aren't equating properly

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (4)
    As of 2018-02-22 00:25 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (288 votes). Check out past polls.