drizopoulos / JM

Joint Models for Longitudinal & Survival Data under Maximum Likelihood
34 stars 7 forks source link

Error while iterating: missing value where TRUE/FALSE needed #10

Closed annette987 closed 6 years ago

annette987 commented 6 years ago

Hi, Thank you for this amazing software. Unfortunately I am having trouble getting it to run on my own data. When I run the code below (modelled on one of your examples) I get the following error message from JointModel():

Error in while (iter < maxits && !converged) { : 
  missing value where TRUE/FALSE needed

This is my code:

library(nlme)
library(survival)
library(JM)

data_dir <- "C:/mydir/"
cox_wide <- read.csv(paste(data_dir, "data_sm_wide.csv", sep=""), header=TRUE, sep=",") 
cox_long <- read.csv(paste(data_dir, "data_sm.csv", sep=""), header=TRUE, sep=",") 

ctrl <- lmeControl(opt='optim');
bloodfit <- lme(Age ~ tstart + tstart:Urate, random=~tstart|ID, method="ML", control=ctrl, data=cox_long, na.action=na.omit)
summary(bloodfit)

coxphobject <- coxph(Surv(time=duration, event=cstatus)~Urate, data=cox_wide, x=TRUE, model=TRUE)
summary(coxphobject)

# Joint Model
ctrljm<-list(iter.EM=500)
jmfit <- jointModel(bloodfit, coxphobject, method="Cox-PH-GH", timeVar = "tstart", verbose=T, control=ctrljm)
summary(jmfit)

I have attached a small subset of my data. It crashes after iteration 6. I am using R 3.5.1. Thanks for your help. Annette data.zip

drizopoulos commented 6 years ago

Do you have the same problem with methods "piecewise-PH-aGH" or "spline-PH-aGH"?

annette987 commented 6 years ago

Yes, a similar problem. For those two methods the error message I get is: Error in if (t1 || t2) { : missing value where TRUE/FALSE needed

For piecewise-PH-aGH it happens on the 3rd iteration and for spline-PH-aGH it happens on the 1st.

drizopoulos commented 6 years ago

It is a scaling issue for the regression coefficients. If you transform your time to years, the model converges, i.e.,


cox_long$tstart <- cox_long$tstart / 365
cox_wide$duration <- cox_wide$duration / 365

ctrl <- lmeControl(opt='optim')
bloodfit <- lme(Age ~ tstart + tstart:Urate, random = ~ tstart | ID, 
                control = ctrl, data = cox_long)

coxphobject <- coxph(Surv(duration, cstatus) ~ Urate, data = cox_wide, x = TRUE)

jmfit <- jointModel(bloodfit, coxphobject, method = "piecewise-PH-aGH", 
                    timeVar = "tstart", verbose = TRUE, iter.EM = 200)
summary(jmfit)