fastcov2 {dipsaus}  R Documentation 
Speed up covariance calculation for large matrices. The
default behavior is similar cov
. Please remove any NA
prior to calculation.
fastcov2(x, y = NULL, col1, col2, df)
x 
a numeric vector, matrix or data frame; a matrix is highly recommended to maximize the performance 
y 
NULL (default) or a vector, matrix or data frame with compatible
dimensions to x; the default is equivalent to 
col1 
integers indicating the subset (columns) of 
col2 
integers indicating the subset (columns) of 
df 
a scalar indicating the degrees of freedom; default is

A covariance matrix of x
and y
. Note that there is no
NA
handling. Any missing values will lead to NA
in the
resulting covariance matrices.
x < matrix(rnorm(400), nrow = 100)
# Call `cov(x)` to compare
fastcov2(x)
# Calculate covariance of subsets
fastcov2(x, col1 = 1, col2 = 1:2)
# Speed comparison
x < matrix(rnorm(100000), nrow = 1000)
microbenchmark::microbenchmark(
fastcov2 = {
fastcov2(x, col1 = 1:50, col2 = 51:100)
},
cov = {
cov(x[,1:50], x[,51:100])
},
unit = 'ms', times = 10
)