Skip to content
Prev 86634 / 398513 Next

Help to find correlation. Oops

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:
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"