The R Project SVN R

Rev

Rev 61160 | Rev 67599 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61160 Rev 61433
Line 21... Line 21...
21
    both be factors.}
21
    both be factors.}
22
  \item{y}{a numeric vector; ignored if \code{x} is a matrix.  If
22
  \item{y}{a numeric vector; ignored if \code{x} is a matrix.  If
23
    \code{x} is a factor, \code{y} should be a factor of the same length.}
23
    \code{x} is a factor, \code{y} should be a factor of the same length.}
24
  \item{correct}{a logical indicating whether to apply continuity
24
  \item{correct}{a logical indicating whether to apply continuity
25
    correction when computing the test statistic for 2 by 2 tables: one
25
    correction when computing the test statistic for 2 by 2 tables: one
26
    half is subtracted from all \eqn{|O - E|} differences; however, the 
26
    half is subtracted from all \eqn{|O - E|} differences; however, the
27
    correction will not be bigger than the differences themselves.  No correction
27
    correction will not be bigger than the differences themselves.  No correction
28
    is done if \code{simulate.p.value = TRUE}.}
28
    is done if \code{simulate.p.value = TRUE}.}
29
  \item{p}{a vector of probabilities of the same length of \code{x}.
29
  \item{p}{a vector of probabilities of the same length of \code{x}.
30
    An error is given if any entry of \code{p} is negative.}
30
    An error is given if any entry of \code{p} is negative.}
31
  \item{rescale.p}{a logical scalar; if TRUE then \code{p} is rescaled
31
  \item{rescale.p}{a logical scalar; if TRUE then \code{p} is rescaled
Line 88... Line 88...
88
  \item{observed}{the observed counts.}
88
  \item{observed}{the observed counts.}
89
  \item{expected}{the expected counts under the null hypothesis.}
89
  \item{expected}{the expected counts under the null hypothesis.}
90
  \item{residuals}{the Pearson residuals,
90
  \item{residuals}{the Pearson residuals,
91
    \code{(observed - expected) / sqrt(expected)}.}
91
    \code{(observed - expected) / sqrt(expected)}.}
92
  \item{stdres}{standardized residuals,
92
  \item{stdres}{standardized residuals,
93
    \code{(observed - expected) / sqrt(V)}, where \code{V} is the residual cell variance (Agresti, 2007, 
93
    \code{(observed - expected) / sqrt(V)}, where \code{V} is the residual cell variance (Agresti, 2007,
94
    section 2.4.5 for the case where \code{x} is a matrix, \code{n * p * (1 - p)} otherwise).}
94
    section 2.4.5 for the case where \code{x} is a matrix, \code{n * p * (1 - p)} otherwise).}
95
}
95
}
96
\seealso{
96
\seealso{
97
  For goodness-of-fit testing, notably of continuous distributions,
97
  For goodness-of-fit testing, notably of continuous distributions,
98
  \code{\link{ks.test}}.
98
  \code{\link{ks.test}}.
Line 122... Line 122...
122
## From Agresti(2007) p.39
122
## From Agresti(2007) p.39
123
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
123
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
124
dimnames(M) <- list(gender = c("M","F"),
124
dimnames(M) <- list(gender = c("M","F"),
125
                    party = c("Democrat","Independent", "Republican"))
125
                    party = c("Democrat","Independent", "Republican"))
126
(Xsq <- chisq.test(M))  # Prints test summary
126
(Xsq <- chisq.test(M))  # Prints test summary
127
Xsq$observed   # observed counts (same as M) 
127
Xsq$observed   # observed counts (same as M)
128
Xsq$expected   # expected counts under the null
128
Xsq$expected   # expected counts under the null
129
Xsq$residuals  # Pearson residuals
129
Xsq$residuals  # Pearson residuals
130
Xsq$stdres     # standardized residuals
130
Xsq$stdres     # standardized residuals
131
 
131
 
132
 
132