Learn R Programming

lazyWeave (version 3.0.2)

mantel.test: Mantel-Haenszel test for two-way tables

Description

Performs a Mantel-Haenszel test for linear trend in two way tables

Usage

mantel.test(x, byVar, row.scores = c("equal", "midrank"),
  col.scores = c("equal", "midrank"))

Arguments

x

Either a vector of data or a two way table. If a vector is given, it should be a factor variable

byVar

If x is a vector, then byVar is a factor variable to be tabulated against x.

row.scores

choice of scores for the row variable. May be "equal", "midrank", or user defined.

col.scores

Choice of scores for the column variable. May be "equal", "midrank", or user defined.

Value

Returns an object of type htest.

statistic

M^2, a Chi-square statistic with 1 degree of freedom.

parameter

degrees of freedom for M^2

p.value

p-value for the test

method

Type of test performed.

correlation

correlation coefficient of linear trend

Details

Currently, there is no check to ensure that either variables submitted are factors.

Data should be ordinal. Nominal data may not have any practical meaning in this test. Sometimes, when a nominal variable has only two levels, this test may still be appropriate, i.e. Yes vs. No.

In 2xJ tables, when arbitrary scores (i.e., 0, 1) are applied to the rows and midranks applied to the columns, this test is equivalent to the Wilcoxon, or Mann-Whitney test.

In Ix2 tables, when monotone scores are applied to the rows and abitrary scores applied to the columns, this test is equivalent to the Cochran-Armitage test. See the reference for further details.

References

Alan Agresti, An Introduction to Categorical Data Analysis, 1996, pp. 34 - 39.

Examples

Run this code
# NOT RUN {
mantel.test(mtcars$gear,mtcars$cyl)

mantel.test(table(mtcars$gear,mtcars$cyl))

mantel.test(table(mtcars$gear,mtcars$cyl), row.scores="midrank")

mantel.test(table(mtcars$gear,mtcars$cyl), col.scores="midrank")
# }

Run the code above in your browser using DataLab