help-octave
[Top][All Lists]
Advanced

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

var(x) and std(x)


From: Anand V
Subject: var(x) and std(x)
Date: Tue, 12 Nov 2002 07:00:10 -0600

Hi,
  I have a doubt regarding the implementation of variance function var(x) in 
octave.It finds the variance as follows

function y = var(x)

  if (nargin != 1)
    usage ("var (x)");
  endif

  [nr, nc] = size (x);
  if (nr == 0 || nc == 0)
    error ("var: x must not be empty");
  elseif ((nr == 1) && (nc == 1))
    y = 0;
  elseif ((nr == 1) || (nc == 1))
    n = length (x);
    y = (sumsq (x) - sum(x)^2 / n) / (n-1);
  else
    y = (sumsq (x) - sum(x).^2 / nr) / (nr-1);
  endif

endfunction

   It gives variance after averaging over n-1 samples, rather than averaging 
over n samples. for example, if we calculate the variance of 
x = [1,2,3] , it returns the value 1, instead of 2/3..This is because it
finds 2/2 and not 2/3..The same is the case with std(x) also. 
Is it an error or is there any explanation for that?
Please correct me if I am wrong.

Thanks and Regards
Anand


_____________________________________________________________
Kerala's coolest community site ---> http://www.achayans.com

India's fastest growing Search Engine ->
http://www.indianindex.com

India's largest Online Matchmakers -->
http://www.indianalliance.com

_____________________________________________________________
Select your own custom email address for FREE! Get address@hidden w/No Ads, 
6MB, POP & more! http://www.everyone.net/selectmail?campaign=tag



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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