After variable selection I usually end up in a model with a numerical covariable (2nd or 3rd degree). What I want to do is to plot using emmeans
package preferentially. Is there a way of doing it?
I can do it using predict
:
m1 <- lm(mpg ~ poly(disp,2), data = mtcars)
df <- cbind(disp = mtcars$disp, predict.lm(m1, interval = "confidence"))
df <- as.data.frame(df)
ggplot(data = df, aes(x = disp, y = fit)) +
geom_line() +
geom_ribbon(aes(ymin = lwr, ymax = upr, x = disp, y = fit),alpha = 0.2)
I didn't figured out a way of doing it using emmip
neither emtrends
For illustration purposes, how could I do it using mixed models via lme
?
m1 <- lme(mpg ~ poly(disp,2), random = ~1|factor(am), data = mtcars)