11# ' Perform many pairwise mutual exclusivity or co-occurrence tests.
22# '
33# ' @param x A \code{discover.matrix} object.
4- # ' @param g An optional grouping vector for the rows of \code{events}. Pairs of rows within the same group are not tested.
5- # ' @param alternative Either \code{"less"} for mutual-exclusivity analysis, or \code{"greater"} for co-occurrence analysis.
6- # ' @param correct If \code{TRUE}, multiple testing correction is performed.
4+ # ' @param g An optional grouping vector for the rows of \code{events}. Pairs of rows
5+ # ' within the same group are not tested.
6+ # ' @param alternative Either \code{"less"} for mutual-exclusivity analysis, or
7+ # ' \code{"greater"} for co-occurrence analysis.
8+ # ' @param fdr.method The false discovery rate procedure used for multiple testing correction.
9+ # ' If \code{"DBH"}, a Benjamini-Hochberg procedure adapted for discrete test statistics is
10+ # ' used. If \code{"BH"}, the standard Benjamini-Hochberg procedure is used. The latter is
11+ # ' much faster, but also more conservative than the discrete version.
712# ' @return An object of type \code{pairwise.discover.out}.
813# '
914# ' @useDynLib discover
1015# ' @export
11- pairwise.discover.test <- function (x , g = NULL , alternative = c(" less" , " greater" ), correct = TRUE ) {
16+ pairwise.discover.test <- function (x , g = NULL , alternative = c(" less" , " greater" ), fdr.method = c( " DBH " , " BH " ) ) {
1217 alternative <- match.arg(alternative )
18+ fdr.method <- match.arg(fdr.method )
19+ discrete.fdr <- fdr.method == " DBH"
1320
1421 events <- x $ events
1522 bg <- x $ bg
@@ -18,9 +25,16 @@ pairwise.discover.test <- function (x, g=NULL, alternative=c("less", "greater"),
1825 result <- .Fortran(" mutex" ,
1926 as.integer(nrow(events )), as.integer(ncol(events )),
2027 as.integer(events ), as.double(bg ), as.integer(alternative == " less" ),
28+ as.integer(discrete.fdr ),
2129 p = double(nrow(events ) * (nrow(events ) - 1 ) / 2 ),
2230 q = double(nrow(events ) * (nrow(events ) - 1 ) / 2 ),
2331 pi0 = double(1 ))
32+
33+ if (fdr.method == " BH" ) {
34+ result $ q <- p.adjust(result $ p , " BH" )
35+ result $ pi0 <- 1.0
36+ }
37+
2438 p <- matrix (NA , nrow(events ), nrow(events ))
2539 p [lower.tri(p )] <- result $ p
2640
@@ -34,8 +48,14 @@ pairwise.discover.test <- function (x, g=NULL, alternative=c("less", "greater"),
3448 as.integer(nrow(events )), as.integer(ncol(events )),
3549 as.integer(events [i , ]), as.double(bg [i , ]), as.integer(alternative == " less" ),
3650 as.integer(length(block.sizes )), as.integer(block.sizes ),
51+ as.integer(discrete.fdr ),
3752 p = double(nrow(events )** 2 ), q = double(nrow(events )** 2 ), pi0 = double(1 ))
3853
54+ if (fdr.method == " BH" ) {
55+ result $ q <- p.adjust(result $ p , " BH" )
56+ result $ pi0 <- 1.0
57+ }
58+
3959 j <- order(i )
4060 p <- matrix (result $ p , nrow = nrow(events ))[j , j ]
4161 p [is.nan(p )] <- NA
@@ -54,7 +74,8 @@ pairwise.discover.test <- function (x, g=NULL, alternative=c("less", "greater"),
5474 p.values = p ,
5575 q.values = q ,
5676 pi0 = result $ pi0 ,
57- alternative = alternative )
77+ alternative = alternative ,
78+ fdr.method = fdr.method )
5879 class(result ) <- " pairwise.discover.out"
5980 result
6081}
0 commit comments