sparseCov: Sparse covariance/correlation, cosine similarity or Euclidean...

Description Usage Arguments Value Author(s) References Examples

Description

Calcultion of matrices of various similarity/distances, which takes use of matrix multiplication. Note: the comparisons are made between columns, similar to the cor function, and unlike the dist function which compares between rows.

See the timing vignette for comparison of the performance of functions against standard dense calculations.

Usage

1
2
3
sparseCov(X, Y = NULL, XtX = NULL)
sparseCosine(X, Y = NULL, XtX = NULL)
sparseEuclid(X, Y = NULL, XtX = NULL)

Arguments

X

a matrix X

Y

optional: a matrix Y, in which case columns of X will be compared to columns of Y. The resulting matrix will be ncol(X) by ncol(Y).

XtX

optional: if not using Y, supplying XtX, the crossproduct of X with itself, will be used rather than recalculating this in the function.

Value

A list with the covariance and correlation matrix of X, or X and Y; The cosine similarity matrix of X, or X and Y; The Euclidean distances matrix of X, or X and Y.

Author(s)

Michael Love

References

The sparseCov function was developed from a discussion here: http://stackoverflow.com/questions/5888287/running-cor-or-any-variant-over-a-sparse-matrix-in-r

Examples

1
2
3
4
5
6
sds1 <- simulateSparseDataSet(100, c(5,5))
sds2 <- simulateSparseDataSet(100, c(2,2))
res <- sparseCov(sparseData(sds1))
res$cor
resxy <- sparseCov(sparseData(sds1),sparseData(sds2))
resxy$cor

mikelove/SparseData documentation built on May 22, 2019, 10:52 p.m.