I use "R" to do some clinical research.
I got a lognitudinal data such as:
... Every "id" is a unique participant. "years" is the visit time from the baseline(0)
I use lmer/lme to make lognitudinal analysis by the f:
lm1 <- lmer(outcome ~ age + edu + sex + group + years + group:years + (years|id), data=mydata)
Now I want to make the result visulizable.
So I code:
lmplot <- ggplot() + geom_line(aes(years,predict(lm1),color=group),data=mydata) + geom_point(aes(years,outcome,color=group,data=mydata)
The R give me the plot:
However, I am looking for the Plot with two straight lines for group 0 & 1 in the same panel to show the difference of the slope by years.
something like :
It seems that the
predict function did not work.
I have search for solutions like: Demetri Pananos answered the similar question before. That really help with simple model, But not for
mixed fitted model (R: "Error in eval(predvars, data, env) : object 'age' not found").
Is there anyone who can help me ?
Thank you very much!