[R] R equivalent of SAS Cochran-Mantel-Haenszel tests?
In SAS, for a two-way (or 3-way, stratified) table, the CMH option in SAS PROC FREQ gives 3 tests that take ordinality of the factors into account, for both variables, just the column variable or neither. Is there an equivalent in R? The mantelhaen.test in stats gives something quite different (a test of conditional independence for *nominal* factors in a 3-way table). e.g. I'd like to reproduce: *-- CMH tests; proc freq data=sexfun order=data; weight count; tables husband * wife / cmh chisq nocol norow; run; The FREQ Procedure Summary Statistics for Husband by Wife Cochran-Mantel-Haenszel Statistics (Based on Table Scores) StatisticAlternative HypothesisDF Value Prob 1Nonzero Correlation1 10.01420.0016 2Row Mean Scores Differ 3 12.56810.0057 3General Association9 16.76890.0525 -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R equivalent of SAS Cochran-Mantel-Haenszel tests?
Dear Michael, It sounds as a linear-by-linear loglinear model (and its variants) which uses scores for one or more variables in the table.. (see Agresti, 1990, Categorical Data Analysis. I do remember the pages and I have not the book here..) If this is the case, you can use standard call to glm(.., family=poisson) with score variables in the linear predictor. For instance for a two-way table with ordered variables the linear-by-linear model is, glm(freq~factor(x)+factor(y)+I(score.x*score.y), family=poisson) The CMH test, probably, is the score test of the parameter of I(score.x*score.y).. best, vito Michael Friendly ha scritto: In SAS, for a two-way (or 3-way, stratified) table, the CMH option in SAS PROC FREQ gives 3 tests that take ordinality of the factors into account, for both variables, just the column variable or neither. Is there an equivalent in R? The mantelhaen.test in stats gives something quite different (a test of conditional independence for *nominal* factors in a 3-way table). e.g. I'd like to reproduce: *-- CMH tests; proc freq data=sexfun order=data; weight count; tables husband * wife / cmh chisq nocol norow; run; The FREQ Procedure Summary Statistics for Husband by Wife Cochran-Mantel-Haenszel Statistics (Based on Table Scores) StatisticAlternative HypothesisDF Value Prob 1Nonzero Correlation1 10.01420.0016 2Row Mean Scores Differ 3 12.56810.0057 3General Association9 16.76890.0525 -- Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' UniversitĂ di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 6626240 fax: 091 485726/485612 http://dssm.unipa.it/vmuggeo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R equivalent of SAS Cochran-Mantel-Haenszel tests?
Dear Vito, Yes, these tests are *similar* in spirit to loglinear models using either row/col/both scores for the association. But I'm still looking for something equivalent to give the same results as SAS with CMH for non-parametric tests. One advantage of the CMH tests is that for stratified tables, a largish sample size is not required in the individual strata, only the total n. The computations are described in: http://support.sas.com/onlinedoc/913/getDoc/en/procstat.hlp/freq_sect27.htm vito muggeo wrote: Dear Michael, It sounds as a linear-by-linear loglinear model (and its variants) which uses scores for one or more variables in the table.. (see Agresti, 1990, Categorical Data Analysis. I do remember the pages and I have not the book here..) If this is the case, you can use standard call to glm(.., family=poisson) with score variables in the linear predictor. For instance for a two-way table with ordered variables the linear-by-linear model is, glm(freq~factor(x)+factor(y)+I(score.x*score.y), family=poisson) The CMH test, probably, is the score test of the parameter of I(score.x*score.y).. best, vito Michael Friendly ha scritto: In SAS, for a two-way (or 3-way, stratified) table, the CMH option in SAS PROC FREQ gives 3 tests that take ordinality of the factors into account, for both variables, just the column variable or neither. Is there an equivalent in R? The mantelhaen.test in stats gives something quite different (a test of conditional independence for *nominal* factors in a 3-way table). e.g. I'd like to reproduce: *-- CMH tests; proc freq data=sexfun order=data; weight count; tables husband * wife / cmh chisq nocol norow; run; The FREQ Procedure Summary Statistics for Husband by Wife Cochran-Mantel-Haenszel Statistics (Based on Table Scores) StatisticAlternative HypothesisDF Value Prob 1Nonzero Correlation1 10.01420.0016 2Row Mean Scores Differ 3 12.56810.0057 3General Association9 16.76890.0525 -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R equivalent of SAS Cochran-Mantel-Haenszel tests?
How about 'cmh_test' in the coin package? From the PDF: The null hypothesis of the independence of y and x is tested, block defines an optional factor for stratification. chisq_test implements Pearson’s chi-squared test, cmh_test the Cochran-Mantel-Haenzsel test and lbl_test the linear-by-linear association test for ordered data. David Freedman Michael Friendly wrote: In SAS, for a two-way (or 3-way, stratified) table, the CMH option in SAS PROC FREQ gives 3 tests that take ordinality of the factors into account, for both variables, just the column variable or neither. Is there an equivalent in R? The mantelhaen.test in stats gives something quite different (a test of conditional independence for *nominal* factors in a 3-way table). e.g. I'd like to reproduce: *-- CMH tests; proc freq data=sexfun order=data; weight count; tables husband * wife / cmh chisq nocol norow; run; The FREQ Procedure Summary Statistics for Husband by Wife Cochran-Mantel-Haenszel Statistics (Based on Table Scores) StatisticAlternative HypothesisDF Value Prob 1Nonzero Correlation1 10.01420.0016 2Row Mean Scores Differ 3 12.56810.0057 3General Association9 16.76890.0525 -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/R-equivalent-of-SAS-Cochran-Mantel-Haenszel-tests--tp21914012p21918306.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.