I have a model with a factor and a continuous covariate, and an ANOVA indicates the main effects of both the factor and covariate are significant (P<0.05), but the interaction is not (P>0.05). The factor has two levels.
To report the results, I used emmeans to extract the model estimates across the range of the covariate, for both levels of the factor. From this I created a plot that showed a different slope for each level of the factor, while I stated in the text this difference in slopes was not significant. Here is a simple made up example:
x<-c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
y<-c(1,1.8,3,1.8,0.7,2,2.7,4,0.8,1.2,1.4,1.6,0.7,1.4,1.6,2.1)
f<-c("a","a","a","a","a","a","a","a","b","b","b","b","b","b","b","b")
df<-data.frame(x,f,y)
m<-lm(y~x*f)
anova(m)
plot.df<-data.frame(emmeans(m,~x*f,cov.reduce=F))
ggplot(plot.df,aes(x=x,y=emmean,colour=f,fill=f))+
geom_line()+
geom_ribbon(aes(ymin=lower.CL,ymax=upper.CL),colour=NA,alpha=0.2)
My colleague came back to me and said it is confusing to see different slopes in the plot when they are not significant in the ANOVA (in our real data the slope difference is bigger than my little example). I thought, okay then, I must be able to get the main effects averaged across the interactions, i.e. to plot the same slope at different intercepts for each factor level ... but I can't work out how to do this ... and now I am wondering if maybe it's not easy because it's not the right thing to do.
So I don't know if I need:
- help with using
emmeans
(or a similar function) to extract the main effects only? - advice on whether it even makes sense to extract the main effects only? (and if not, what to do instead?)
I have tried the below but it makes no difference:
plot.df<-data.frame(emmeans(m,~x+f,cov.reduce=F))
Update: After a chat with a statistician colleague, I posed a similar question on how to do this with predict.lm()
, without reference to emmeans or statistical validity. It turns out it is possible with predict.lm()
(and for what it's worth, my stats colleague sees no problem with the concept):
How to edit interactions in model matrix used by predict.lm()?