Re: [R] correlatation matrix

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue, 31 May 2011 11:09:46 +0100 (BST)

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

______________________________________________
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.
Received on Tue 31 May 2011 - 10:27:36 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 31 May 2011 - 11:50:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive