CecileProust-Lima / lcmm

R package lcmm
https://CecileProust-Lima.github.io/lcmm/
54 stars 13 forks source link

Plot for jointlcmm results #195

Closed wy2020hku closed 1 year ago

wy2020hku commented 1 year ago

Dear Cécile and Viviane,

Thank you for your help to answer questions! I have encountered some problem when plotting the fitted jointlcmm models.

  1. After I use "permut" to re-order the class indexes, the plot function (for example, with which = "fit") still give figures of the originial order, instead of the manually specified order by "permut". (while the "class" variable in mod$ppred is successfully changed). My code:

permut_sub <- function(mod, neworder){ mod <- permut(mod, order = neworder,estim = FALSE) mod$pprob$class <- as.factor(mod$pprob$class) mod$pprob$class <- factor(mod$pprob$class, neworder) mod$pprob$class <- as.integer(mod$pprob$class) return(mod) } mod <- permut_sub(mod, c(2,3,1,4)) plot(mod, which = "fit", var.time = "time")

  1. When I was using predictY to get the class-specific predicted values and plot them, I found that if I change the vector or "time" variable, the predicted values (trajectories) are only compressed or streched, like the figures below:

pred 1 pred 2

code for pred 1:

dt_pd <- data.frame(time=seq(0.5,12.5,0.5)) mod.pred <- predictY(mod, newdata = dt_pd, var.time = "time") plot(mod.pred, bty = "l", ylim = c(6, 13.5), xlim=c(0,15), legend.loc = "topright", ylab = "HbA1c",xlab="years", lwd = 2)

code for pred 2:

dt_pd <- data.frame(time=seq(5,12.5,0.5)) mod.pred <- predictY(mod, newdata = dt_pd, var.time = "time") plot(mod.pred, bty = "l", ylim = c(6, 13.5), xlim=c(0,15), legend.loc = "topright", ylab = "HbA1c",xlab="years", lwd = 2)

(The time variable in the dataset include separate values: 0.5, 1.5, 2.5, ..., 12.5.)

When I looked at the predicted values, I found that pred 1 for time=0.5 equals to pred 2 for time=5. Did I made any mistake when using predictY function?

Best, Yuan

VivianePhilipps commented 1 year ago

Hi,

sorry, I don't understand your permut_sub function. The permut function already does the permutation, even in the pprob output, so you don't need to order it manually.

According to the shapes of your trajectories, I guess you are using splines. Please make sure to specify the knots, as explain in #28. If the knots are not specified, the predictions are generally not correct.

Viviane

wy2020hku commented 1 year ago

Dear Viviane,

Thank you for your timely reply!

For the permut function, I changed the parameter "estim" to be "True" and get all the orders updated. This (estim=F when I run it before) should be the reason of my wrong orders. I though estim=T will repeat the whole model again and thus cost long time, but surprisingly it seems only use several iterations and cost much fewer time than the jointlcmm modelling step.

For the predictY function problem, yes I am using splines with specifying only "df" instead of knots. I read #28 and roughly understand the reason. I will try to speficy knots for the ns() function.

Best, Yuan