The variance of a set of $n$ binary variables $D = <x_1, \ldots, x_n>$ is $$ {\rm var(D)} = \frac{k(n-k)}{n^2}, $$ where $k$ denotes the number of $1$s in $D$ (see http://capone.mtsu.edu/dwalsh/VBOUND2.pdf).

With Matlab the variance of $<1, 0, 0, 1, 0, 0>$ is 0.2667, while using the above formula the variance is 0.22.

What is the reason for that? Moreover, what is the simplified version of covariance formula between two binary variables?

  • $\begingroup$ The formula is for the population variance, whilst Matlab probably computes the sample variance (with factor $1/(n-1)$). $\endgroup$ – QuantIbex Aug 10 '13 at 17:49

The shortcut formula for the covariance of two binary variables is $(n\,k_{xy}-k_xk_y)/n^2$, where $k_x$ is the number of pairs in which $x=1$, $k_y$ is the number of pairs in which $y=1$, and $k_{xy}$ is the number of pairs in which $x=y=1$.

Both that formula and the formula you gave are usually called "population" formulas. They give the variance (or covariance) of the numbers in the data.

The answer that Matlab gave, and the corresponding answer it would give for the covariance, replace the $n^2$ in the denominator by $n(n-1)$. They are usually called "sample" formulas because they treat the data as a sample from some population and give an unbiased estimate of the variance (or covariance) in that population.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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