CecileProust-Lima / lcmm

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

Error with predictY 'cannot subset column that don't exist #115

Closed fliang1976 closed 2 years ago

fliang1976 commented 2 years ago

Dear Cecile, I met a strange problem when I tried to get the predicted mean to draw a trajectory plot. I used the results from the following 3-class model: WK$TIME_25<-(WK$TIME_QRT_R-25)/10 #TIME_QRT_R is the orginal time variable m3a <- hlme(GFR_QRT_MEAN~ poly(TIME_25, degree = 3, raw = TRUE)+GENDER+AGE_BL+HOSP+PROTEINURIA_bl,random = ~ 1, mixture=~poly(TIME_25, degree = 3, raw = TRUE),subject = "ID",data = WK, ng = 3,B=m1)

After I got the results, I tried to create new dataset to draw trajectory mean plot. My codes are as below: datnew<-data.frame(TIME_QRT_R=seq(0,27,length=100) datnew$TIME_25<-(datnew$TIME_QRT_R-25)/10 datnew$GENDER<-1 datnew$AGE_BL<-64 datnew$HOSP<-1 # 1 stands for hospitalization datnew$PROTEINURIA_bl<-1 # 1 stands for the presence of renal damage mon_p<-predictY(m3a, datnew, var.time='TIME_QRT_R', draws=T)

To my surprise, I got the following error message after running the 'predictY' statement above: "Error: cannot subset columns that don't exist. x column 'TIME_25' doesn't exist" I created 'TIME_25' in the 'datnew' data, and the hlme model also includes this variable.

I ran 'rlang::last_error()' , it showed the following that I am not able to understand: "<error/vctrs_error_subscript_oob> Cannot subset columns that don't exist. x Column 'TIME_25' doesn't exist. Backtrace:

  1. lcmm::predictY(...)
  2. lcmm::predictY.hlme(...)
  3. tibble:::'[.tbl_df'(olddata, , v)
  4. tibble:::vectbl_as_col_location(...)
  5. vctrs::vec_as_location(j,n,names)
  6. vctrs:::stop_subscript_oob(...)
  7. vctrs:::stop_subscript(...)"

Could you help me to figure out why I got this error message and how to fix it? Thank you!

Best Regards, Liang Feng

VivianePhilipps commented 2 years ago

Hello,

the error may occur because you provide your estimation data in a tibble. Our package is designed for data frames, so we can get troubles with tibbles. Moreover, I see that you are using an older version of the package. The predictY does not need anymore to retrieve the estimation data for hlme objects. You can check with the current version (1.9.5) if the error disappears. But this will maybe require that you reestimate the model with that new version.

Best,

Viviane