# Linear model with interaction - pairwise comparison

I have the following model in R:

lme(log_weight ~ log_weight0 + Group*Day, random = ~ 1 | ID, data = mydata)


The interaction term is significant. I would like to compare the Groups pairwise but in "overall" not separately for each Day. So I can see if there is significant difference between Group1 and Group2, or Group1 and Group3, etc. How can I perform it? Is it possible at all?

• Yes, I am familiar with emmeans package. The question is more about theory, can I compare only groups without day if they are in interaction in the model? When I am running the emmeans it says: "NOTE: Results may be misleading due to involvement in interactions". Commented Jul 25 at 13:21
• ¿Can you clarify what you are investigating? The reason I ask is because if you want to know if the groups are different from each other, then a significant interaction term indicates that yes...they are different. Commented Jul 25 at 13:23
• I have four different treatment groups, and I would like to perform pairwise comparisons to determine if there are significant differences in weight between each pair of groups. Based on the significance of interaction term I do not know which groups are differ. Commented Jul 25 at 13:28

## Why pairwise comparisons result in a warning

Suppose you have a model like this:

LM <- lm(Petal.Length ~ Species * Petal.Width, iris)


You want to compare the groups, but your model has an interaction. When you use emmeans, you are asking for an overall difference in groups. This causes the following warning:

require("emmeans")
EMM <- emmeans(LM, pairwise ~ Species)
# NOTE: Results may be misleading due to involvement in interactions


To understand why this isn't a valid question to ask, try plotting your model and see what happens:

require("sjPlot")
plot_model(LM, type = "pred", terms = c("Petal.Width", "Species"))


Where should you evaluate this 'overall' difference? At the intercept, the difference is not the same as at Petal.Width == 1, or the average Petal.Width, etc.

## Alternative(s)

What you can do instead, is:

• If there is practically no difference in slopes, simplify your model to one without an interaction.
• Compute pairwise differences in estimated slopes.

The latter is also supported by the emmeans package, using the function emtrends:

EMT <- emtrends(LM, pairwise ~ Species, var = "Petal.Width")
EMT\$contrasts

#  contrast               estimate    SE  df t.ratio p.value
#  setosa - versicolor      -1.323 0.555 144  -2.382  0.0483
#  setosa - virginica       -0.101 0.525 144  -0.192  0.9799
#  versicolor - virginica    1.222 0.322 144   3.798  0.0006
#
# P value adjustment: tukey method for comparing a family of 3 estimates

• thank you, this is exactly what I was looking for! Commented Jul 26 at 6:15
• I'm curious about how to perform a comparison when both of my explanatory variables are factors (e.g., Day*Group, with Day being a factor). I can do separate pairwise comparisons for each distinct day, but is it possible to evaluate an "overall" difference? Or is it meaningless to make comparisons separately by day and then look for an overall difference? Commented Jul 30 at 9:51