[R] correlatation matrix

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue May 31 12:09:46 CEST 2011


See ?cor for an efficient vectorized way to find the correlation 
matrix.

You could compute p-values from the matrix (read the code for 
stats:::cor.test.default for the formulae), but note that with 
169x20043 p-values, they don't really have much meaning.

On Tue, 31 May 2011, Unger, Kristian, Dr. wrote:

> Hi there,
>
> I wonder if there is a way of efficiently generating a correlation matrix of two expression matrices. I want to correlate miRNA and mRNA expression and used the following code:
> ##dat.mi miRNA expression matrix, dat.m mRNA expression matrix
> nc <- nrow(dat.mi)
> cor.mat <- data.frame(rep(NA,nrow(dat.m)))
> pval.mat <- data.frame(rep(NA,nrow(dat.m)))
> for(i in 1:nc)
> {
> cr <- vector()
> pv <- vector()
> print(paste(i," mirs out of ", nc,sep=""))
> for (k in 1:nrow(dat.m))
> {
> #print(paste(k," genes out of ",  nrow(dat.m),sep=""))
> cr2 <- cor.test(as.numeric(dat.mi[i,]),as.numeric(dat.m[k,]))
> cr <- c(cr,cr2$estimate)
> pv <- c(pv,cr2$p.value)
> }
> cor.mat <- cbind(cor.mat,as.vector(cr))
> pval.mat <- cbind(pval.mat,as.vector(pv))
> }
>
> The columns in the output represent miRNAs and the rows mRNAs. The 
> code works fine but takes ages (about an 1.5h for generating a 
> 169x20043 matrix) so I wonder if there is a more efficient way of 
> doing this calculation?
>
> Best wishes
>
> Kristian
>
> ________________________________
> Helmholtz Zentrum M?nchen
> Deutsches Forschungszentrum f?r Gesundheit und Umwelt (GmbH)
> Ingolst?dter Landstr. 1
> 85764 Neuherberg
> www.helmholtz-muenchen.de
> Aufsichtsratsvorsitzende: MinDir?in B?rbel Brumme-Bothe
> Gesch?ftsf?hrer: Prof. Dr. G?nther Wess und Dr. Nikolaus Blum
> Registergericht: Amtsgericht M?nchen HRB 6466
> USt-IdNr: DE 129521671
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list