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, correct=T)

REQUIRED ARGUMENTS:
x:
either a factor, a category object or a three-dimensional contingency table in array form. If x is an array, the dim(x)[3] subtables must each have dimension 2 by 2, all elements of x must be non-negative. NAs and Infs are not allowed. The elements of array 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 array x will be coerced to "double". For restrictions on x when it is a factor or category object, see argument y.

OPTIONAL ARGUMENTS:
y,z:
factors or category objects. If x is an array, y and z are ignored. If x is a factor or a category object, y and z are required and must have the same length as x. Factors x and y must each have exactly two levels. NAs in the factor/category index vectors are allowed, but triplets (x[i],y[i],z[i]) containing these will be 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/category object. Infs have no meaning as indices, and should not be present.

Conversely, if x, y or z is not a factor or a category object (and x is not an array), it will be coerced to one implicitly. In this case triplets (x[i],y[i],z[i]) containing NAs and will be removed, but not those with Infs. Coercion of x, y and z 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 either factors or category objects.

correct:
logical flag: if TRUE, a continuity correction will be applied, but only under certain conditions. See section DETAILS.

VALUE:
A list of class "htest", containing the following components:

statistic:
the Mantel-Haenszel statistic (chi-squared form), with names attribute "Mantel-Haenszel chi-square". See section DETAILS for a definition.
parameters:
always 1, the degrees of freedom of the asymptotic chi-square distribution associated with statistic. Component parameters has names attribute "df".
p.value:
the asymptotic p-value for the test.
method:
character string giving the name of the method used, including whether the continuity correction was applied.
data.name:
a character string (vector of length 1) containing the actual name of the input argument x, and of y and z if all three are factor or category objects.


NULL:
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:
The returned p.value should be interpreted carefully. Its validity depends on the assumption that certain sums of expected cell counts are at least moderately large; see Fleiss (1981), p. 175 for guidelines. 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; see Fleiss (1981) and Bishop, Fienberg and Holland (1980) for examples.

DETAILS:
See the hardcopy help-file for an algebraic definition of the statistic.

Under the null hypothesis, the Mantel-Haenszel statistic has an asymptotic chi-square distribution with one degree of freedom.


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 , category , cut , table .

EXAMPLES:
x        # x, y and z are category objects
[1] 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2
attr(, "levels"):
[1] "No Response" "Response"
table(x,y,z)        # table from Bishop, Fienberg, Holland, p. 148
, , Nodular
            Male Female
No Response    1      2
   Response    4      6
, , Diffuse
            Male Female
No Response   12      3
   Response    1      1
mantelhaen.test(x,y,z)
mantelhaen.test(table(x,y,z))        # same thing