I am using the lcmm package in R to fit a latent class mixed model and predict trajectories for glucose over time. However, when I plot the predictions using the predictY function, I see two lines per class instead of one. I suspect that it might be plotting both the linear and quadratic slopes, but I am not sure.
Here is my code:
Fitting the model
m2 <- gridsearch(rep=100, maxiter=10, minit=m1,
hlme(GLU ~ year + I(year^2), subject = "ID", random = ~1 + year + I(year^2),
ng = 2, data = df_long, mixture = ~year + I(year^2), nwg = TRUE))
summary(m2)
Predictions of the trajectories
pred <- predictY(m2, df_long, var.time = "year")
Plotting the predictions
plot(pred, col=c("red", "navy"), lty=1, lwd=3,
ylab="Fasting glucose", legend=NULL, main="Predicted trajectories for FG",
ylim=c(80, 200))
Plot output
The output I am getting
I want to plot only the mean predicted trajectories for each class. Does anyone know how to fix this and get only one line per class?
Regina Paradela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.