5
$\begingroup$

I always thought I understood the concept of variance, but this one confuses me.

$ \begin{eqnarray} X & := & (1, 2, 3)\\ E(X) & = & (1 + 2 + 3) / 3 = 2\\ Var(X) & = & Cov(X, X) = E((X - E(X))^2)\\ & = & E((-1, 0, 1)^2)\\ & = & E(1,0,1)\\ & = & 2/3 \end{eqnarray} $

But R tells me that

> var(c(1,2,3))
[1] 1

Which part of my calculation is wrong?

$\endgroup$
2
  • 3
    $\begingroup$ You gave the formula for population variance. Sample variance is scaled by a factor of $\frac{n}{n-1}$, which adjusts for the fact that the sample is closer (in squared-deviation sense) to the sample mean than it is to the population mean; this fact imposes a downward bias on $n$-denominator sample variance estimates. As such, the unbiased version of sample variance is used very widely. see wikipedia. So R's answer will be 3/2 times as big as if you just apply the population-variance definition to a sample. $\endgroup$
    – Glen_b
    Sep 1, 2013 at 23:59
  • 2
    $\begingroup$ To clarify - your calculation isn't exactly wrong, since it's perfectly valid to use that for a sample variance -- but the usual convention is to apply the $n-1$ denominator for a sample variance. $\endgroup$
    – Glen_b
    Sep 3, 2013 at 0:31

1 Answer 1

10
$\begingroup$

In the details of ?var we find:

The denominator n - 1 is used which gives an unbiased estimator of the (co)variance for i.i.d. observations.

so you should have $2/2=1$ instead. See here for some more details.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.