Skip to content

Commit

Permalink
Add man page for phicoef().
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jun 20, 2012
1 parent 5a1eec9 commit 856626f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/phicoef.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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")
stop("when 'y' is not supplied, 'x' must be ",
"a 2x2 integer matrix or an integer vector of length 4")
a <- x[1L]
c <- x[2L]
b <- x[3L]
Expand Down
49 changes: 49 additions & 0 deletions man/phicoef.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
\name{phicoef}

\alias{phicoef}

\title{Calculate the "phi coefficient" between two binary variables}

\description{
The \code{phicoef} function calculates the "phi coefficient" between
two binary variables.
}

\usage{
phicoef(x, y=NULL)
}

\arguments{
\item{x, y}{
Two logical vectors of the same length, or, if \code{y} is not supplied,
\code{x} must be a 2x2 integer matrix (or an integer vector of length 4)
representing the contingency table of two binary variables.
}
}

\value{
The "phi coefficient" between the two binary variables.
This is a single numeric value ranging from -1 to + 1.
}

\references{
\url{http://en.wikipedia.org/wiki/Phi_coefficient}
}

\author{
H. Pages
}

\examples{
set.seed(33)
x <- sample(c(TRUE, FALSE), 100, replace=TRUE)
y <- sample(c(TRUE, FALSE), 100, replace=TRUE)
phicoef(x, y)
phicoef(rep(x, 10), c(rep(x, 9), y))

stopifnot(phicoef(table(x, y)) == phicoef(x, y))
stopifnot(phicoef(x, !y) == - phicoef(x, y))
stopifnot(phicoef(x, x) == 1)
}

\keyword{manip}

0 comments on commit 856626f

Please sign in to comment.