| Line 1... |
Line 1... |
| 1 |
% File src/library/stats/man/chisq.test.Rd
|
1 |
% File src/library/stats/man/chisq.test.Rd
|
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2022 R Core Team
|
3 |
% Copyright 1995-2025 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{chisq.test}
|
6 |
\name{chisq.test}
|
| 7 |
\alias{chisq.test}
|
7 |
\alias{chisq.test}
|
| 8 |
\concept{goodness-of-fit}
|
8 |
\concept{goodness-of-fit}
|
| Line 57... |
Line 57... |
| 57 |
|
57 |
|
| 58 |
If \code{simulate.p.value} is \code{FALSE}, the p-value is computed
|
58 |
If \code{simulate.p.value} is \code{FALSE}, the p-value is computed
|
| 59 |
from the asymptotic chi-squared distribution of the test statistic;
|
59 |
from the asymptotic chi-squared distribution of the test statistic;
|
| 60 |
continuity correction is only used in the 2-by-2 case (if \code{correct}
|
60 |
continuity correction is only used in the 2-by-2 case (if \code{correct}
|
| 61 |
is \code{TRUE}, the default). Otherwise the p-value is computed for a
|
61 |
is \code{TRUE}, the default). Otherwise the p-value is computed for a
|
| 62 |
Monte Carlo test (Hope, 1968) with \code{B} replicates. The default
|
62 |
Monte Carlo test \bibcitep{R:Hope:1968} with \code{B} replicates. The default
|
| 63 |
\code{B = 2000} implies a minimum p-value of about 0.0005 (\eqn{1/(B+1)}).
|
63 |
\code{B = 2000} implies a minimum p-value of about 0.0005 (\eqn{1/(B+1)}).
|
| 64 |
|
64 |
|
| 65 |
In the contingency table case, simulation is done by random sampling
|
65 |
In the contingency table case, simulation is done by random sampling
|
| 66 |
from the set of all contingency tables with given marginals, and works
|
66 |
from the set of all contingency tables with given marginals, and works
|
| 67 |
only if the marginals are strictly positive. Continuity correction is
|
67 |
only if the marginals are strictly positive. Continuity correction is
|
| Line 90... |
Line 90... |
| 90 |
\item{expected}{the expected counts under the null hypothesis.}
|
90 |
\item{expected}{the expected counts under the null hypothesis.}
|
| 91 |
\item{residuals}{the Pearson residuals,
|
91 |
\item{residuals}{the Pearson residuals,
|
| 92 |
\code{(observed - expected) / sqrt(expected)}.}
|
92 |
\code{(observed - expected) / sqrt(expected)}.}
|
| 93 |
\item{stdres}{standardized residuals,
|
93 |
\item{stdres}{standardized residuals,
|
| 94 |
\code{(observed - expected) / sqrt(V)}, where \code{V} is the
|
94 |
\code{(observed - expected) / sqrt(V)}, where \code{V} is the
|
| 95 |
residual cell variance (\bibcite{Agresti, 2007, section 2.4.5}
|
95 |
residual cell variance \bibcitep{|R:Agresti:2007|section 2.4.5}
|
| 96 |
for the case where \code{x} is a matrix, \code{n * p * (1 - p)} otherwise).}
|
96 |
for the case where \code{x} is a matrix, \code{n * p * (1 - p)} otherwise).}
|
| 97 |
}
|
97 |
}
|
| 98 |
\seealso{
|
98 |
\seealso{
|
| 99 |
For goodness-of-fit testing, notably of continuous distributions,
|
99 |
For goodness-of-fit testing, notably of continuous distributions,
|
| 100 |
\code{\link{ks.test}}.
|
100 |
\code{\link{ks.test}}.
|
| 101 |
}
|
101 |
}
|
| 102 |
\source{
|
102 |
\source{
|
| 103 |
The code for Monte Carlo simulation is a C translation of the Fortran
|
103 |
The code for Monte Carlo simulation is a C translation of the Fortran
|
| 104 |
algorithm of Patefield (1981).
|
104 |
algorithm of \bibcitet{R:Patefield:1981}.
|
| 105 |
}
|
105 |
}
|
| 106 |
|
106 |
|
| 107 |
\references{
|
107 |
\references{
|
| 108 |
Hope, A. C. A. (1968).
|
- |
|
| 109 |
A simplified Monte Carlo significance test procedure.
|
- |
|
| 110 |
\emph{Journal of the Royal Statistical Society Series B}, \bold{30},
|
- |
|
| 111 |
582--598.
|
- |
|
| 112 |
\doi{10.1111/j.2517-6161.1968.tb00759.x}.
|
- |
|
| 113 |
%% \url{https://www.jstor.org/stable/2984263}.
|
- |
|
| 114 |
|
- |
|
| 115 |
Patefield, W. M. (1981).
|
- |
|
| 116 |
Algorithm AS 159: An efficient method of generating r x c tables
|
- |
|
| 117 |
with given row and column totals.
|
- |
|
| 118 |
\emph{Applied Statistics}, \bold{30}, 91--97.
|
108 |
\bibinfo{R:Agresti:2007}{footer}{Page 38.}
|
| 119 |
\doi{10.2307/2346669}.
|
- |
|
| 120 |
|
- |
|
| 121 |
Agresti, A. (2007).
|
- |
|
| 122 |
\emph{An Introduction to Categorical Data Analysis}, 2nd ed.
|
- |
|
| 123 |
New York: John Wiley & Sons.
|
- |
|
| 124 |
Page 38.
|
109 |
\bibshow{*}
|
| 125 |
}
|
110 |
}
|
| 126 |
\examples{
|
111 |
\examples{
|
| 127 |
|
112 |
|
| 128 |
## From Agresti(2007) p.39
|
113 |
## From Agresti(2007) p.39
|
| 129 |
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
|
114 |
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
|