RE: [R] Pearson corelation and p-value for matrix

From: John Fox <jfox_at_mcmaster.ca>
Date: Sat 16 Apr 2005 - 08:26:07 EST


Dear Dren,

How about the following?

 cor.pvalues <- function(X){

    nc <- ncol(X)
    res <- matrix(0, nc, nc)
    for (i in 2:nc){

        for (j in 1:(i - 1)){
            res[i, j] <- res[j, i] <- cor.test(X[,i], X[,j])$p.value
            }
        }

    res
    }

What one then does with all of those non-independent test is another question, I guess.

I hope this helps,
 John



John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Dren Scott
> Sent: Friday, April 15, 2005 4:33 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Pearson corelation and p-value for matrix
>
> Hi,
>
> I was trying to evaluate the pearson correlation and the
> p-values for an nxm matrix, where each row represents a
> vector. One way to do it would be to iterate through each
> row, and find its correlation value( and the p-value) with
> respect to the other rows. Is there some function by which I
> can use the matrix as input? Ideally, the output would be an
> nxn matrix, containing the p-values between the respective vectors.
>
> I have tried cor.test for the iterations, but couldn't find a
> function that would take the matrix as input.
>
> Thanks for the help.
>
> Dren
>
>
>
>
> ---------------------------------
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Apr 17 00:34:01 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:13 EST