I have performed a logistic regression with the following variables:

  • X: Categorical with three levels (St, An, Int)
  • M: Moderator, which has two levels (Mob,Desk)
  • Y: Dichotomous dependent variable (0/1)

I found no main effect of X on Y or of M on Y but I did find a significant interaction effect between level 'Int' of X with M.

Hence, I want to show a graph in which I show the cross over interaction but I can't figure out how.

I already read this question (Plotting logistic regression interaction (categorical) in R) but I couldn't rewrite this to my own dataset.

PS: I am using R in case anyone would kindly like to provide an example.


There could be many ways. One of them is to compute the predicted odds, and turn that into probability for each possible combination between X and M. Here is a short example:


x <- as.factor(sample(c(1,2,3), 100, replace=T))
m <- as.factor(sample(c(1,1,2,2,2), 100, replace=T))
y <- sample(c(1,0), 100, replace=T)

m1 <- glm(y ~ x*m, family=binomial)

possibleCombo=data.frame(x = c(1,2,3,1,2,3), m = c(1,1,1,2,2,2))

yhatProb <- predict(m1, possibleCombo, type="response")*100

possibleCombo <- data.frame(possibleCombo,yhatProb)

p1 <- ggplot(possibleCombo, aes(factor(x),yhatProb)) + 
      geom_bar(aes(fill=factor(m)), position="dodge", stat="identity")

The result looks something like this:

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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