5
$\begingroup$

I have a linear mixed-effect model in R with two continuous fixed-effects and one random effect, like this:

                           model<-lmer(y~x1+x2+(1|r),data)

To graphically display the independent effect of x1 on y, while controlling the effects of x2 (fixed effect) and r (random effect), is it appropriate to do a partial regression plot using the same logic used for multiple linear regression models? I.e.:

                          #removing the effect of x2 and r on y

                         res.y<-residuals(lmer(y~x2+(1|r),data)) 

                          #removing the effect of x2 and r on x1

                         res.x1<-residuals(lmer(x1~x2+(1|r),data)) 

              #partial regression plot to display the pure effect of x1 on y

                                     plot(res.x1,res.y)

Also, I used the "plotLMER.fnc function" from the "LMERConvenienceFunctions" R package to plot the partial effect size of each fixed effect as follows:

                                      plotLMER.fnc(model) 

However, I am not sure what this package means by "effect size". Is it β1 and β2?

I will be very grateful for any help in this issue.

$\endgroup$
2
  • $\begingroup$ You might be better on an R-specific site like R-help or asking the package maintainer. $\endgroup$
    – mdewey
    Commented Jan 26, 2017 at 15:00
  • $\begingroup$ Please provide some example data. $\endgroup$ Commented Jan 26, 2017 at 15:11

2 Answers 2

3
$\begingroup$

You can use the remef package to prepare data for the visualization of partial effects. The package can be installed with devtools.

install.packages("devtools")
devtools::install_github("hohenstein/remef")

To remove the influece of x2 and the random effects from the dependent variable, you can use

library(remef)
y_partial <- remef(model, fix = "x2", ran = "all")

This will create a modified version of y based on the partial effect while the residuals are still present. Hence, you can still visualize the deviations from the predictions.

With the adjusted data y_partial you can, for example, create a plot of y_partial as a function of x1 together with a linear regression line.


Disclaimer: I am the author of the remef package

$\endgroup$
2
  • $\begingroup$ It worked, thanks a lot! Is there a code to compute the partial R^2? $\endgroup$ Commented Jan 27, 2017 at 12:53
  • $\begingroup$ @tomzer I'm sorry, I don't have a solution for this paricular task. $\endgroup$ Commented Jan 27, 2017 at 13:36
6
$\begingroup$

I used the Effect function from the effect package for this.

model1<-lmer(y~x1+x2+(1|r),data)

est<-Effect("x1", partial.residuals=T, model1)
plot(est)
$\endgroup$
3
  • $\begingroup$ Welcome to CrossValidated @Seraina! Try improving the quality of your answer by explaining why your proposed solution is the right answer and how it works to make it as useful as possible for others who might be struggling with the same problem. $\endgroup$ Commented Feb 6, 2018 at 9:17
  • 1
    $\begingroup$ This answer is totally perfect, clear and helpful, no need for clutter it with unnecessary bs. Good job Seraina! $\endgroup$
    – Tomas
    Commented Jul 8, 2019 at 13:31
  • $\begingroup$ @Seraina, is this a partial plot where the effects of other variables in the model are held at 0? Or are they controlled for in some other way? So basically it's plots the coefficient of x1 from the lmer? $\endgroup$ Commented Nov 20, 2023 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.