-----Original Message-----
From: R-sig-mixed-models [mailto:r-sig-mixed-models-bounces at r-
project.org] On Behalf Of Boden, Matthew T. via R-sig-mixed-models
Sent: Wednesday, January 30, 2019 4:27 PM
To: r-sig-mixed-models at r-project.org
Subject: [R-sig-ME] LMER - Plotting of a quadratic effect interacting
with time
Hello,
I have a question related to fitting and plotting a longitudinal
linear mixed model that includes an interaction between a quadratic
effect and time. Data attached.
I fit the following:
Q1 <- lmer(Patients ~ Time*FTE + Time*I(FTE^2) + (FTE | ID), data =
SHARE)
#Yes, the variables are on very different scales - will take care of
that later
I find a sizeable quadratic effect.
Fixed effects:
Estimate Std. Error t value
(Intercept) 6.760e+03 5.347e+02 12.642
Time 2.033e+01 1.011e+01 2.011
FTE 9.728e+01 8.583e+00 11.335
I(FTE^2) -5.155e-01 4.000e-02 -12.890
Time:FTE -5.560e-01 2.254e-01 -2.467
Time:I(FTE^2) 7.371e-03 1.052e-03 7.006
To plot the quadratic interaction, I attempt to use the effects package.
However, effects are displayed for Time x FTE, not time by FTE^2. Time
x FTE is clearly not the plot that I want (I think...).
e1 <- effect(term="Time:I(FTE^2)", mod=Q1)
ed1<-as.data.frame(e1)
ed1
Time FTE fit se lower upper
1 1 17 8277.635 464.3995 7366.770 9188.500
2 4 17 8316.650 463.3763 7407.792 9225.508
......
I tried a workaround, by fitting a model that included FTE^2 as a
second, calculated variable in the data set. Using the effects
package, I do indeed obtain Time * FTE_sq.
Q2 <- lmer(Patients ~ Time*FTE + Time*FTE_sq + (FTE | ID), data =
SHARE)
e2 <- effect(term="Time*FTE_sq", mod=Q2)
ed2<-as.data.frame(e2)
ed2
Time FTE_sq fit se lower upper
1 1 300 14678.1413 564.5423 13570.8582 15785.4243
2 4 300 14606.9253 563.3827 13501.9166 15711.9340
......
But the plot does not at all look like what I would expect. All lines
representing FTE_sq over time are straight.