[R-sig-ME] Plotting interactions while controlling for other predictors.
Walid Mawass
w@lidm@w@@@10 @ending from gm@il@com
Wed Dec 12 18:05:23 CET 2018
Hi,
The package 'effects' is a good tool for this sort of thing. It let's you
plot the effect of the interaction term from a regression model while
controlling for other predictors by using the mean value for each other
variable by default while plotting the predictions for the interaction term
based on the model.
Hope this helps.
--
Walid Mawass
Ph.D. candidate in Cellular and Molecular Biology
Population Genetics Laboratory
University of Québec at Trois-Rivières
3351, boul. des Forges, C.P. 500
Trois-Rivières (Québec) G9A 5H7
Telephone: 819-376-5011 poste 3384
On Wed, Dec 12, 2018, 11:51 AM David Sidhu <dsidhu using ucalgary.ca wrote:
> 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.
> Dave
>
> set.seed(182)
> require(data.table)
> require(lme4)
> require(ggplot2)
>
> 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)
> library(ggplot2)
> 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
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list