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

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Thu, 05 May 2011 12:17:25 -0400

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 05 May 2011 - 16:20:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 16:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive