Wacek Kusnierczyk wrote:
>
> 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
>   

except for that i seem to have pasted wrong output.

    set.seed(0)
    x = matrix(rnorm(4), 2, 2)

    var(x)
    #           [,1]        [,2]
    # [1,] 1.2627587 0.045585801
    # [2,] 0.0455858 0.001645655

    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])))
    #           [,1]        [,2]
    # [1,] 1.2627587 0.045585801
    # [2,] 0.0455858 0.001645655

vQ

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to