# Logistic Regression for 2x2xK data

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

• 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. – mdewey Aug 1 '17 at 14:41
• 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 – a.powell Aug 1 '17 at 15:09
• 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.. – mdewey Aug 1 '17 at 15:27
• 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 – a.powell Aug 1 '17 at 17:10
• 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." – mdewey Aug 1 '17 at 17:13

    model <- glm(cbind(Damages, No_Damages) ~ Family + Response,

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