yoav baranan
2011-May-05 14:48 UTC
[R] cross-correlation table with subscript or superscript to indicate significant differences
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]]
David Winsemius
2011-May-05 16:17 UTC
[R] cross-correlation table with subscript or superscript to indicate significant differences
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
yoav baranan
2011-May-05 16:40 UTC
[R] cross-correlation table with subscript or superscript to indicate significant differences
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 significantly 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: dwinsemius@comcast.net > To: ybaranan@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]]
David Winsemius
2011-May-05 17:45 UTC
[R] cross-correlation table with subscript or superscript to indicate significant differences
On May 5, 2011, at 12:40 PM, yoav baranan wrote:> 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 varC > varA 0.05 0.14 0.44 > varB 0.32 0.24 0.34 > varC 0.66 0.57 0.50 > > sizes: > varA varB varC > varA 44 142 201 > varB 68 144 100 > varC 313 207 99 > > i.e., the correlation between variables A and C was 0.66 with sample > size of 313. (I got these tables from rcorr).Why not offer the result of dput() on the result from rcorrs cone on 3 variables. Then we should have the necessary building blocks for your original request. This way we do not have the matrix of p-values. And as the Posting Guide clearly says ...Please post in plain text. In your case it is particularly annoying because I do not get the filtered version but rather you html version and the text is almost unreadable at a font size of 10 in whatever font it is specifying!> > 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 significantly different from each other). > Something like this: > varA varB varC > varA 0.05b 0.14b 0.44a > varB 0.32a 0.24a 0.34a > varC 0.66a 0.57ab 0.50bAt the moment we have no way of determining what values should be post- pended with which letters.> > Of 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 at r-project.org > > From: dwinsemius at comcast.net > > To: ybaranan at 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). > >snipped> >David Winsemius, MD West Hartford, CT