\Header{chisq.test}{Pearson's Chi-square Test for Count Data}
\keyword{htest}{chisq.test}
\keyword{distribution}{chisq.test}
\begin{Usage}
\begin{verbatim}
chisq.test(x, y = NULL, correct = TRUE,
           p = rep(1/length(x), length(x)))
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{x}] a vector or matrix.
\item[\texttt{y}] a vector; ignored if \texttt{x} is a matrix.
\item[\texttt{correct}] a logical indicating whether to apply continuity
correction when computing the test statistic.
\end{ldescription}
\end{Arguments}
\begin{Description}
\texttt{chisq.test} performs chi-square tests on contingency tables.\end{Description}
\begin{Details}
If \texttt{x} is a matrix with one row or column, or if \texttt{x} is a
vector and \texttt{y} is not given, \texttt{x} is treated as a
one-dimensional contingency table.  In this case, the hypothesis
tested is whether the population probabilities equal those in
\texttt{p}, or are all equal if \texttt{p} is not given. 

If \texttt{x} is a matrix with at least two rows and columns, it is
taken as a two-dimensional contingency table, and hence its entries
should be nonnegative integers.  Otherwise, \texttt{x} and \texttt{y}
must be vectors or factors of the same length; incomplete cases are
removed, the objects are coerced into factor objects, and the
contingency table is computed from these.  Then, Pearson's
chi-square test of the null that the joint distribution of the cell
counts in a 2-dimensional contingency table is the product of the row
and column marginals is performed.  Continuity correction is only
used in the 2-by-2 case if \texttt{correct} is \texttt{TRUE}.\end{Details}
\begin{Value}
A list with class \texttt{"htest"} containing the following
components:
\begin{ldescription}
\item[\texttt{statistic}] the value the chi-square test statistic.
\item[\texttt{parameter}] the degrees of freedom of the approximate
chi-square distribution of the test statistic.
\item[\texttt{p.value}] the p-value for the test.
\item[\texttt{method}] a character string indicating the type of test
performed, and whether continuity correction was used.
\item[\texttt{data.name}] a character string giving the name(s) of the data.
\item[\texttt{observed}] the observed counts.
\item[\texttt{expected}] the expected counts under the null hypothesis.
\end{ldescription}
\end{Value}
\begin{Examples}
\begin{ExampleCode}
data(insects)                   # Not really a good example
chisq.test(insects$count > 7, insects$spray)
                                # Prints test summary
chisq.test(insects$count > 7, insects$spray)$obs
                                # Counts observed
chisq.test(insects$count > 7, insects$spray)$obs
                                # Counts expected under the null
\end{ExampleCode}
\end{Examples}

