mcnemar.test(x, y=NULL, correct=T)
x
is a matrix, it must be square, have at least two
rows and columns, all elements of
x
must be non-negative,
and
NA
s, and
Inf
s are not allowed. The
elements of matrix
x
should be whole numbers,
as the test is based on counts; however, since all computations are
carried out to double precision accuracy where possible, the storage mode
of matrix
x
will be coerced to
"double"
. For restrictions on
x
when
it is a factor or a category object, see argument
y
.
x
is a matrix,
y
is ignored. If
x
is
a factor or a category object,
y
is required and must have
the same length as
x
. Both objects must have the same number of
levels, and this number must be at least two.
NA
s in the category index vectors
are allowed, but pairs
(x[i],y[i])
containing these will be removed.
Each element of the index vectors of
x
and
y
should give the membership
of that observation in one of the groups present in the
levels
attributes;
an
NA
in an index vector means that the observation is not in one of
the groups listed for that category object.
Inf
s have no
meaning as indices, and should not be present.
x
or
y
is not a factor/category object (and
x
is not a matrix), it will
be coerced to one implicitly. In this case pairs
(x[i],y[i])
containing
NA
s
will be removed, but not pairs with
Inf
s. Coercion of
x
and
y
in this manner is intended for datasets of mode
numeric
, whose elements are
typically small integers; data in the form of
character vectors should first be made into factor or category objects.
TRUE
,
a continuity correction will be applied, but only under certain
conditions. See section DETAILS.
"htest"
, containing the following components:
names
attribute
"McNemar's chi-square"
. See section DETAILS for a definition.
statistic
. Component
parameters
has
names
attribute
"df"
.
x
, and of
y
if both are factor or category objects.
If the contingency table consists of N observations cross-classified
on the row and column variables, which would typically have the
same levels, then McNemar's statistic could be used to test the null
hypothesis of symmetry, namely that the probability of an observation
being classified into cell
[i,j]
is the same as the probability of
being classified into cell
[j,i]
. Fleiss (1981) p. 113 gives an
application of McNemar's test to matched case-control pairs.
The returned
p.value
should be interpreted carefully. Its validity
depends on the assumption that the cell counts are at
least moderately large. Even when cell counts are adequate, the
chi-square is only a large-sample approximation to the true distribution
of McNemar's statistic under the null hypothesis.
Some attention should also be given to the underlying sampling scheme;
see the literature references for examples.
Under the null hypothesis, McNemar's statistic has an
asymptotic chi-square distribution with degrees of freedom
given by
R*(R-1)/2
, where
R
is the number of rows of the
contingency table.
Fleiss, J. L. (1981).
Statistical Methods for Rates and Proportions,
2nd ed. New York: Wiley.
Zar, J. H. (1984).
Biostatistical Analysis,
2nd ed. Englewood Cliffs: Prentice-Hall.
# Data from table Fleiss, p. 114 cases <- factor(rep(c(1,2,1,2), c(15,5,20,60)), labels=c("Present", "Absent")) controls <- factor(rep(c(1,2), c(20,80)), labels=c("Present", "Absent")) table(cases, controls) mcnemar.test(cases, controls) mcnemar.test(table(cases, controls)) # same thing