Basically I have a mixed-effect model with 2 predictors, an interaction term and a random effect that looks like this:
x1<-abs(rnorm(300)) #continuous variable
x2<-sample(c(1,2,3), 300, replace = T) #discrete variable
x3<-sample(c("A","B","C"), 300, replace = T) #categorical variable
y<-abs(rnorm(300)) #continuous variable
df<-as.data.frame(cbind(as.numeric(x1),as.numeric(x2),x3,as.numeric(y)))
m1=lmer(y~x1*x2+(1|x3),data=df)
summary(m1)
I used lme4 to create such a model. I want to find the marginal effect of x1 on y (the beta coefficient) at different levels of x2 (which is a factor with 3 levels).
I would also like to get the confidence interval of beta at each level and plot such results.
You may want to try the
marginaleffects
package. (Disclaimer: I am the maintainer.)