[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]] __ 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.
Re: [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 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.
[R] get cells by the combination of their column and row names
Hi, I have a (correlation) matrix and I want to select a subset of its cells depending on the combination of their column and row names. This illustrates my problem: mtrx - matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3, dimnames = list(c('c132','c432', 'c233'), c('r132','r233', 'r432'))) mtrx r132 r233 r432c132147c432258c233369 At this point I want to compute the mean of the cells in which the column and the row names share the same suffix (i.e., the cells mtrx[1,1], mtrx[2,3], mtrx[3,2]). By suffix I mean the last three digits of the row/col name. I need a generic code (and not vec-c(mtrx[1,1], mtrx[2,3], mtrx[3,2])) because I don't know in advance how many rows and columns I will have (currently 118). Thanks, Yoav [[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.
[R] Find index of a string inside a string?
Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do in SAS. thanks, y. baranan. [[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.
Re: [R] Find index of a string inside a string?
Thank you. I know grep, but I don't know how to use it for what I need to do. for instance: grep(bcd, abcd) returns: [1] 1 grep(bcd, aabcd) returns: [1] 1 I need the first one to return 2 (b is in the 2nd cell), and the second one return 3 (b is in the 3rd cell). thanks From: nick.sa...@ugent.be To: ybara...@hotmail.com; r-help@r-project.org Subject: RE: [R] Find index of a string inside a string? Date: Mon, 25 Oct 2010 13:42:23 +0200 For simple searches, use grep with fixed=TRUE. Check ?grep. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of yoav baranan Sent: maandag 25 oktober 2010 13:27 To: r-help@r-project.org Subject: [R] Find index of a string inside a string? Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do in SAS. thanks, y. baranan. [[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. [[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.
Re: [R] Find index of a string inside a string?
Indeed, thank you. The exact equivalent of index in SAS seems to me: regexpr(bcd, aabcd, fixed=T)[1] [1] 3 Date: Mon, 25 Oct 2010 07:53:22 -0400 Subject: Re: [R] Find index of a string inside a string? From: jholt...@gmail.com To: ybara...@hotmail.com CC: r-help@r-project.org I think what you want is 'regexpr': regexpr(bcd, aabcd) [1] 3 attr(,match.length) [1] 3 On Mon, Oct 25, 2010 at 7:27 AM, yoav baranan ybara...@hotmail.com wrote: Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do in SAS. thanks, y. baranan. [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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.