This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: Collecting statistics for time dependent data?
- From: John Lamb <J dot D dot Lamb at btinternet dot com>
- To: gsl-discuss at sources dot redhat dot com
- Date: Thu, 09 Dec 2004 19:30:46 +0000
- Subject: Re: Collecting statistics for time dependent data?
- References: <1102593229.8374.16.camel@pcgiamma.vki.ac.be>
Raimondo Giammanco wrote:
Hello,
I was wondering if there is a way to compute "running" statistics with
gsl.
Yes you can do it, but there's nothing in GSL that does it and its eay
enough that you don't need GSL. Something like (untested)
double update_mean( double* mean, int* n, double x ){
if( *n == 1 )
*mean = x;
else
*mean = (1 - (double)1 / *n ) * *mean + x / n;
}
will work and you can derive a similar method for updating the variance
using the usual textbook formula.
var[x] = (1/n) sum x^2_i - mean(x)^2
I don't know if there is a method that avoids the rounding errors. I
don't know why so many textbooks repeat this formula without the
slightest warning that it can go so badly wrong.
--
JDL