Skip to content

spearman correlation and p-value as a matrix

2 messages · Ozgul Inceoglu, arun

#
Thank you all for the answers. I really need to learn a lot. 
Bu I also discover cor2m(x, y, trim = TRUE, alpha = 0.05)
in ecodist package, which gives an output file with significant correlations.

?zg?l

Yj>HI,
?zg?l Inceoglu, PhD.

Universit? Libre de Bruxelles
Ecology of Aquatic Systems 
Campus de la plaine CP221  
Boulevard du triomphe  
1050 Bruxelles Belgium
#
Dear Ozgul,

I made a comment in the previous email, which I didn't check it.
Thank you for the ?cor2m().
I checked the results of the example dataset with cor2m().? Does it have an option for spearman correlation?? 

The values below seem to be pearson
#cor2m
?cor2m(bg,ag,trim=TRUE,alpha=0.05) ######I
????? Otu00022 Otu00029?? Otu00039 Otu00042? Otu00101 Otu00105 Otu00125
ag1? 0.0000000????? NaN? 0.0000000????? NaN 0.0000000????? NaN????? NaN
ag2? 0.0000000????? NaN? 0.0000000????? NaN 0.7743597????? NaN????? NaN
ag3 -0.8901029????? NaN -0.8901029????? NaN 0.0000000????? NaN????? NaN
ag4? 0.0000000????? NaN? 0.0000000????? NaN 0.0000000????? NaN????? NaN
ag5? 0.0000000????? NaN? 0.0000000????? NaN 0.0000000????? NaN????? NaN
??? Otu00131?? Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185?? Otu00190
ag1????? NaN? 0.0000000????? NaN????? NaN????? NaN????? NaN????? NaN? 0.0000000
ag2????? NaN? 0.0000000????? NaN????? NaN????? NaN????? NaN????? NaN? 0.0000000
ag3????? NaN -0.8901029????? NaN????? NaN????? NaN????? NaN????? NaN -0.8901029
ag4????? NaN? 0.0000000????? NaN????? NaN????? NaN????? NaN????? NaN? 0.0000000
ag5????? NaN? 0.0000000????? NaN????? NaN????? NaN????? NaN????? NaN? 0.0000000
??? Otu00209?? Otu00218
ag1????? NaN? 0.0000000
ag2????? NaN? 0.0000000
ag3????? NaN -0.8901029
ag4????? NaN? 0.0000000
ag5????? NaN? 0.0000000

#Pearson correlation from my solution:
resr<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x)
 {res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]))$r; row.names(res)<- 
rep(paste(x[1],x[2],sep="_"),2);res})) 
?indx<-row(resr)%%2!=1
resrnew<-as.matrix(resr[indx[,1],1]) 
resrnew1<-data.frame(read.table(text=row.names(resrnew),sep="_",stringsAsFactors=FALSE),value=resrnew)
?row.names(resrnew1)<-1:nrow(resrnew1)
library(reshape2)
?dcast(resrnew1,V2~V1,value.var="value")?? V2??? Otu00022 Otu00029??? Otu00039 Otu00042?? Otu00101 Otu00105 Otu00125
#1 ag1 -0.12705141????? NaN -0.12705141????? NaN -0.6394308????? NaN????? NaN
#2 ag2 -0.61522514????? NaN -0.61522514????? NaN? 0.7743597????? NaN????? NaN
#3 ag3 -0.89010286????? NaN -0.89010286????? NaN -0.2655363????? NaN????? NaN
#4 ag4? 0.03036290????? NaN? 0.03036290????? NaN -0.5638320????? NaN????? NaN
#5 ag5? 0.08266317????? NaN? 0.08266317????? NaN -0.2582930????? NaN????? NaN
?# Otu00131??? Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185??? Otu00190
#1????? NaN -0.12705141????? NaN????? NaN????? NaN????? NaN????? NaN -0.12705141
#2????? NaN -0.61522514????? NaN????? NaN????? NaN????? NaN????? NaN -0.61522514
#3????? NaN -0.89010286????? NaN????? NaN????? NaN????? NaN????? NaN -0.89010286
#4????? NaN? 0.03036290????? NaN????? NaN????? NaN????? NaN????? NaN? 0.03036290
#5????? NaN? 0.08266317????? NaN????? NaN????? NaN????? NaN????? NaN? 0.08266317
?# Otu00209??? Otu00218
#1????? NaN -0.12705141
#2????? NaN -0.61522514
#3????? NaN -0.89010286
#4????? NaN? 0.03036290
#5????? NaN? 0.08266317

A.K.



----- Original Message -----
From: Ozgul Inceoglu <Ozgul.Inceoglu at ulb.ac.be>
To: R help <r-help at r-project.org>
Cc: 
Sent: Thursday, February 14, 2013 1:10 AM
Subject: Re: [R] spearman correlation and p-value as a matrix

Thank you all for the answers. I really need to learn a lot. 
Bu I also discover cor2m(x, y, trim = TRUE, alpha = 0.05)
in ecodist package, which gives an output file with significant correlations.

?zg?l

Yj>HI,
?zg?l Inceoglu, PhD.

Universit? Libre de Bruxelles
Ecology of Aquatic Systems 
Campus de la plaine CP221? 
Boulevard du triomphe? 
1050 Bruxelles Belgium? 

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