##### Example of a joint latent class model estimated for a varying number
# of latent classes:
# The linear mixed model includes a subject (ID) and class-specific linear
# trend (intercept and Time in fixed, random and mixture components) and
# a common effect of X1 and its interaction with time (X1_Time) over classes
# (in fixed).
# The variance of the random intercept and slopes are assumed to be equal
# over classes (nwg=F).
# The covariate X3 predicts the class membership (in classmb).
# The baseline hazard function is modelled with cubic M-splines -5
# equidistant nodes- (in hazard) and a proportional hazard over classes is
# assumed (in hazardtype). Covariates X1 and X2 predict the risk of event
# (in survival) with a common effect over classes for X1 and a class-specific
# effect of X2.
# !CAUTION: for illustration, only default initial values where used but
# other sets of initial values should be tried to ensure convergence towards
# the global maximum.
#### data loading
data(data_Jointlcmm)
#### estimation with 1 latent class (ng=1): independent models for the
# longitudinal outcome and the time of event
m1 <- Jointlcmm(fixed= Ydep1~Time+X1+X1_Time,random=~Time,subject='ID'
,survival = Surv(Tevent,Event)~ X1+X2 ,hazard="5-equi-splines"
,hazardtype="PH",ng=1,data=data_Jointlcmm)
#Goodness-of-fit statistics for m1:
# maximum log-likelihood: -3938.91; AIC: 7911.82; BIC: 7974.79
#### estimation with 2 latent classes (ng=2)
m2 <- Jointlcmm(fixed= Ydep1~Time+X1+X1_Time,mixture=~Time,random=~Time,
classmb=~X3,subject='ID',nwg=F,survival = Surv(Tevent,Event)~X1+mixture(X2)
,hazard="5-equi-splines",hazardtype="PH",ng=2,data=data_Jointlcmm)
summary(m2)
#Goodness-of-fit statistics for m2:
# maximum log-likelihood: -3913.96; AIC: 7873.93; BIC: 7959.12
#### estimation with 3 latent classes (ng=3)
m3 <- Jointlcmm(fixed= Ydep1~Time+X1+X1_Time,mixture=~Time,random=~Time,
classmb=~X3,subject='ID',survival = Surv(Tevent,Event)~ mixture(X1)+X2
,hazard="5-equi-splines",hazardtype="PH",ng=3,data=data_Jointlcmm)
summary(m3)
#Goodness-of-fit statistics for m3:
# maximum log-likelihood: -3885.94 ; AIC: 7829.89; BIC: 7937.29
#### estimation with 4 latent classes (ng=4)
m4 <- Jointlcmm(fixed= Ydep1~Time+X1+X1_Time,mixture=~Time,random=~Time,
classmb=~X3,subject='ID',survival = Surv(Tevent,Event)~mixture(X1)+X2,
hazard="5-equi-splines",hazardtype="PH",ng=4,data=data_Jointlcmm)
summary(m4)
#Goodness-of-fit statistics for m4:
# maximum log-likelihood: -3882.38; AIC: 7834.75; BIC: 7964.38
##### The model with 3 latent classes is retained according to the BIC
##### and the conditional independence assumption is not rejected at
##### the 5# posterior classification
postprob(m3)
# Class-specific predicted baseline risk & survival functions in the
# 3-class model retained (for the reference value of the covariates)
plot.baselinerisk(m3)
plot.baselinerisk(m3,ylim=c(0,5))
plot.survival(m3)
# class-specific predicted trajectories in the 3-class model retained
# (with characteristics of subject ID=193)
data <- data_Jointlcmm[data_Jointlcmm$ID==193,]
plot.predict(m3,var.time="Time",newdata=data)
############## end of example ##############
Run the code above in your browser using DataLab