Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I've downloaded a script to draw a correlation matrix using colored circles. This script allows to order variables using PCA, but I'm not sure how it works. The code responsible for ordering is below:

if (order) {
    if(!n==m){
            stop("The matrix must be squre if order is TRUE!")
    }
  x.eigen <- eigen(corr)$vectors[, 1:2]
  e1 <- x.eigen[, 1]
  e2 <- x.eigen[, 2]
  alpha <- ifelse(e1 > 0, atan(e2/e1), atan(e2/e1) + pi)
  corr <- corr[order(alpha), order(alpha)]
}

Question:
What is the interpretation of such ordering and what theory lies behind it?

share|improve this question
I think that You can write this as an answer. There is everything what I was looking for and I will be glad to accept such answer. – Tomek Tarczynski Apr 23 '12 at 19:03

1 Answer

up vote 4 down vote accepted

It is described in Michael Friendly's American Statistician paper on corrgrams, Preprint PDF here. See section on correlation ordering. Also of potential interest, a presentation by Leland Wilkinson on other potential ways to order heatmaps. Also if you look at the source of the corrgram library you will see some other potential ways to order the data as well.

To describe what the code is doing in a nut-shell, the variables in the correlation matrix are ordered according to the correlation with the first principle component extracted from that same correlation matrix. If you look at the Eigenvector plot in the Friendly paper, the code atan(e2/e1) is the angle of the eigen-vector associated with a particular variable against the first principle component (the horizontal axis). Apparently this approximates the correlation (although to be honest I have not walked myself through the necessary math to convince myself of such an approximation!)

Again the reason for the ordering is given in the Friendly paper, but we almost always want more similar things next to more similar things (in either graphics or tables). Frequently the ordering is more informative than the numbers or the graph! Here in this example more similar is defined by correlation to the first principle component.

Also note I assume the first if statement in the code prevents this ordering from occurring if the correlation matrix is not full rank.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.