[R] computing the variance

2005-12-05 Thread Wang Tian Hua
hi, when i was computing the variance of a simple vector, i found unexpect result. not sure whether it is a bug. var(c(1,2,3)) [1] 1 #which should be 2/3. var(c(1,2,3,4,5)) [1] 2.5 #which should be 10/5=2 it seems to me that the program uses (sample size -1) instead of sample size at the

Re: [R] computing the variance

2005-12-05 Thread Romain Francois
Le 05.12.2005 09:53, Wang Tian Hua a écrit : hi, when i was computing the variance of a simple vector, i found unexpect result. not sure whether it is a bug. var(c(1,2,3)) [1] 1 #which should be 2/3. var(c(1,2,3,4,5)) [1] 2.5 #which should be 10/5=2 it seems to me that the program uses

Re: [R] computing the variance

2005-12-05 Thread Uwe Ligges
Wang Tian Hua wrote: hi, when i was computing the variance of a simple vector, i found unexpect result. not sure whether it is a bug. Not a bug! ?var: The denominator n - 1 is used which gives an unbiased estimator of the (co)variance for i.i.d. observations. var(c(1,2,3)) [1] 1

Re: [R] computing the variance

2005-12-05 Thread Kristel Joossens
Just redefine the var(x) as sum((x-mean(x))^2)/length(x)? Or straightforward just use var(x)*(1-1/length(x)) As you already mentioned var(x) is now defined by sum((x-mean(x))^2)/(length(x)-1) which is an *unbaised* estimtor of COV. While sum((x-mean(x))^2)/length(x) is a *biased* estimator with