Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

corrMatOrder

Reorder a correlation matrix.


Description

Draw rectangle(s) around the chart of corrrlation matrix based on the number of each cluster's members.

Usage

corrMatOrder(
  corr,
  order = c("AOE", "FPC", "hclust", "alphabet"),
  hclust.method = c("complete", "ward", "ward.D", "ward.D2", "single", "average",
    "mcquitty", "median", "centroid")
)

Arguments

corr

Correlation matrix to reorder.

order

Character, the ordering method for the correlation matrix.

  • "AOE" for the angular order of the eigenvectors. It is calculated from the order of the angles, a_i:

    a_i = arctan (e_{i2} / e_{i1}), if e_{i1} > 0

    a_i = arctan (e_{i2} / e_{i1}) + π, otherwise.

    where e_1 and e_2 are the largest two eigenvalues of matrix corr. See Michael Friendly (2002) for details.

  • "FPC" for the first principal component order.

  • "hclust" for hierarchical clustering order.

  • "alphabet" for alphabetical order.

hclust.method

Character, the agglomeration method to be used when order is hclust. This should be one of "ward", "ward.D", "ward.D2", "single", "complete", "average", "mcquitty", "median" or "centroid".

Value

Returns a single permutation vector.

Author(s)

Taiyun Wei

See Also

Package seriation offers more methods to reorder matrices, such as ARSA, BBURCG, BBWRCG, MDS, TSP, Chen and so forth.

Examples

M <- cor(mtcars)

(order.AOE <- corrMatOrder(M, order = "AOE"))
(order.FPC <- corrMatOrder(M, order = "FPC"))
(order.hc <- corrMatOrder(M, order = "hclust"))
(order.hc2 <- corrMatOrder(M, order = "hclust", hclust.method = "ward.D"))

M.AOE <- M[order.AOE,order.AOE]
M.FPC <- M[order.FPC,order.FPC]
M.hc  <- M[order.hc, order.hc]
M.hc2 <- M[order.hc2,order.hc2]



par(ask = TRUE)
corrplot(M)
corrplot(M.AOE)
corrplot(M.FPC)
corrplot(M.hc)

corrplot(M.hc)
corrRect.hclust(corr = M.hc, k = 2)

corrplot(M.hc)
corrRect.hclust(corr = M.hc, k = 3)

corrplot(M.hc2)
corrRect.hclust(M.hc2, k = 2, method = "ward.D")

corrplot

Visualization of a Correlation Matrix

v0.88
MIT + file LICENSE
Authors
Taiyun Wei [cre, aut], Viliam Simko [aut], Michael Levy [ctb], Yihui Xie [ctb], Yan Jin [ctb], Jeff Zemla [ctb], Moritz Freidank [ctb], Jun Cai [ctb], Tomas Protivinsky [ctb]
Initial release
2021-05-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.