mcnemar.test(x, y = NULL, correct = TRUE)
x |
a factor or a two-dimensional contingency table in matrix form.
If x is a matrix, it must be square and contain at least two
rows and two columns. All elements of the matrix must be non-negative,
and not contain any missing values (NAs) or infinite values
(Infs). Since the test uses counts, the elements should be
whole numbers, however, the function coerces the storage mode of the
matrix to double and, where possible, the function carries out
computations to double precision accuracy. |
y |
a factor object. If x is a matrix, y is ignored.
If x is a factor object, y is required and length(x) must equal length(y). Both objects must contain more than two levels and have the same number of levels as the other object. The index vectors can contain missing values (NAs), but if both elements in a pair ((x[i],y[i])) are missing values (NAs), they are 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, a missing value (NA) in an index vector means that the observation is not in one of the groups listed for that factor object. Infinite values Infs have no meaning as indices, and should not be present. If x or y is not a factor object (and x is not a matrix), it is implicitly coerced to a factor object. In this case, pairs ((x[i],y[i])) that contain missing values (NAs) are removed, but not pairs with infinite values (Infs). Coercion of x and y in this manner is intended for datasets of mode numeric, whose elements are typically small integers; you should convert data in the form of character vectors into factor objects before using them in this function. |
correct | a logical value. If TRUE, a continuity correction will be applied, but only under certain conditions. |
statistic | McNemar's statistic along with the names attribute "McNemar's chi-squared". |
parameters | degrees of freedom of the asymptotic chi-square distribution associated with statistic along with the names attribute df. |
p.value | asymptotic p-value for the test. |
method | a character string that returns the name of the method used, including whether the continuity correction was applied. |
data.name | a character string (vector of length 1) that contains the actual name of the input argument x, and of y if both are factor objects. |
R * (R - 1) / 2 |
where R is the number of rows of the contingency table. |
# 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 thingmcnemar.test(cases, controls, correct = FALSE) mcnemar.test(matrix(c(6,3,5,8,2,9,1,7,4), nrow = 3)) # matrix input