forked from jimhester/GenomicRanges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add phicoef() (will be needed for "Overlap encodings" vignette).
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/GenomicRanges@66839 bc3139a8-67e5-0310-9ffc-ced21a209358
- Loading branch information
1 parent
5c2db51
commit 5a1eec9
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### Based on http://en.wikipedia.org/wiki/Phi_coefficient | ||
|
||
phicoef <- function(x, y=NULL) | ||
{ | ||
if (is.null(y)) { | ||
if (!is.integer(x) || length(x) != 4L) | ||
stop("when 'y' is not supplied, 'x' must be a 2x2 integer matrix ", | ||
"or a vector of length 4") | ||
a <- x[1L] | ||
c <- x[2L] | ||
b <- x[3L] | ||
d <- x[4L] | ||
} else { | ||
if (!is.logical(x) || !is.logical(y) || length(x) != length(y)) | ||
stop("when 'y' is supplied, 'x' and 'y' must be ", | ||
"2 logical vectors of the same length") | ||
a <- sum(x & y) | ||
b <- sum(x & !y) | ||
c <- sum(!x & y) | ||
d <- sum(!x & !y) | ||
} | ||
a <- as.double(a) | ||
b <- as.double(b) | ||
c <- as.double(c) | ||
d <- as.double(d) | ||
div <- sqrt((a + b) * (c + d) * (a + c) * (b + d)) | ||
(a * d - b * c) / div | ||
} | ||
|