groupSimilarityMatrix {MsFeatures}R Documentation

Group rows of a diagonal matrix using a threshold

Description

This function groups elements (rows or columns) of a diagonal matrix, such as a pairwise correlation matrix or similarity matrix, with a value >= threshold. This creates clusters of elements in which all elements have a value >= threshold with any other element in that cluster. On a correlation matrix (such as created with cor) it will generate small clusters of highly correlated elements. Note however that single elements in one cluster could also have a correlation >= threshold to another element in another cluster. The average similarity to its own cluster will however be higher to that of the other.

Usage

groupSimilarityMatrix(x, threshold = 0.9, full = TRUE, ...)

Arguments

x

symmetrix numeric matrix.

threshold

numeric(1) above which rows in x should be grouped.

full

logical(1) whether the full matrix should be considered, or just the upper triangular matrix (including the diagonal).

...

ignored.

Details

The algorithm is defined as follows:

This ensures that groups are defined in which all elements have a correlation >= threshold with each other and the correlation between members of the same group is maximized.

Value

integer same length than nrow(x), grouped elements (rows) defined by the same value.

Author(s)

Johannes Rainer

See Also

Other grouping operations: groupClosest(), groupConsecutive()

Examples


x <- rbind(
    c(1, 0.9, 0.6, 0.8, 0.5),
    c(0.9, 1, 0.7, 0.92, 0.8),
    c(0.6, 0.7, 1, 0.91, 0.7),
    c(0.8, 0.92, 0.91, 1, 0.9),
    c(0.5, 0.8, 0.7, 0.9, 1)
    )

groupSimilarityMatrix(x, threshold = 0.9)

groupSimilarityMatrix(x, threshold = 0.1)

## Add also a correlation between 3 and 2
x[2, 3] <- 0.9
x[3, 2] <- 0.9
x
groupSimilarityMatrix(x, threshold = 0.9)

## Add a higher correlation between 4 and 5
x[4, 5] <- 0.99
x[5, 4] <- 0.99
x
groupSimilarityMatrix(x, threshold = 0.9)

## Increase correlation between 2 and 3
x[2, 3] <- 0.92
x[3, 2] <- 0.92
x
groupSimilarityMatrix(x, threshold = 0.9) ## Don't break previous cluster!

[Package MsFeatures version 1.0.0 Index]