[R] cross-correlation table with subscript or superscript to indicate significant differences

David Winsemius dwinsemius at comcast.net
Thu May 5 18:17:25 CEST 2011


On May 5, 2011, at 10:48 AM, yoav baranan wrote:

>
> Hi, I wonder whether the following is possible with R, and whether  
> anyone has done that and can share his/her code with me. I have a  
> correlation matrix, and I want to create a correlation table that I  
> can copy to Microsoft Word with a superscript above each  
> correlation, indicating significant differences in the same row.  
> That is, when correlations in the same row do not share superscript,  
> it means that they are significantly different from each other. 		 
> thanks,yoav 		 	   		
> 	[[alternative HTML version deleted]]

An example with data and the desired result might help focus the  
discussion.

This shows how to set up an example showing how extract the row  
numbers from a correlation matrix with absolute values above 0.5 but  
less than 1 (to exclude the trivial cases).

 > set.seed(123)
 > X <- matrix(rnorm(100), 10)
 > apply(cor(X), 2, function(x) which(abs(x) > 0.5 & x < 1)  )
[[1]]
[1] 2 4 8

[[2]]
[1] 1 3

[[3]]
[1] 2 6 9

[[4]]
[1] 1 7

[[5]]
integer(0)

[[6]]
[1]  3 10

[[7]]
[1] 4

[[8]]
[1] 1

[[9]]
[1] 3

[[10]]
[1] 6

This would extract the rownames if they are letters[1:10]

 > lapply( apply(cor(X), 2, function(x) which(abs(x) > 0.5 & x < 1) ),  
function(x) rownames(X)[x])
[[1]]
[1] "b" "d" "h"

[[2]]
[1] "a" "c"

[[3]]
[1] "b" "f" "i"

[[4]]
[1] "a" "g"

[[5]]
character(0)

[[6]]
[1] "c" "j"

[[7]]
[1] "d"

[[8]]
[1] "a"

[[9]]
[1] "c"

[[10]]
[1] "f"

Exactly how we are supposed to pass this to MS Word does not seem to  
be a proper question for this mailing list.

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list