I will risk the ridicule of answering to a 15 5 year old thread for the sake of adding one more method of calculating basic descriptive statistics. And this is quite different from what anyone with basic engineering or CS background is used to, i.e. loop over your numbers to calculate their sum, divide by their count to get the average and having the average loop again over your numbers in order to calculate standard deviation. Apart from looping twice, one also has to keep the numbers in memory until the stats are calculated.

Apparently there is another way to do it which, in my opinion, should have been the primary method tought from elementary schools to university. This of course is an online version which calculates the stats as new data comes in. There is no need to store numbers in memory. And stats are updated when a new data point arrives without the need to loop-twice over the WHOLE array of data. The maths are very simple and were put together by BP Welford in the 60's who also devised a way to avoid cumulative numerical accuracy errors.

Two modules I have discovered so far in CPAN for doing this kind of statistics calculations:

So, exactly the same functionality without the need to remember incoming data history in possibly gigabyte-long arrays and looping over it twice from the beginning once a new data point arrives.


In reply to Re: Statistic in Perl(Using Subroutines) by bliako
in thread Statistic in Perl(Using Subroutines) by stamp1982

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.