mantelhaen.test
Mantel-Haenszel Chi-Square Test for Count Data

Description

Performs a Mantel-Haenszel chi-square test on a three-dimensional contingency table.

Usage

mantelhaen.test(x, y = NULL, z = NULL, alternative = c("two.sided", "less", "greater"), 
    correct = TRUE, exact = FALSE, conf.level = 0.95)

Arguments

x a factor or an array. If x is:
  • a factor, it should have at least two levels.
  • an array, it should be a three-dimension contingency table, and each dimension should have at least two levels where the last dimension corresponds to the strata.
y,z a factor object with at least two levels.
  • If x is an array, y and z are ignored.
  • If x is a factor or object, y and z are required and must have the same length as x. Factors x and y must each have exactly two levels. Missing values (NA)s in the factor index vectors are allowed, but triplets (x[i],y[i],z[i]) that contain an NA are removed. Each element of the index vectors of x, y, and z 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 factor object. Infs have no meaning as indices, and should not be present.
  • If x is not an array and any of x, y, or z are not either a factor object it will be coerced to one implicitly. In this case, triplets (x[i],y[i],z[i]) that contain an NA are removed, but Infs are not removed. Coercion of x, y, and z in this manner is intended for datasets of mode numeric, whose elements are typically small integers.
You should coerce data in the form of character vectors into either factors objects before you use this function.
alternative a character string that specifies the alternative hypothesis but is only used when data is a three-dimension table of dim with 2 by 2 by K. To test the hypothesis, type one of the following:

  • two.sided
  • greater
  • less
Note: You only need to enter enough of the character string to create a unique match for the value.
correct a logical value. If TRUE, a continuity correction is applied when the test statistic is calculated, only used when data is a three-dimension table of dim with 2 by 2 by K.
exact a logical value. If TRUE, exact conditional test is computed. Otherwise, Mantel-Haenszel test is computed. Only used when data is a three-dimension table of dim with 2 by 2 by K.
conf.level a numeric vector in the range [0, 1] that specifies the confidence level for the returned confidence interval. Only used when data is a three-dimension table of dim with 2 by 2 by K.
Value
returns a list of class htest, containing the following components:
statistic Mantel-Haenszel statistic (chi-squared form).

When data has dimension 2 by 2 by K:

  • if exact = FALSE, the return value is the result of the Mantel-Haenszel chi-squared statistic and it is returned with the names attribute Mantel-Haenszel X-squared.
  • if exact = TRUE, the return value is the result of x[1,1,] and it is returned with the names attribute "S".
When data is not dimension 2 by 2 by K, the return value is the result of the generalized Cochran-Mantel-Haenszel statistic and it is returned with the names attribute Cochran-Mantel-Haenszel M^2.
parameters degrees of freedom of the asymptotic chi-square distribution associated with statistic along with the names attribute df. This value is not returned when you specify a value for the exact argument.
p.value asymptotic p-value for the test.
method a character string for the name of the method used for the calculation, including whether the continuity correction was applied.
data.name a character string (vector of length 1) that contains the name of the input argument x, and the names of y and z if provided.
conf.int a confidence interval. Only returned when data is with dimension 2 by 2 by K.
estimate an estimate of the common odds ratio when the data has the dimensions of 2 by 2 by K. When you provide a value for the exact argument, the return value is the conditional Maximum Likelihood Estimate. In all other cases, the return value is the Mantel-Haenszel estimate.
null.value common odds ratio under the null of independence. Its value is always 1, with name attribute common odds ratio. Only present when data is with dimension 2 by 2 by K.
alternative a character string that returns the alternative hypothesis (two.sided, greater, or less) as specified in the alternative argument. This value is only returned when the data contains a three-dimension table of dimension if 2 by 2 by K.
Null hypothesis
Under the null hypothesis, the Mantel-Haenszel statistic has an asymptotic chi-square distribution with one degree of freedom. A typical application of the Mantel-Haenszel statistic is to test the null hypothesis that there is no interaction between the variables corresponding to the categories x and y at any of the levels of z. This amounts to conditional independence of the x and y variables. Bishop, Fienberg and Holland (1980) caution against using the Mantel-Haenszel statistic to test this hypothesis when the magnitude of the interaction between x and y varies with z; it should first be established that this three-way interaction is zero.
Test assumptions
Use caution when you interpret the returned p.value. Its validity depends on the assumption that certain sums of expected cell counts are at least moderately large, for guidelines see Fleiss (1981), p. 175. Even when cell counts are adequate, the chi-square is only a large-sample approximation to the true distribution of the Mantel-Haenszel statistic under the null hypothesis. Some attention should also be given to the underlying sampling scheme, for examples see Fleiss (1981) and Bishop, Fienberg and Holland (1980).
References
Bishop, Y. M. M., Fienberg, S. J., and Holland, P. W. (1980). Discrete Multivariate Analysis: Theory and Practice, Cambridge, Mass.: The MIT Press.
Fleiss, J. L. (1981). Statistical Methods for Rates and Proportions, 2nd ed. New York: Wiley.
Snedecor, G. W. and Cochran, W. G. (1980). Statistical Methods, 7th ed. Ames, Iowa: Iowa State University Press.
See Also
fisher.test, chisq.test, mcnemar.test, cut, table.
Examples
# Data from Bishop, Fienberg, Holland, p. 148, response to chemotherapy
x <- factor(rep(c(1,2,1,2), c(3,10,15,2)),
     labels=c("NoResponse", "Reponse"))
y <- factor(rep(c(1,2,1,2,1,2,1,2), c(1,2,4,6,12,3,1,1)),
     labels=c("Male", "Female"))
z <- factor(rep(c(1,2), c(13,17)),
     labels=c("Nodular", "Diffuse"))
table(x,y,z)

mantelhaen.test(x,y,z)

mantelhaen.test(table(x,y,z)) # same thing

Package stats version 6.0.0-69
Package Index