DenisRustand / INLAjoint

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

use of splines with 2 or more longitudinal outcomes #1

Closed ElsaVazquez29 closed 2 years ago

ElsaVazquez29 commented 2 years ago

@DenisRustand I have been working on understanding how the joint function works. I was wondering if it is possible to fit joint models with one survival outcome, and one ordinal and one continuous longitudinal outcome. I tried fitting such model using this package. First, I expanded the dataset for the ordinal outcome to fit a continuation ratio model. Then, I put the ordinal outcome as the first element of the list for formLong and the dataLong arguments, I provided a list with the dataset for the ordinal outcome and a different dataset for the continuous outcome. The model works if I fit it with the continuous outcome being linear as a function of time. However, my continuous longitudinal outcome is non-linear and I need a non-restricted cubic spline with 5 knots for time to adequately describe its longitudinal trajectory.

I used the following code to describe the model I am trying to fit.

_#define spline functions for time Nsplines5=ns(Longi$time_years, 5) f15=function(x) predict(Nsplines5, x) [ ,1] f25=function(x) predict(Nsplines5, x) [ ,2] f35=function(x) predict(Nsplines5, x) [, 3] f45=function(x) predict(Nsplines5, x) [ ,4] f55=function(x) predict(Nsplines5, x) [ ,5]

fit joint model for ordinal outcome as a continuation ratio model and longitudinal outcome with 5 splines for time

mjoint2=joint(formSurv = survival~ female+treatment+white+baseline_age+baseline_bmi, formLong = list(y_new ~ cat2+cat3+female+treatment+white+baseline_age+baseline_bmi+ time_years+treatmenttime_years+(1+time_years|id), continuous~female+white+baseline_age+baseline_bmi+ (1+f15(time_years)+f25(time_years)+f35(time_years)+f45(time_years)+f55(time_years))treatment +(1+time_years|id)), id = "id", timeVar = "time_years", corLong=FALSE, family = c("binomial", "gaussian"), assoc=c("CV","CV"), basRisk = "rw2", NbasRisk=25, control=list(int.strategy="eb"), dataLong =list(cr_data, Longi), dataSurv = Surv)

y_new is a binomial outcome created when expanding the dataset for the continuation ratio model, the ordinal outcome has 4 categories.__

When I run this code, I get the following error.

_Error in [.data.frame(data_cox[[m]], , modelFE[[k]][[1]][j]) : undefined columns selected Called from: [.data.frame(datacox[[m]], , modelFE[[k]][[1]][j])

I also get this error when I am trying to fit a joint model for survival and two or more continuous longitudinal outcomes and the number of splines for time is not the same for all continuous outcomes (i.e. it is 3 for one outcome and 5 for another outcome).

Any help or comments on this would be greatly appreciated.

DenisRustand commented 2 years ago

Hi,

Thank you for your interest in INLAjoint. The function names must be between f1 and f20 to be recognized by the program, therefore only your first spline basis will be properly handled and the rest is making the error. The following code seems to run fine (functions are named f1 to f5 here):

library(INLAjoint) data(Long) data(Surv)

Nsplines5=ns(Long$time, 5) f1=function(x) predict(Nsplines5, x) [ ,1] f2=function(x) predict(Nsplines5, x) [ ,2] f3=function(x) predict(Nsplines5, x) [, 3] f4=function(x) predict(Nsplines5, x) [ ,4] f5=function(x) predict(Nsplines5, x) [ ,5] YD1 <- inla.surv(time = c(Surv$deathTimes), event = c(Surv$Event1)) # Event

JMINLA <- joint( formLong = list(Y3 ~ time + ctsX + binX + (1 + time | Id), Y1 ~ (f1(time) + f2(time) + f3(time) + f4(time) + f5(time))*ctsX + binX + (1 + time| Id)), dataLong = Long, formSurv = list(YD1 ~ binX + ctsX), id = "Id", timeVar = "time", corLong=TRUE, family = c("binomial", "gaussian"), basRisk = c("rw1"), assoc = list(c("CV"), c("CV")), control=list(int.strategy="eb")) summary(JMINLA)

Let me know if it is fixed. I'll add an explicit warning message to avoid this in the futur.

Denis

ElsaVazquez29 commented 2 years ago

Thank you @DenisRustand ! This seems to work. Also, thank you for developing this package, it makes fitting joint models much faster.