# [BioC] Pearson correlation and p-values for a matrix

Naomi Altman naomi at stat.psu.edu
Tue Apr 19 17:48:31 CEST 2005

```Here is what I would do:

use "cor" to compute the correlations

extract the test part of the cor.test into a function that inputs a vector
of correlations and outputs a  vector of p-values.

Run the new function on the correlation matrix.

--Naomi

At 11:19 AM 4/19/2005, xpeng wrote:
>Hi Dren,
>
>I had the similar question, then I wrote my own C program to calculate
>correlation matrices (2-3min for a 8000 x 60 matrix). You can contact with me
>directly (xpeng at utk.edu), it need some extra works to get p-values. I will
>post it somewhere online if there are enough interests.
>
>Best,
>Xinxia
>
>
>
>
>   >===== Original Message From Dren Scott <dren_scott at yahoo.com> =====
> >Hi All,
> >
> >I was trying to calculate the pearson correlation (and p-value) for a gene
>dataset ( 6000 rows x 10 columns). For each row vector, I wanted to calculate
>the p-value with respect to the other row vectors. My resulting p-value
>matrix
>should be of size 6000 x 6000.
> >
> >I tried the iterative approach:
> >
> >
> >for(i in 1:nrow(data)){
> >
> >   for(j in i:nrow(data)){
> >
> >         p_value <- cor.test(data[i,],data[j,])\$p.value
> >
> >         pmatrix[j,i] <- pmatrix[i,j] <- p_value
> >
> >   }
> >
> >}
> >
> >
> >
> >But this will take too long for nrow(data) = 6000. Is there some method by
>which I can pass the matrix into a function to get the p-values? The dataset
>would also have some/many NA's.
> >
> >
> >
> >thanks,
> >
> >
> >
> >Dren
> >
> >
> >
> >---------------------------------
> >
> >
> >       [[alternative HTML version deleted]]
> >
> >_______________________________________________
> >Bioconductor mailing list
> >Bioconductor at stat.math.ethz.ch
> >https://stat.ethz.ch/mailman/listinfo/bioconductor
>
>_______________________________________________
>Bioconductor mailing list
>Bioconductor at stat.math.ethz.ch
>https://stat.ethz.ch/mailman/listinfo/bioconductor

Naomi S. Altman                                814-865-3791 (voice)
Associate Professor
Bioinformatics Consulting Center
Dept. of Statistics                              814-863-7114 (fax)
Penn State University                         814-865-1348 (Statistics)
University Park, PA 16802-2111

```