[scilab-Users] newbie question-probably an easy answer!

Mathieu Dubois mathieu.dubois at limsi.fr
Thu Aug 11 09:12:01 CEST 2011


Hello,

Le 10/08/2011 19:40, bazcor a écrit :
> Hello and thanks for reading this, I've been playing around with
> scilab,(nothing very deep,just starting out).
>
> The problem I have that needs explanation is this
> :-
> -->a=[2,3,4,5,5];
> -->b=[2,3,4,5]
> -->fre=[1,1,1,2]
> -->variance(a) ans= 1.7 //ok here
> -->variancef(b,fre) ans= 1.7 // also ok
> -->stdev(a) ans = 1.3038405 //good to here
> -->stdevf(b,fre) ans = 0 //?? thought it should be the above answer!
>
> I'll just bet there's a easy answer to this, but I'm stumped. Any comment
> gratefully received.
>
I think you're right: the result should be similar and they are not.

Playing a bit with your example, I came to the conclusion that there is 
a bug stdevf function.
More precisely from the file SCI/modules/statistics/macros/stdevf.sci 
lines 56-60:
   if size(x,1)==1 then
     s=0*sum((y.^2).*fre,o)
   else
     s=sqrt(sum((y.^2).*fre,o)./(sum(fre,o)-1));
   end

The purpose of the test is clear: if x contains only one element, the 
standard deviation is null.
Two points here:
  - I think that the test is wrong: it should test size(x,o)==1 to take 
into account the orientation specified by the user
  - The test can be done before (for instance line 44: if size(x,o)==1 
then s=0; return, end)

Therefore the end of the function becomes:
   s=sqrt(sum((y.^2).*fre,o)./(sum(fre,o)-1));

Attached is the diff file and some work on your example.
AFAI, it works.
Can someone (scilab developers) confirm this?

HTH,
Mathieu

> --
> View this message in context: http://mailinglists.scilab.org/newbie-question-probably-an-easy-answer-tp3243360p3243360.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stdevf.sci.patch
Type: text/x-patch
Size: 239 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20110811/22c63615/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_bazcor.sce
Type: application/x-scilab
Size: 728 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20110811/22c63615/attachment-0001.bin>


More information about the users mailing list