commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark R. Diggory" <mdigg...@latte.harvard.edu>
Subject Re: [math] error in variance calculation...
Date Wed, 14 May 2003 17:29:08 GMT
My apologies, the subject heading is incorrect, there is no error, but 
WOW, didn't that grab your attention!

-M.

Mark R. Diggory wrote:
> I noticed the following code and was curious (as I do it differently in 
> my packages):
> 
>     public double getVariance() {
>         double xbar = getMean();
>         // FIXME: throw something meaningful if n = 0
>         return (sumsq - xbar*xbar*n)/(n-1);
>     }
> 
> This is equivalent to:
> 
>     public double getVariance() {
>     return (sumsq - (sum*sum / n)) / (n - 1);
>     }
> 
> If ones storing the sum already, its just as easy to use it to calculate 
> the variance rather than grabbing the mean. Is either way 
> computationally better?
> 
> -M.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message