Cochran–Mantel–Haenszel test in R and Interpretation – R tutorial


R provides several methods of testing the independence of the categorical variables. In my tutorial, I will show three tests such as the chi-square test of independence, the Fisher exact test, and the Cochran-Mantel–Haenszel test. This article shows you about Cochran–Mantel–Haenszel test in R and how to interpret the results.

The Cochran–Mantel–Haenszel test is an extension of the chi-square test of association. This test is used to examine the significance of the association two nominal variables if they are conditionally independent in each stratum of a third variable.

The function mantelhean.test() is used to perform this operation. I will show an example with builtin data on vcd package. You can always import data into R using CSV, Excel or SPSS data file. Also, we will see how to interpret the results of the Cochran–Mantel–Haenszel test.

Hypotheses of Cochran–Mantel–Haenszel test

Null hypothesis – There is no association between the two inner variables.

Alternative hypothesis – There is an association between the two inner variables.

Let us see an example now.


To install vcd package use the command install.packages("vcd"). Then use the following code to performs the test in R.

> library(vcd)
> mantelhaen.test(Arthritis$Treatment,Arthritis$Improved,Arthritis$Sex)

        Cochran-Mantel-Haenszel test

data:  Arthritis$Treatment and Arthritis$Improved and Arthritis$Sex
Cochran-Mantel-Haenszel M^2 = 14.632, df = 2, p-value = 0.0006647

The above code tests the hypothesis that Treatment and Improved variables are independent within each level Sex. The test assumes that there’s no three-way (Treatment x Improved x Sex) interaction.

The results suggest that the treatment received and the improvement reported aren’t independent within each level of sex (that is, treated individuals improved more than those receiving placebos when controlling for sex). We come to this conclusion because the p-value is less than 0.01. i.e, p < 0.01. Hence, we reject the null hypothesis and accept the alternative hypothesis.

So, this is how you can perform a Cochran-Mantel–Haenszel test in R and interpret the result.

Previous articleFisher’s exact test in R and Interpretation – R tutorial
Next articleAll key Financial Ratios and its types with simple Examples
A.Sulthan, Ph.D.,
Author and Assistant Professor in Finance, Ardent fan of Arsenal FC. Always believe "The only good is knowledge and the only evil is ignorance - Socrates"
Notify of
Inline Feedbacks
View all comments