help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Different result between Octave and GSL (Gnu Scientific Library) C f


From: Markus Mützel
Subject: Re: Different result between Octave and GSL (Gnu Scientific Library) C function call
Date: Fri, 1 Jan 2021 11:23:02 +0100

Am 01. Januar 2021 um 07:24 Uhr schrieb "Tallis Huther da Costa":
> >> gsl_stats_wvariance_test_c
> Hello World has 0 input arguments and 0 output arguments.
> n: 11
> ans =  1.7643
> 
> As you can see, the answer is 1.7643.
> 
> Now, from the function's documentation:
> 
> So, I wrote this little Octave script to confirm that the call was correct:
> data = [0 2 2 3 1 5 2.5 7 3 3.9 1.1];
> _mean = mean (data);
> stride = 1;
> w = [2 20 1.8 3 4 5.4 4.5 1.2 30 1.9 10.1];
> wstride = 1;
> n = numel (data);
> expected = (sum (w) / ((sum (w))^2 - sum (w .^ 2))) * sum (w .* ((data - 
> _mean) .^ 2));
> 
> The result was:
> expected =  1.8427
 
Looking at the definition of the weighted variance as used by gsl, the 
*weighted* mean has to be used in its calculation.
Correcting for that gives the same result in Octave as the one you observed 
when using the gsl function:
data = [0 2 2 3 1 5 2.5 7 3 3.9 1.1];
w = [2 20 1.8 3 4 5.4 4.5 1.2 30 1.9 10.1];
weighted_mean = sum (w .* data) / sum (w);
expected = ((sum (w) / ((sum (w))^2 - sum (w .^ 2))) * sum (w .* ((data - 
weighted_mean) .^ 2));

>> expected
expected =  1.7643

HTH,
Markus



reply via email to

[Prev in Thread] Current Thread [Next in Thread]