Skip to content

Commit

Permalink
chisq.test: Avoid overcorrection
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/branches/R-2-15-branch@59556 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
pd committed Jun 11, 2012
1 parent f73e48d commit 69f3985
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion doc/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
\title{ R News}
\encoding{UTF-8}

\section{\Rlogo CHANGES IN R VERSION 2.15.0 patched}{
\section{\Rlogo CHANGES IN R VERSION 2.15.1}{
\subsection{NEW FEATURES}{
\itemize{
\item \code{source()} now uses \code{withVisible()} rather than
Expand Down Expand Up @@ -306,6 +306,10 @@

\item \code{by()} failed for a zero-row data frame. (Reported by
Weiqiang Qian)

\item Yates correction in \code{chisq.test()} could be bigger than
the terms it corrected, leading to an infinite test statistic in
some corner cases.
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/library/stats/R/chisq.test.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ chisq.test <- function(x, y = NULL, correct = TRUE,
if (simulate.p.value)
warning("cannot compute simulated p-value with zero marginals")
if (correct && nrow(x) == 2 && ncol(x) == 2) {
YATES <- 0.5
METHOD <- paste(METHOD, "with Yates' continuity correction")
YATES <- min(0.5, abs(x-E))
if (YATES > 0)
METHOD <- paste(METHOD, "with Yates' continuity correction")
}
else
YATES <- 0
Expand Down
3 changes: 2 additions & 1 deletion src/library/stats/man/chisq.test.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ chisq.test(x, y = NULL, correct = TRUE,
\code{x} is a factor, \code{y} should be a factor of the same length.}
\item{correct}{a logical indicating whether to apply continuity
correction when computing the test statistic for 2 by 2 tables: one
half is subtracted from all \eqn{|O - E|} differences. No correction
half is subtracted from all \eqn{|O - E|} differences; however, the
correction will not be bigger than the differences themselves. No correction
is done if \code{simulate.p.value = TRUE}.}
\item{p}{a vector of probabilities of the same length of \code{x}.
An error is given if any entry of \code{p} is negative.}
Expand Down

0 comments on commit 69f3985

Please sign in to comment.