Lets say I have data of the following format in R:

group <- sample.int(4, size=50, replace=T)
endorsement <- sample(c(0,1), size=50, replace=T)
df <- data.frame(group, endorsement)


> head(df)
 group endorsement
     1           0
     3           1
     4           0
     2           1
     2           1
     2           1

Each row represents an individual. group is a grouping variable that indicates their membership in 1 of 4 groups. endorsement is whether that individual endorses a particular item

My goal is to determine:

  1. Whether there is an overall effect of group, which would indicate whether theres a difference between the groups with regards to how much they each endorse the item. This would be analogous to a main effect in ANOVA
  2. Given a significant main effect, which pairwise differences between groups are significant? Analogous to a post-hoc test like Tukey's HSD

I understand the analysis I want to do from an ANOVA perspective, however, the ANOVA model doesn't quite fit when I have a binary DV

My first question is, if I were to use an ANOVA for binary data, what negative effect would that have on my inference and interpretation?

Ive thought about using logistic regression for this given the binary response:

glm(endorsement ~ factor(group), data=df, family=binomial(logit))

However, when running a GLM model in R I dont get an F test for what would be the overall main effect of group so I can't accomplish goal #1 above

I've also thought about running a chi-square test with count data for each group and compare the count distribution against a null distribution where each group has the same count. This, I believe, would give me something analogous to a main effect of group but I'm not sure how I would then go on to compute pairwise differences between each group to accomplish goal #2

So my second question is, what technique could I use that would allow me to accomplish both goals when my response is binary?

  • $\begingroup$ use summary(glm(endorsement ~ ...)) to get the p-value for the main effect. $\endgroup$ Mar 11, 2017 at 8:12
  • $\begingroup$ summary() doesnt provide a main effect F test for glm models, only for regular lm $\endgroup$
    – Simon
    Mar 11, 2017 at 8:15

1 Answer 1


Try this:

model <- glm(endorsement ~ factor(group), data=df, family=binomial(logit))


This creates an analysis of deviance table which is like an anova table but it uses a chi-square test.

For the comparisons:

lsmeans(model, pairwise ~ group)                      # on the logit scale
lsmeans(model, pairwise ~ group, type = "response")   # on the probability scale

The comparisons in the 2nd call are actually in terms of odds ratios (as will be shown in annotations below the output), because the differences of logits (1st lsmeans call) are back-transformed from the log scale.

  • $\begingroup$ Ive never seen analysis of deviance before, what is the (null) hypothesis being tested in this case? i.e. how would I interpret the results of the chi square test? $\endgroup$
    – Simon
    Mar 13, 2017 at 1:33
  • $\begingroup$ I think we are at the point of having led you in the right direction. $\endgroup$
    – Russ Lenth
    Mar 13, 2017 at 2:51

Your Answer

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

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