0

I'm attempting to plot a curvilinear effect with including covariates from a multi-level model (HLM) in R (see model below)

modelUF_US2 = lmer(ufeel ~ age_c + nat + extra_c + trait_sk_c + neuro_c + agree_c + open_c + g.usuccess + usuccess_cwc + usuccess_cwc2 + trait_sk_c2 (usuccess_cwc | subject), data = S6_MLM, REML = 0, na.action = "na.omit",)

Where usuccess_cwc2 is the squared term of usuccess_cwc that I'm looking to plot.

I've looked over posts discussing how to model curvilinear effects using simple models and MLMs , but haven't figured out how to combine these two approaches.

Any assistance on this would be greatly appreciated!

Community
  • 1
  • 1

1 Answers1

0

You could use the sjPlot-package for that. Use sjp.lmer(modelUF_US2, type = "effect") to plot marginal effects for all fixed effects of your model.

If you just want to plot the marginal effect for the polynomial term, use:

sjp.lmer(modelUF_US2, type = "poly", poly.term = "usuccess_cwc")

However, you need to re-specify your model and square usuccess_cwc inside the formula before:

modelUF_US2 <- 
  lmer(ufeel ~ age_c + nat + extra_c + trait_sk_c +
         neuro_c + agree_c + open_c + g.usuccess + usuccess_cwc +
         I(usuccess_cwc) ^ 2 + trait_sk_c2 + (usuccess_cwc | subject),
       data = S6_MLM, REML = 0, na.action = na.omit)

library(sjPlot)
sjp.lmer(modelUF_US2, type = "poly", poly.term = "usuccess_cwc")
Daniel
  • 7,252
  • 6
  • 26
  • 38
  • Thanks for the answer. Strangely, when I re-specify the model incorporating I(usuccess_cwc)^2 - the fixed effect model matrix becomes rank deficient ("fixed-effect model matrix is rank deficient so dropping 1 column / coefficient"). I've read [this post](http://stats.stackexchange.com/questions/35071/what-is-rank-deficiency-and-how-to-deal-with-it) and it doesn't seem like my data should be fine. Have you used that function before in multilevel models? – Chris Wiese Jan 27 '17 at 17:27
  • See the help page `?sjp.lmer`, one of the last examples there uses a polynomial term in the formula. – Daniel Jan 27 '17 at 20:09