CecileProust-Lima / lcmm

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

NAs returned by predictY function #234

Closed fBeyer89 closed 4 months ago

fBeyer89 commented 7 months ago

Dear developers, I would like to predict trajectories for individual markers from a multlcmm model. Unfortunately, I receive NA as predicted values whenever I include more variables than the time variable in my model.

This works: base <- multlcmm(learning_us + recall_us ~ time_el, random =~ time_el, subject='num', randomY = T, link = c('beta'), data = lifec_old_cog) p<-predictY(base,newdata=datnew,var.time='time_el',draws=F, nsim = 5)

while here p$pred has only NAs as Ypred: base <- multlcmm(learning_us + recall_us ~ time_el + agec, random =~ time_el, subject='num', randomY = T, link = c('beta'), data = lifec_old_cog) p<-predictY(base,newdata=datnew,var.time='time_el',draws=F, nsim = 5)

  1. Both models converge fine and outputs/estimates look good.

  2. My data only has two timepoints (the distribution of time_el is shown below) - could this be the reason for the error? Histogram_time I tried to generate a similar dataset from paquid, limiting it to paquid_sel=paquid[paquid$time<0.1|paquid$time>0.5&paquid$time<0.55,]. Here, predicting works still fine. So it must somehow be about my dataset?

  3. Also, when having only two time points, is it correct to specify time_elas a random effect - when in fact I would only like to include random intercepts?

This is the head of lifec_old_cog: learning_us recall_us num agec sexn EstimatedTotalIntraCranialVol time_el scores.TC5 1 26 9 1 -0.05 1 1.6077931 0.0000000 -1.259550 2 23 9 1 -0.05 1 1.6077931 0.6350773 -1.259550 3 25 9 2 -0.45 1 1.2641431 0.0000000 -1.107109 4 23 9 2 -0.45 1 1.2641431 0.7334222 -1.107109 5 25 7 3 -0.15 1 -0.2849973 0.6287961 -1.290905 6 26 8 3 -0.15 1 -0.2849973 0.0000000 -1.290905

and this of datnew num agec sexn EstimatedTotalIntraCranialVol time_el scores.TC5 1 1 -0.5400361 0 0.01510632 0.08000000 0.81 2 2 -0.5198341 0 0.01510632 0.08929293 0.81 3 3 -0.4996321 0 0.01510632 0.09858586 0.81 4 4 -0.4794301 0 0.01510632 0.10787879 0.81 5 5 -0.4592280 0 0.01510632 0.11717172 0.81 6 6 -0.4390260 0 0.01510632 0.12646465 0.81

Thank you for your support! Frauke

VivianePhilipps commented 6 months ago

Hi Frauke,

the predictY function should be used to get predictions for one profile of covariates, not for multiple subjects.

In your case, datnew should contain only one value of 'agec'. If you want to plot trajectories like we do in the vignette (https://cecileproust-lima.github.io/lcmm/articles/latent_process_model_with_multlcmm.html), a sequence of 'time_el' should be given. For example datnew <- data.frame(time_el = seq(0, 2, length.out=100), agec = -0.54) if your time scale goes form 0 to 2.

For another profile, you run the predictY function again with a different value of 'agec'.

Best,

Viviane