in reply to Re: Re: (jcwren) Re: Still confused
in thread Still confused

Actually, you should compute $number, $sum, and $sqsum (which is the sum of the squares of all of the numbers) as you go and then you can compute standard deviation without having to loop a second time.

I'll omit the details of the calculation since you can probably just look them up in Statistics::Descriptive, though I find deriving the formula is a good way to see if you remember any of your math classes. (:

This standard trick allows you to add numbers to the set (or even remove some) and recalculate the average and stddev without having to even keep the list of numbers around, much less loop through them.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Still confused
by buckaduck (Chaplain) on Apr 11, 2001 at 23:39 UTC
    Oh holy smokes, that works nicely. I looked it up in Statistics::Descriptive and could have kicked myself. My way was pretty trivial and I think easy for anyone to understand. But it's not all that hard to do it your way, and it has significant advantages. Well worth a look.

    Thanks, tye.

    buckaduck