Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
use strict; use warnings; # Copyleft moxliukas 2002 # This program outputs some statistical information # about the data that is given in two tab separated # columns, first one being X column, and second one # Y column. unless (@ARGV==1) { print "Usage: $0 data_file\n"; exit (-1); } my (@x, @y, $f); open($f, "<$ARGV[0]"); while(<$f>) { /^(.*)\t(.*)$/; push @x, $1; push @y, $2; } close $f; my $Xn = $#x+1; my $Yn = $#y+1; my @X2 = map { $_ * $_ } @x; my @Y2 = map { $_ * $_ } @y; my (@XY, $Sx, $Sy, $SX2, $SY2, $SXY, $SX_Xv__Y_Yv); for (my $i = 0; $i <= $#x; $i++) { push @XY, $x[$i] * $y[$i]; } foreach my $o (@x) { $Sx += $o; } foreach my $o (@y) { $Sy += $o; } foreach my $o (@X2) { $SX2 += $o; } foreach my $o (@Y2) { $SY2 += $o; } foreach my $o (@XY) { $SXY += $o; } my $MX = $Sx / $Xn; my $MY = $Sy / $Yn; my $VX = ($SX2 * $Xn - $Sx * $Sx) / ($Xn * $Xn); my $VY = ($SY2 * $Yn - $Sy * $Sy) / ($Yn * $Yn); my $SdevX = sqrt($VX); my $SdevY = sqrt($VY); my @Xsort = sort { $a <=> $b } @x; my @Ysort = sort { $a <=> $b } @y; my $q1 = int(.25 * ($Xn + 1)) - 1; my $q2 = int(.5 * ($Xn + 1)) - 1; my $q3 = int(.75 * ($Xn + 1)) - 1; for(my $i = 0; $i <= $#x; $i++) { $SX_Xv__Y_Yv += ($x[$i] - $MX) * ($y[$i] - $MY); } my $cov = $SX_Xv__Y_Yv / $Xn; my $correl = $cov / ($SdevX * $SdevY); my $determ = $correl * $correl; my $slope = ($Xn * $SXY - $Sx * $Sy) / ($Xn * $SX2 - $Sx * $Sx); my $intercept = $MY - $slope * $MX; #--- output ---# print <<EOI; Sums: -------- X: $Sx Y: $Sy X^2: $SX2 Y^2: $SY2 XY: $SXY n: $Xn -------- Mean X: $MX Mean Y: $MY Variance X: $VX Variance Y: $VY St. dev. X: $SdevX St. dev. Y: $SdevY -------- Quartiles -------- Q1 of X: $Xsort[$q1] Q2 of X: $Xsort[$q2] Q3 of X: $Xsort[$q3] Q1 of Y: $Ysort[$q1] Q2 of Y: $Ysort[$q2] Q3 of Y: $Ysort[$q3] -------- Covariance: $cov Linear correlation: $correl Determinance: $determ -------- Linear regression -------- Slope: $slope Intercept: $intercept Y = $intercept + X * ($slope) EOI

In reply to Statistical data analysis by moxliukas

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (3)
    As of 2014-10-26 07:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (152 votes), past polls