[R-sig-ME] Plotting interactions while controlling for other predictors.
guill@ume@imon@@2 @ending from gm@il@com
Wed Dec 12 18:06:49 CET 2018
For plotting interactions between two continuous variables, maybe a gamm
model might be more adapted?
However, by defaut, in the visreg package, you can facet one of your
continuous variables (which is subsetted relative to its distribution) and
plot the other one accordingly.
This would be coded the following way: visreg(m1, X2, by="X3")
#overlay=TRUE to have them all combined in one plot, partial=TRUE to have
the partial residuals (which do not include RE by default), by default X1
will be fixed to its median
This will produce a conditional plot in which all random effects (or X1 in
this case) are fixed at a certain level (you can also fix this at a
particular value with cond=list(X1=XXXX) ).
Nevertheless, this simply calls for predict.lmer(). It is still pretty
Hope this helps.
Le mer. 12 déc. 2018 à 17:51, David Sidhu <dsidhu using ucalgary.ca> a écrit :
> I am interested in creating a plot of an interaction that accounts for
> other variables present in a model.
> I am attaching a reproducible example of my try so far, but I don’t
> believe this is quite getting at what I’d like.
> Essentially, I want to show the interaction between X2 and X3, while
> controlling for X1.
> Thank you very much.
> X1 = rnorm(1000)
> X2 = rnorm(1000)
> X3 = sample(1:3, size = 1000, replace = TRUE)
> X3 <- as.factor(X3)
> DV = rnorm(1000)
> Item <- rep(1:10, times = 100)
> Subject <- rep(1:100, each = 10)
> d <- as.data.frame(cbind(X1, X2, X3, DV, Item, Subject))
> m1 <- lmer(DV ~ X1 + X2*X3 + (1|Subject) + (1|Item), data = d)
> d$Pred <- predict(m1)
> ggplot(d, aes(x = X2, y = Pred, col = factor(X3), group = X3)) +
> geom_jitter(alpha = .2) + geom_smooth(method = "lm")
> David M. Sidhu, MSc
> PhD Candidate
> Department of Psychology
> University of Calgary
> R-sig-mixed-models using r-project.org mailing list
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models