I am very familiar with logistic regression. I have used logistic regression with data sets in which each set up independent variables has a binary (1 or 0) dependent variable. However, I have found much discussion of logistic regression as an alternative to a Cochran-Mantel-Haenszel (CMH) test. The CMH test takes 2x2xK contingency tables and test whether or not the odds ratio between the K-levels is different from 1.

Can logistic regression be run on 3-dimensional contingency tables, without attempting to split the counts within the contingency table into a normal data frame? Is there logic to do this in R?

Below is an example of a 2x2xK subsection where K = 1. You can see why I would not want to have 15,511 rows that all have the same information (K = 1, Female, No Damages) and would rather keep in this clean format.

            Response for K = 1
Family         Damages   No Damages
  Male         10        245
  Female       533       15511
  • $\begingroup$ Assuming Damages is your response and Family and K are your predictors then why not use glm? If you want specific code perhaps another site would be better as this is more of a programming than a statistical issue, you already know what statistical technique you want to use. $\endgroup$
    – mdewey
    Aug 1, 2017 at 14:41
  • $\begingroup$ I would then have to create 16,299 rows which would be quite redundant. I have read statistical papers and presentations that mention that the process of using a contingency table as I have laid out can be used within the structure of a logistic regression model and was hoping to do that and understand the formulation of this model. @mdewey $\endgroup$
    – a.powell
    Aug 1, 2017 at 15:09
  • $\begingroup$ There is absolutely no way you need 16000+ rows per value of K. You just need two each containing the two cell entries (or one of them and the total) and the values of whatever covariates you need.. $\endgroup$
    – mdewey
    Aug 1, 2017 at 15:27
  • $\begingroup$ One of us is confused. I'm thinking of the "damages" as my binary variable. Maybe you could give me an example of what you mean @mdewey $\endgroup$
    – a.powell
    Aug 1, 2017 at 17:10
  • $\begingroup$ From the documentation of glm "For binomial and quasibinomial families the response can also be specified as a factor (when the first level denotes failure and all others success) or as a two-column matrix with the columns giving the numbers of successes and failures." $\endgroup$
    – mdewey
    Aug 1, 2017 at 17:13

1 Answer 1


Was able to answer my own question for those interested.

    model <- glm(cbind(Damages, No_Damages) ~ Family + Response, 
data = df, family = binomial(link = 'logit'))

The cbind format allowed me to keep in two-way format.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.