# Why does SAS Cochran-Mantel-Haenszel seems different than others?

I've been asked to compute a Cochran-Mantel-Haenszel (CMH) Test on 2 variables :

• one is an ordered factor from quantiles of a numeric value ("Q1", "Q2", "Q3", "Q4")
• the other is an unordered factor from groups of a character value ("group A", "group B", "group C").

Both variables are usual values (columns) for a high number of observations (lines).

Based on the little Wikipedia page and the Biostat Handbook, I tried to understand what the CMH test is and here is what I understood :

Cochran–Mantel–Haenszel test for repeated tests of independence : Use the Cochran–Mantel–Haenszel test when you have data from 2×2 tables that you've repeated at different times or locations.

Then it seems it should be done over 3 factors : lines, cols and stratas :

There are three nominal variables: the two variables of the 2×2 test of independence, and the third nominal variable that identifies the repeats.

Indeed, in R, the mantelhaen.test {stats} function need 3 factors or a 3 dimensions array which makes sense.

On the other hand, in SAS, you can easily write a 2 factors CMH test :

PROC FREQ data=MY_DATA;
TABLE VAR1 * VAR2 /CMH; /*or /CHISQ, which give the first MH pvalue too*/
RUN;


The SAS documentation is not crystal clear about it, and examples are maid over 3 factors, but this 2 dimensions test runs normally and give you 3 statistics and p-values, including a "correlation" one. All stats and pvalues are different from a standard chisquare test.

This SAS doc link gives another definition of the CMH (sorry no anchor, search for "Mantel-Haenszel"), which is not what I understood from wikipedia. It states that :

The Mantel-Haenszel chi-square statistic tests the alternative hypothesis that there is a linear association between the row variable and the column variable. Both variables must lie on an ordinal scale.

I have to compute the CMH test with both R and SAS but I want to know what I am doing.

Thus, my questions are :

• Is the SAS definition of CMH test correct ? If not, how can a big enterprise like SAS can afford to play like this ?
• Can I reproduce it in R ? If yes, is the mantelhaen.test function adapted and why can't I put only 2 variables ?
• What SAS is calling the CMH test is called the Cochran test of trend by many other authors.
– DWin
Commented Apr 27, 2021 at 13:24
• What SAS is calling the CMH test is called the Cochran test of trend (or Cochran-Armitage) by many other authors. stats.stackexchange.com/questions/539/… I think Cochran-Armitage is the label used by SPSS, hence its predominance in questions here.
– DWin
Commented Apr 27, 2021 at 13:43

The problem seems to arise because the paper by Cochran and the paper by Mantel extending the paper by Mantel and Haenszel both cover a lot of ground so it is difficult to speak of one test unambiguously as being the CMH test. It is true that most people who call it Mantel-Haenszel mean a method for allowing for stratification of a $2\times2$ contingency table which is what the R function mantelhaen provides and which is discussed in the paper by Mantel and Haenszel. It is also true that in both the Cochran paper and the Mantel paper the issue for using a single degree of freedom test for a linear by linear association in an arbitrary sized contingency table is also discussed.
• Very interesting, thanks ! But then, do you know how to make the SAS CMH test in R ? Also, in a paper, since most people call for stratification CMH, am I allowed to say I made a CMH test when computed with SAS ? Commented Feb 8, 2018 at 15:41
• On SAS output: For the linear-by-linear test, when using proc freq and the cmh1 or cmh options, the test is listed under Cochran-Mantel-Haenszel Statistics. When using the chisq option it is called Mantel-Haenszel chi-square. Commented Oct 11, 2018 at 15:57
• To answer the question by @DanChaltiel, about conducting the linear-by-linear test in R, you can use coin::lbl_test or vcdExtra::CMHtest. There are some examples on SAEPER, my own page, and I'm working on updating this page to include the confusion with the names of this test in R, SAS, and SPSS. Commented Oct 11, 2018 at 16:04