Re: [R] Adjusting p values of a matrix

From: peter dalgaard <PDalgd_at_gmail.com>
Date: Mon, 04 Apr 2011 18:03:40 +0200

On Apr 4, 2011, at 17:02 , January Weiner wrote:

> Dear all,
>
> I have an n x n matrix of p-values. The matrix is symmetrical, as it
> describes the "each against each" p values of correlation
> coefficients.
>
> How can I best correct the p values of the matrix? Notably, the total
> number of the tests performed is n(n-1)/2, since I do not test the
> correlation of each variable with itself. That means, I only want to
> correct one half of the matrix, not including the diagonal. Therefore,
> simply writing
>
> pmat <- p.adjust( pmat, method= "fdr" )
> # where pmat is an n x n matrix
>
> ...doesn't cut it.
>
> Of course, I can turn the matrix in to a three column data frame with
> n(n-1)/2 rows, but that is slow and not elegant.

I don't think there's a really elegant way (have a look inside pairwise.table if you care).

If you start one step further back, you could just use pairwise.table with a suitably defined comparison function. Otherwise, how about

ltri <- lower.tri(pmat)
utri <- upper.tri(pmat)
pmat[ltri] <- p.adjust(pmat[ltri], method = "fdr") pmat[utri] <- t(pmat)[utri]

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes_at_cbs.dk  Priv: PDalgd_at_gmail.com

______________________________________________
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 Mon 04 Apr 2011 - 16:06:47 GMT

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 Mon 04 Apr 2011 - 16:10:26 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