[R] Help to find correlation. Oops
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Thu Feb 16 21:55:35 CET 2006
Or simply
library(Hmisc)
rcorr(data matrix)
Frank
Martin Henry H. Stevens wrote:
> Hi,
> Ignore the previous post-it contained a typo. Sorry! The following is
> ok.
> Hank
>
> See help files for read.csv for input.
> See help files for cor.test
> dat <- read.csv("whatever-your-file-is", other info...)
>
> # Generate an upper triangular matrix of Pearson product moment
> correlation coefficients
> r.s <- matrix(NA, nr=dim(dat)[2], nc=dim(dat)[2])
> rownames(r.s) <- names(dat)
> colnames(r.s) <- names(dat)
> for(i in 1:(dim(dat)[2]-1)) {
> for(j in i:dim(dat)[2]) r.s[i,j] <- {cor.test(dat[,i], dat[,j])
> $estimate}}
> r.s
>
> # Generate an upper triangular matrix of P values of the r's
> p.s <- matrix(NA, nr=dim(dat)[2], nc=dim(dat)[2])
> rownames(p.s) <- names(dat)
> colnames(p.s) <- names(dat)
> for(i in 1:(dim(dat)[2]-1)) {
> for(j in i:dim(dat)[2]) p.s[i,j] <- {cor.test(dat[,i], dat[,j])
> $p.value}}
> p.s
>
> Please do read the help files.
> Hank
>
> On Feb 16, 2006, at 1:17 PM, Anusha Aiyaloo kannan ((RIT Student))
> wrote:
>
>
>>Respected Sir,
>>
>>I am trying to import excel file into R, but I need to truncate
>>some columns from the original file.
>>
>> How to delete unwanted columns when I import data from excel file.
>>
>>How to use cor.test for the data when I want the output rowwise.
>>
>>How to do grouping and use cor.test on that data
>>
>>I need some help regarding how to calculate the correlation.
>>I don't know whether you understood my question, but I need help.
>>
>>Any help is appreciated.
>>
>>Thanks,
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! http://www.R-project.org/posting-
>>guide.html
>
>
> Dr. Martin Henry H. Stevens, Assistant Professor
> 338 Pearson Hall
> Botany Department
> Miami University
> Oxford, OH 45056
>
> Office: (513) 529-4206
> Lab: (513) 529-4262
> FAX: (513) 529-4243
> http://www.cas.muohio.edu/~stevenmh/
> http://www.muohio.edu/ecology/
> http://www.muohio.edu/botany/
> "E Pluribus Unum"
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list