Here is an example for my earlier question. Say you have a 3x3 correlation 
matrix:corrs <- matrix(c(0.25,0.32,0.66,0.14,0.24,0.34,0.44,0.34,0.11), nrow=3, 
ncol=3, dimnames = list(c('varA','varB', 'varC'), c('varA','varB', 'varC')))And 
another matrix for the sample size of each correlation:sizes <- 
matrix(c(44,68,313,142,144,207,201,100,99), nrow=3, ncol=3, dimnames = 
list(c('varA','varB', 'varC'), c('varA','varB', 'varC')))corrs looks like this: 
     varA varB varCvarA 0.05 0.14 0.44varB 0.32 0.24 0.34varC 0.66 0.57 
0.50sizes:     varA varB varCvarA   44  142  201varB   68  144  100varC  313  
207   99i.e., the correlation between variables A and C was 0.66 with sample 
size of 313. (I got these tables from rcorr).What I want to do is to compare 
the correlations in each row (probably using r.test), and then create a 
correlation table with subscripts or superscripts indicating the significance 
"group" (again: correlations with different superscripts, in the same row, are 
signif!
 icantly different from each other). Something like this:       varA varB 
varCvarA 0.05b 0.14b 0.44avarB 0.32a 0.24a 0.34avarC 0.66a 0.57ab 0.50bOf 
course, I don't have a 3x3 table. I have about 20 tables of at least 7x7 each, 
so this is why I'm looking for methods to automate the process. Thanks,Yoav
> CC: r-help@r-project.org
> From: dwinsem...@comcast.net
> To: ybara...@hotmail.com
> Subject: Re: [R] cross-correlation table with subscript or superscript to 
> indicate significant differences
> Date: Thu, 5 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
> 

                                          
        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to