Skip to contents

Given a correlation matrix \(R\), this function discovers the block-diagonal structure by thresholding the absolute values of the entries of the correlation matrix at \(c\). We create an adjacency matrix with the elements being 1 if and only if the corresponding member of the correlation matrix has an absolute value \(\ge c\). This is equivalent to performing a single linkage hierarchical clustering on the variables, with the distance matrix given by \(1 - |R|\) and cutting the tree at height \(1-c\).

Usage

block_diag(R, c, fig = FALSE)

Arguments

R

a \(p \times p\) correlation matrix

c

a threshold

fig

a logical input; if TRUE, plots R, the adjacency matrix obtained by thresholding R, and the undirected graph corresponding to the adjacency matrix; default value is FALSE

Value

A \(p\) length integer vector whose \(i^{th}\) element denotes the group \(i^{th}\) variable belongs to. If fig = TRUE, returns the plots for R, the adjacency matrix obtained by thresholding R, and the undirected graph corresponding to the adjacency matrix.

Examples

# Simulates a 10 x 5 X from N(0, I)
set.seed(1)
X <- matrix(rnorm(50), 10, 5)
# Compute the correlation matrix of X.
corX <- cor(X)
# Compute the block diagonal structure at c=0.5
block_diag(R=corX, c=0.5)
#> [1] 1 1 1 2 3