covarMatrix

Syntax

covarMatrix(X)

Arguments

X is a matrix.

Details

Return a covariance matrix, where the (i, j) entry is the covariance between Xi and Xj.

Note:

  • NULL values are converted to 0 by default in covarMatrix, whereas NULL values are ignored in functions covar and cross/pcross.

  • For a matrix without NULL values, the result of covarMatrix is equivalent to cross(covar, X) but with significant performance improvement.

Examples

$ m = matrix(1 3 2, 2 4 3, 3 1 1, 4 2 4);
$ covarMatrix(m)

#0

#1

#2

#3

1

1

-1

-1

1

1

-1

-1

-1

-1

1.333333333333333

0.666666666666667

-1

-1

0.666666666666667

1.333333333333333

$ a = rand(1.0, 30000000).reshape(10000:3000)
$ a.rename!("s" + string(1..3000))
$ timer covarMatrix(a)
Time elapsed: 2927.264 ms
$ timer pcross(covar, a)
Time elapsed: 29484.85 ms

Related function: corrMatrix