I am running a LME (Linear Mixed-Effects regression) in R where the knot is determined by the time of diagnosis (t=0). So the model is now:
lme(function ~ age+sex+timepre*marker+timepost*marker, random=~time|ID, data=data)
Thus: timepre is where everything from t=0 is 0 and before that is 0-time, and timepost is where everything before diagnosis is 0 and afterwards is 0+time. The time is the combination of timepre and timepost.
I now wanted to plot these effects using the sjPlot library as it nicely gives the predicted values (corrected for covariates) and having this as a plot where one could see the knot at t=0.
plot_model(model, type="int")
Instead it is plotting two different plots, one for each interaction. Is there a way to combine these plots, so that the slopes before and after come together (the intercepts are also different now)? Or how should I do this?
UPDATE:
After googling more, I found a suggestion to use splines instead of two separate time frames. So, what I tried now is:
lme(function ~ age+sex+bs(time, knots=0, degree=1)*marker, random=~time|ID, data=data)
I am able to plot this with the visreg library and I do seem to get the knot at zero:
Is this correct? Am I correct that the coefficients should be interpreted as follows:
bs(time, knots = 0, degree = 1)1:marker 12.055090 p= 0.0004
bs(time, knots = 0, degree = 1)2:marker 13.750058 p= 0.0133
the first coeff (12.055 and with p-value 0.0004) represents the change in the first slope (before the knot) as a function of the level of the marker? And the second coeff (13.75 with p-value 0.013) represents the difference between the first and second slope as a function of the marker? How then to know if change in the second slope is significant as a function of the marker?
You don't need to use splines for your time variable, especially if you just have two time points, you can't fit any curve between these two points. Thus, your model would be:
lme(function ~ age + sex + time * marker, random=~time|ID, data=data)
You can then use plot_model(model, type = "int")
to see the interaction and differences between the two time points. Or you can use the ggeffects package, which is even a bit more flexible.
If the time
variable has more than two time points, it probably makes sense using poly()
or splines. For ggeffects, there's a practical example including polynomial terms here (and a general introduction here).
For your above example:
library(ggeffects)
m <- lme(function ~ age+sex+bs(time, knots=0, degree=1)*marker, random=~time|ID, data=data)
pred <- ggpredict(m, c("time", "marker"))
plot(pred)