Re: [R] computing the variance

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Mon 05 Dec 2005 - 20:23:43 EST

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 #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 denominator. how can i rectify this?

Simply change it by:

x <- c(1,2,3,4,5)
n <- length(x)
var(x)*(n-1)/n

if you really want it.

Uwe Ligges

> regards,
> tianhua
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Dec 05 20:40:53 2005

This archive was generated by hypermail 2.1.8 : Mon 05 Dec 2005 - 23:30:54 EST