This question already has an answer here:
I would like to know how to make quickly pairwise comparisons of regressions coefficients across three or more groups in R. Here is a small example:
library(car) data(iris) scatterplot(Sepal.Width~Sepal.Length | Species, regLine=TRUE, smooth=FALSE, boxplots=FALSE, by.groups=TRUE, data=iris)
As you can see here, two groups seem to have approximately the same regression coefficients, whereas the third one exhibits a clearly different relationship between the two variables. I can make an Ancova, for example like this:
modComplete <- lm(Sepal.Width ~ -1 + Species + Species:Sepal.Length, data=iris) modSimple <- lm(Sepal.Width ~ Sepal.Length, data=iris) anova(modComplete, modSimple)
However, this only tells me that at least two groups differ, and I have no information about pairwise comparisons. I would like to know if there are significantly different regression coefficients between each pair of groups. I think that it could be done using the function
multcomp::glht but I am not familiar with it, and the help page is a little confusing to me.
Is there a quick way to do this?