Calculates the euclidean distances between the rows of the correlation matrix of the columns of 'x'.

tgs_cor_dist(x, pairwise.complete.obs = FALSE, spearman = FALSE)

Arguments

x

numeric matrix or data frame

pairwise.complete.obs

see 'tgs_cor' documentation

spearman

if 'TRUE' Spearman correlation is computed, otherwise Pearson

Value

An object of class 'dist' with the distances between the columns of 'x', similar to the output of 'tgs_dist'.

Details

'tgs_cor_dist(x, pairwise.complete.obs, spearman)' returns the same distances as 'tgs_dist(tgs_cor(x, pairwise.complete.obs = pairwise.complete.obs, spearman = spearman))' up to rounding errors, for well-conditioned data. (When the columns of 'x' have offsets that are large relative to their spread, 'tgs_cor' loses precision while 'tgs_cor_dist', which centers the columns first, does not, so the two differ.)

When 'x' has much fewer rows (G) than columns (N), 'tgs_cor_dist' does not compute the NxN correlation matrix. Instead it maps each column of 'x' to a point in G dimensions, such that the euclidean distances between the points equal the distances between the rows of the correlation matrix, and passes these points to 'tgs_dist'. This takes time proportional to G^3 + N^2 x G (an eigendecomposition of a GxG matrix and the distances) instead of N^2 x G + N^3, and is used when G < N / 3 with BLAS ('tgs_use.blas') and G < N / 2 without, which is where it was measured to be faster.

It is also used only when all the values of 'x' are finite and no column of 'x' is constant. Otherwise 'tgs_cor_dist' returns 'tgs_dist(tgs_cor(...))'.

See also

Examples

# \donttest{
# Note: all the available CPU cores might be used

set.seed(seed = 0)
m <- matrix(rnorm(100 * 2000), nrow = 100)
d <- tgs_cor_dist(m)
hc <- hclust(d)
# }