Skip to content
Prev 174504 / 398506 Next

variance/mean

rkevinburton at charter.net wrote:
you may well be ignorant about how var works with matrices, but this
does not mean it's your fault.  the documentation is typically cryptical.

when you apply var to a single matrix, it will compute covariances
between its columns rather than the overall variance:

    set.seed(0)
    x = matrix(rnorm(4), 2, 2)
   
    var(x)
    #                [,1]     [,2]
    # [1,]  1.2629543 1.329799
    # [2,] -0.3262334 1.272429

    matrix(nrow=2, ncol=2, byrow=TRUE, c(
       cov(x[,1], x[,1]), cov(x[,1], x[,2]),
       cov(x[,2], x[,1]), cov(x[,2], x[,2])))
      
vQ