Learn R Programming

Rfast (version 1.7.3)

Covariance and correlation matrix: Fast covariance and correlation matrix calculation

Description

Fast covariance and correlation matrix calculation.

Usage

cova(x)
cora(x)

Arguments

x
A matrix with data. It has to be matrix, if it is data.frame for example the function does not turn it into a matrix.

Value

The covariance or correlation matrix.

Details

The calculations take place faster than the built-in functions covcor as the number of variables increases. For a few tens of variables This is true if the number of variables is high, say from 500 and above. For less variables, it's better to use the R's built-in function. We found this method in stackoverflow

References

Shabalin, A.A. (2012). Matrix eQTL: Ultra fast eQTL analysis via large matrix operations. Bioinformatics 28(10): 1353-1358.

See Also

colVars, cor, cov

Examples

Run this code
x <-matrix( rnorm( 1000 * 700), ncol = 700 )
system.time( s1 <- cor(x) )
system.time( s2 <- cora(x) )
all.equal(s1, s2)


x <- as.matrix(iris[, 1:4])
system.time( for (i in 1:1000) cova(x) )
system.time( for (i in 1:1000) cov(x) )

Run the code above in your browser using DataLab