DenisRustand / INLAjoint

Joint modeling multivariate longitudinal and time-to-event outcomes with INLA
15 stars 0 forks source link

problem fitting joint model for longitudinal and multistate processes #27

Closed ElsaVazquez29 closed 3 months ago

ElsaVazquez29 commented 11 months ago

Hi Denis,

Thanks again for your continued work in developing this package. It has been super useful for my research.

I am trying to use the INLAjoint package to fit a model with two continuous time-dependent covariates and with a multistate process with 4 transitions (similar to the illness-death multistate model but with an extra transition from the illness to the healthy/no-illness state). Once, I get the data for the multistate model in the right format, ie. for each transition, I have the Tstart, Tstop and status format; the data for the multistate model has 36800 observations. The data for the longitudinal model (the two time-dependent covariates) has 21043 observations.

I fit the joint model with the transitions indicated for the multistate model; and

Error in [.data.frame(data_cox[[m]], , modelFE[[k]][[1]][j]) : undefined columns selected

I have been able to fit other multistate models using this package with 2 or more time-dependent covariates (with fixed effects other than time or splines for time). However, in those cases the datasets for the multistate models had less observations than the datasets for the time-dependent covariates.

Could this error be happening because the dataset for the time-to-event outcomes (for the multistate model) has a bigger sample size than the dataset for the time-dependent covariates?

Any help in solving this would be greatly appreciated.

DenisRustand commented 11 months ago

Hi Elsa, Thank you for your feedback! I am currently out of the office for conferences but I'll try to fix the error once I get back. It looks like the code is trying to find some covariates for fixed effects in the survival datasets but they are not there... I think you can fix it temporarily while waiting for a real fix from my side: If you include covariates in the longitudinal (e.g., sex, race, treatment), can you try to have these covariates also in the survival datasets (with the same names)? I think it should fix the issue for now and in the future I'll adapt the code so that it grabs these covariates from the longitudinal data. If this does not fix the issue, it may be useful if you can share a reproducible example of the error (given the message, the error should persist even with a couple observations from the data). Best, Denis

ElsaVazquez29 commented 10 months ago

Hi Denis, Thank you for taking your time to answer my issue! I tried the solution you proposed, including covariates in the longitudinal dataset with the same name as in the survival datasets, and unfortunately I still got the same error.

Here are the longitudinal and the survival datasets. toy_dt1_e contains the data for transition 1 in the multistate model, toy_dt2_e contains the data for transition 2, toy_dt3_e contains the data for transition3, and toy_dt4_e contains the data for transition 4, toy_longi_e contains the longitudinal data for the two outcomes (outcome1 and outcome2). The id variable is called "id" in all datasets, for the longitudinal data, time for each measurement is "time_years". The variable "covariate_1" is the same in the transition and longitudinal datasets. If you take the "covariate_1" out of the formula for the model for outcome1 and outcome2 from the longitudinal dataset the model runs.

Here is the code I used to fit the model.

setting up models for all transitions in multistate models

t1=inla.surv(time=toy_dt1_e$Tstop, truncation=toy_dt1_e$Tstart, event=toy_dt1_e$status) t2=inla.surv(time=toy_dt2_e$Tstop, truncation=toy_dt2_e$Tstart, event=toy_dt2_e$status) t3=inla.surv(time=toy_dt3_e$Tstop, truncation=toy_dt3_e$Tstart, event=toy_dt3_e$status) t4=inla.surv(time=toy_dt4_e$Tstop, truncation=toy_dt4_e$Tstart, event=toy_dt4_e$status)

toy_mjoint=joint(formSurv = list(t1~covariate_1, t2~covariate_1, t3~covariate_1, t4~covariate_1), formLong = list(outcome1~covariate_1+time_years+(1+time_years|id), outcome2~covariate_1+time_years+(1+time_years|id)), basRisk=c("rw2", "rw2", "rw2", "rw2"), dataLong=toy_longi_e, id="id", timeVar="time_years", corLong=FALSE, family=c("normal", "normal"), assoc = list(c("CV", "CV", "CV", "CV"), c("CV", "CV","CV", "CV")), dataSurv = list(toy_dt1_e, toy_dt2_e, toy_dt3_e, toy_dt4_e), control=list(verbose=TRUE,strategy="adaptive", int.strategy="eb", priorFixed=list(mean=0, prec=0.16, mean.intercept=0, prec.intercept=0.16), priorAssoc=list(mean=0, prec=0.16) ))

Please let me know if you are able to use the datasets.

Thank you again for your help!

Elsa Vazquez Arreola toy_dt1_e.txt toy_dt2_e.txt toy_dt3_e.txt toy_dt4_e.txt toy_longi_e.txt

DenisRustand commented 10 months ago

Hi Elsa, The code you shared runs without errors, do you still have the same error message as in your first message? Best, Denis

ElsaVazquez29 commented 9 months ago

Hi Denis,

I updated my version of INLAjoint and now the code I uploaded works. Now, I get the following error when I include interactions of the time variable with other covariates in the models of the time-dependent covariates.

Error in [.data.frame(data_cox[[m]], , ntvar) : undefined columns selected

DenisRustand commented 9 months ago

Hi Elsa,

It should be fixed now.

Best, Denis