CecileProust-Lima / lcmm

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

Assistance with plotting model fit from hlme object #275

Closed catpsaras closed 2 hours ago

catpsaras commented 23 hours ago

Hello, I am trying to visualize the model fit over 15 time points using the 'plot' function; however, the plot is only displaying 14 points instead of the expected 15.

Here is the relevant portion of my code:

gmm3_2_recheck <- gridsearch(rep = 10, maxiter = 30, minit = gmm1_2_recheck, hlme(pdc_c_d ~ poly(month, degree=3, raw=TRUE), subject = "ENROLID", random=~1+poly(month, degree=3, raw=TRUE),
                                                                                  ng = 3, data = df, mixture = ~ poly(month, degree=3, raw=TRUE),
                                                                                  nwg=T, nproc= 5))

break.times<- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)

plot(gmm3_2_recheck, which="fit", var.time="month", break.times, ylab="Y", xlab="X", marg=FALSE, shades = TRUE, legend=NULL)
axis(side=1, at=1:15)

Despite specifying the break.times vector with 15 points, the resulting plot (attached) only shows 14 of them. I would greatly appreciate your guidance on why this might be happening and how to resolve the issue to display all 15 time points.

Thank you!

CecileProust-Lima commented 12 hours ago

Hi, the plot uses summaries (averages) of the observations and predictions at the observation times. The break times define the boundaries of the intervals for the averages calculation. So probably in your case, You would like to define 16 of them from 0.5 to 15.5. I hope this helps, Cécile

catpsaras commented 2 hours ago

That worked--thank you so much!