comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Incremental statistics functions
Date: Tue, 27 Jan 2004 03:39:44 GMT
Date: 2004-01-27T03:39:44+00:00	[thread overview]
Message-ID: <44lRb.124968$sv6.677741@attbi_s52> (raw)
In-Reply-To: 86k73e9uzk.fsf@lucretia.kaos

An incremental algorithm for standard deviation is easy.  An incremental
algorithm for variance (as far as I know) is not possibile.  It is my
understanding that standard deviation is really an approximation of variance
that is easier to calculate.

As I recall (it's been a while):
  Variance is the average deviation from the average value of a set of
values.

To find variance you must first find the average of all values.  Then you
must take the absolute value of the average of the difference between the
average and each individual value.

  avg = sum of values / number of values
  variance = (sum over i ( abs( value(i) - avg ) )) / number of values

That "abs" in the formula makes things tough for incremental algorithms.

The standard deviation approximates variance as

  std dev = sqrt( sum of i(( value(i) - avg)^2) )

Which transforms to:

  std dev = sqrt( (avg of value^2) - (avg of value)^2 )

To calculate an incremental standard deviation you keep track of:
   the sum of all values
   the sum of the squares of values
   the number of values
Then do a straight calculation after each new value is added.

I hope this helps,
Steve
(The Duck)


"Mats Karlssohn" <sm5tfx@telia.com> wrote in message
news:86k73e9uzk.fsf@lucretia.kaos...
> Hi
>
> I'm trying to find algorithms to calculate standard-deviation and variance
> _without_ keeping a buffer of the samples. I'm not really shure if I'm
right
> to call them incremental algorithms but I couldn't find a better
expression.
> Basically I don't want to keep a (limited) buffer of samples but would
like
> to add the values one at a time when they are calculated.
>
> Probably I googled bad, since I didn't find anything I could understand.
>
> Any suggestions please?
>
> -- 
> Mats Karlssohn (SM5TFX), sm5tfx@telia.com
> "Without mistakes there is no forgiving, without forgiving there is no
love"





  parent reply	other threads:[~2004-01-27  3:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-26 22:59 OT: Incremental statistics functions Mats Karlssohn
2004-01-27  1:50 ` tmoran
2004-01-27  2:13 ` Stephen Leake
2004-01-27  3:37 ` Robert I. Eachus
2004-01-27  4:56   ` tmoran
2004-01-28  0:22   ` tmoran
2004-01-28 19:56     ` OT: large sums; was " tmoran
2004-01-27  3:39 ` Steve [this message]
2004-01-27 16:22   ` Robert I. Eachus
2004-01-27 15:48 ` Joachim Schr�er
2004-01-28  0:22   ` tmoran
2004-01-27 23:44 ` OT: " Mats Karlssohn
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox