| Title: | Estimate Location-Scale Joint Models |
|---|---|
| Description: | Estimation of mixed models including a subject-specific variance that can be time- and covariate-dependent or defined for within- and between-visit variability. In the joint modeling framework, the package handles left truncation, interval censoring, and multistate models, and allows a flexible dependence structure between competing events and the longitudinal marker. Estimation is performed in a frequentist framework using the Marquardt-Levenberg algorithm. Methods are described in Courcoul et al. (2025) <doi:10.1002/sim.70244> and in Courcoul et al. (2026) <doi:10.1002/bimj.70123>. |
| Authors: | Léonie Courcoul [aut, cre], Antoine Barbieri [aut], Hélène Jacqmin-Gadda [aut] |
| Maintainer: | Léonie Courcoul <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.1.1 |
| Built: | 2026-10-14 14:51:56 UTC |
| Source: | https://github.com/leoniecourcoul/lsjm |
Management of longitudinal data
data.manag.long(formGroup, formFixed, formRandom, data.long1)data.manag.long(formGroup, formFixed, formRandom, data.long1)
formGroup |
A formula which indicates the group variable |
formFixed |
A formula which indicates the fixed effects for the longitudinal submodel |
formRandom |
A formula which indicates the random effects for the longitudinal submodel |
data.long1 |
A dataframe with the longitudinal data |
A list with the following components :
data_longa clean dataframe for the longitudinal data
y.new.progthe vector of responses variable
Xa matrix with the fixed effects
Ua matrix with the random effects
ida vector with the identification of individuals
offseta vector with the number of measurements for each individual
Ian integer, the number of individuals
Management of data for residual part
data.manag.sigma(formGroup, formFixed, formRandom, data.long1)data.manag.sigma(formGroup, formFixed, formRandom, data.long1)
formGroup |
A formula which indicates the group variable |
formFixed |
A formula which indicates the fixed effects for the longitudinal submodel |
formRandom |
A formula which indicates the random effects for the longitudinal submodel |
data.long1 |
A dataframe with the longitudinal data |
A list with the following components :
Xa matrix with the fixed effects
Ua matrix with the random effects
Management of survival data
data.manag.surv(formGroup, formSurv, data.long1)data.manag.surv(formGroup, formSurv, data.long1)
formGroup |
A formula which indicates the group variable |
formSurv |
A formula which indicates the survival submodel |
data.long1 |
A dataframe with the longitudinal data |
This function can be used only with an lsjm object.
Individual dynamic predictions can be computed and plotted.
They are defined as the predicted probability of having event between time and
given that the subject has not experienced any event before time ,
and knowing all marker measures collected until time ,
denoted by , and the set of estimated parameters. The prediction is defined for
subject by:
#'
For illness-death and competing risks models, , whereas for a model with a single
event, .
For illness-death and single-event models, only the prediction from state (0) to state (1) can be
computed, while for competing risks, transitions (0→1) and (0→2) can both be predicted.
As in the estimation procedure, the integral over the random effects is computed by QMC approximation and the integral over time by the Gauss-Kronrod quadrature.
The 95\
which can be computationally intensive. For large enough and
(e.g. ):
Generate
,
where is the inverse of the Hessian
matrix at ;
Compute
from the equation above;
Compute the 95\
97.5th percentiles of the -sample of
.
dynpred(object, newdata, s, horizon, event, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_classicCR' dynpred(object, newdata, s, horizon, event, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_classicIDM' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_classicSingle' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_covDepCR' dynpred(object, newdata, s, horizon, event, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_covDepIDM' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_covDepSingle' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_interintraCR' dynpred(object, newdata, s, horizon, event, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_interintraIDM' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_interintraSingle' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000)dynpred(object, newdata, s, horizon, event, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_classicCR' dynpred(object, newdata, s, horizon, event, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_classicIDM' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_classicSingle' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_covDepCR' dynpred(object, newdata, s, horizon, event, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_covDepIDM' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_covDepSingle' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_interintraCR' dynpred(object, newdata, s, horizon, event, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_interintraIDM' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000) ## S3 method for class 'lsjm_interintraSingle' dynpred(object, newdata, s, horizon, event = NULL, CI = 95, nb.draws = 1000)
object |
An |
newdata |
A dataset containing the individuals for whom predictions are to be computed. |
s |
The landmark time (a single numeric value). |
horizon |
The horizon time of prediction. The function computes the probability of
experiencing the event between |
event |
An integer indicating for which event the prediction is computed. In the case of a * competing risks model, it can be 1 or 2, whereas for other models it can only be 1. |
CI |
An integer between 0 and 100 indicating the confidence level (default: |
nb.draws |
An integer giving the number of Monte Carlo draws used to compute the confidence
interval (default: |
A dataframe containing the table of predictions (table.pred).
set.seed(123) data <- data.frame( ID = rep(1:100, each = 3), time = rep(1:3, 100), y = rnorm(300), event = rep(rbinom(100,1,0.5), each = 3), time_event = rep(runif(100), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) fit <- lsjm( Objectlsmm = m0, survival_type = "Single", formSurv_01 = ~ 1, sharedtype_01 = "value", hazardBase_01 = "Weibull", delta1 = ~ event, Time_T = ~ time_event, S1 = 10, S2 = 10, nproc = 1 ) ind1 <- data[which(data$ID == 1),] dynpEvent <- dynpred(fit, ind1, s = 2, horizon = seq(2.1,3,0.1), event = 1, nb.draws = 100) ## Not run: library(dplyr) # Begin by running the examples from the lsjm function (see ?lsjm). data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 # Example: prediction of the risk to be diagnosed with dementia # (dynpDementia) and to die (dynpDeath) between 85 and 95 years old # given the blood pressure measurements before 85 years old for # individual "10003", with a competing risk model threeC_ex2 <- threeC[,c("ID", "SBP", "age.visit65", "age0_65", "age.final65", "age.last65", "age.first65", "dem", "death", "sex","num.visit")] threeC_ex2$age65_CR <- NA threeC_ex2$age65_CR[which(threeC_ex2$dem == 1)] <- (threeC_ex2$age.last65[which(threeC_ex2$dem == 1)] + threeC_ex2$age.first65[which(threeC_ex2$dem == 1)])/2 threeC_ex2$age65_CR[which(threeC_ex2$dem == 0)] <- threeC_ex2$age.final65[which(threeC_ex2$dem == 0)] threeC_ex2$demCR <- threeC_ex2$dem threeC_ex2$deathCR <- NA threeC_ex2$deathCR[which(threeC_ex2$dem == 1)] <- 0 threeC_ex2$deathCR[which(threeC_ex2$dem == 0)] <- threeC_ex2$death[which(threeC_ex2$dem == 0)] threeC_ex2 <- threeC_ex2 %>% group_by(ID) %>% dplyr::filter(age.visit65 <= age65_CR) threeC_ex2 <- threeC_ex2[,c("ID","SBP","age.visit65","num.visit","age0_65", "demCR","deathCR","age65_CR","sex")] ind2 <- threeC_ex2[which(threeC_ex2$ID == 3),] ind2 <- as.data.frame(ind2) m2 <- lsmm(formFixed = SBP ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex2, formVar = "inter-intra", random_inter = TRUE, random_intra = TRUE, formGroupVisit = ~num.visit, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l2 <- lsjm(Objectlsmm = m2, survival_type = 'CR', formSurv_01 = ~ sex, formSurv_02 = ~ sex, sharedtype_01 = c("value", "variability inter"), sharedtype_02 = c("value", "variability inter", "variability intra"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", delta1 = ~ demCR, delta2 = ~ deathCR, Time_T0 = ~ age0_65, Time_T = ~ age65_CR, nproc = 5, S1 = 1000, S2 = 2000) dynpDementia <- dynpred(l2, ind2, s = 2, horizon = seq(2.1,3,0.1), event = 1, nb.draws = 1000) dynpDeath <- dynpred(l2, ind2, s = 2, horizon = seq(2.1,3,0.1), event = 2, nb.draws = 1000) ## End(Not run)set.seed(123) data <- data.frame( ID = rep(1:100, each = 3), time = rep(1:3, 100), y = rnorm(300), event = rep(rbinom(100,1,0.5), each = 3), time_event = rep(runif(100), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) fit <- lsjm( Objectlsmm = m0, survival_type = "Single", formSurv_01 = ~ 1, sharedtype_01 = "value", hazardBase_01 = "Weibull", delta1 = ~ event, Time_T = ~ time_event, S1 = 10, S2 = 10, nproc = 1 ) ind1 <- data[which(data$ID == 1),] dynpEvent <- dynpred(fit, ind1, s = 2, horizon = seq(2.1,3,0.1), event = 1, nb.draws = 100) ## Not run: library(dplyr) # Begin by running the examples from the lsjm function (see ?lsjm). data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 # Example: prediction of the risk to be diagnosed with dementia # (dynpDementia) and to die (dynpDeath) between 85 and 95 years old # given the blood pressure measurements before 85 years old for # individual "10003", with a competing risk model threeC_ex2 <- threeC[,c("ID", "SBP", "age.visit65", "age0_65", "age.final65", "age.last65", "age.first65", "dem", "death", "sex","num.visit")] threeC_ex2$age65_CR <- NA threeC_ex2$age65_CR[which(threeC_ex2$dem == 1)] <- (threeC_ex2$age.last65[which(threeC_ex2$dem == 1)] + threeC_ex2$age.first65[which(threeC_ex2$dem == 1)])/2 threeC_ex2$age65_CR[which(threeC_ex2$dem == 0)] <- threeC_ex2$age.final65[which(threeC_ex2$dem == 0)] threeC_ex2$demCR <- threeC_ex2$dem threeC_ex2$deathCR <- NA threeC_ex2$deathCR[which(threeC_ex2$dem == 1)] <- 0 threeC_ex2$deathCR[which(threeC_ex2$dem == 0)] <- threeC_ex2$death[which(threeC_ex2$dem == 0)] threeC_ex2 <- threeC_ex2 %>% group_by(ID) %>% dplyr::filter(age.visit65 <= age65_CR) threeC_ex2 <- threeC_ex2[,c("ID","SBP","age.visit65","num.visit","age0_65", "demCR","deathCR","age65_CR","sex")] ind2 <- threeC_ex2[which(threeC_ex2$ID == 3),] ind2 <- as.data.frame(ind2) m2 <- lsmm(formFixed = SBP ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex2, formVar = "inter-intra", random_inter = TRUE, random_intra = TRUE, formGroupVisit = ~num.visit, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l2 <- lsjm(Objectlsmm = m2, survival_type = 'CR', formSurv_01 = ~ sex, formSurv_02 = ~ sex, sharedtype_01 = c("value", "variability inter"), sharedtype_02 = c("value", "variability inter", "variability intra"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", delta1 = ~ demCR, delta2 = ~ deathCR, Time_T0 = ~ age0_65, Time_T = ~ age65_CR, nproc = 5, S1 = 1000, S2 = 2000) dynpDementia <- dynpred(l2, ind2, s = 2, horizon = seq(2.1,3,0.1), event = 1, nb.draws = 1000) dynpDeath <- dynpred(l2, ind2, s = 2, horizon = seq(2.1,3,0.1), event = 2, nb.draws = 1000) ## End(Not run)
Initialisation of Longitudinal Submodel
initial.long(formFixed, formRandom, idVar, data.long1, ncX, nproc = nproc)initial.long(formFixed, formRandom, idVar, data.long1, ncX, nproc = nproc)
formFixed |
A formula which indicates the fixed effects for the longitudinal submodel |
formRandom |
A formula which indicates the random effects for the longitudinal submodel |
idVar |
A character, indicates the name of the group variable |
data.long1 |
A dataframe with the longitudinal data |
ncX |
An integer, the number of columns of matrix X, ie, the number of fixed effects |
nproc |
An integer, the number of cores for parallel computation |
A list with the following components :
long_modelthe result of the hlme function
priorMean.betathe estimated parameters for fixed effects in the linear mixed effects model
sigmathe estimated sigma of the model
This function fits joint models in which the residual error variance is allowed to be subject-specific and the survival submodel may include either a single event, competing risks, or an illness-death process. Up to nine different model structures can be estimated (see Details). Parameters are estimated by maximum likelihood using a Marquardt-Levenberg algorithm.
lsjm( Objectlsmm, survival_type = c("Single", "CR", "IDM"), formSurv_01, formSurv_02 = NULL, formSurv_12 = NULL, sharedtype_01, sharedtype_02 = NULL, sharedtype_12 = NULL, hazardBase_01, hazardBase_02 = NULL, hazardBase_12 = NULL, delta1, delta2 = NULL, Time_T, Time_L = NULL, Time_R = NULL, Time_T0 = NULL, formSlopeFixed = NULL, formSlopeRandom = NULL, index_beta_slope = NULL, index_b_slope = NULL, nb.knots.splines = c(1, 1, 1), nb_pointsGK = 15, S1 = 1000, S2 = 5000, binit = NULL, nproc = 1, clustertype = "PSOCK", maxiter = 500, print.info = FALSE, file = NULL, epsa = 1e-04, epsb = 1e-04, epsd = 1e-04 )lsjm( Objectlsmm, survival_type = c("Single", "CR", "IDM"), formSurv_01, formSurv_02 = NULL, formSurv_12 = NULL, sharedtype_01, sharedtype_02 = NULL, sharedtype_12 = NULL, hazardBase_01, hazardBase_02 = NULL, hazardBase_12 = NULL, delta1, delta2 = NULL, Time_T, Time_L = NULL, Time_R = NULL, Time_T0 = NULL, formSlopeFixed = NULL, formSlopeRandom = NULL, index_beta_slope = NULL, index_b_slope = NULL, nb.knots.splines = c(1, 1, 1), nb_pointsGK = 15, S1 = 1000, S2 = 5000, binit = NULL, nproc = 1, clustertype = "PSOCK", maxiter = 500, print.info = FALSE, file = NULL, epsa = 1e-04, epsb = 1e-04, epsd = 1e-04 )
Objectlsmm |
The result from the |
survival_type |
Character string specifying the survival scheme: |
formSurv_01 |
One-sided formula specifying covariates for the 0–1 transition. |
formSurv_02 |
One-sided formula specifying covariates for the 0–2 transition. |
formSurv_12 |
One-sided formula specifying covariates for the 1-2 transition. |
sharedtype_01 |
Character vectors defining the dependence structure between the longitudinal
and the survival submodel for the 0-1 transition. For standard mixed models, valid options
include |
sharedtype_02 |
Character vectors defining the dependence structure between the longitudinal
and the survival submodel for the 0-2 transition. For standard mixed models, valid options
include |
sharedtype_12 |
Character vectors defining the dependence structure between the longitudinal
and the survival submodel for the 1-2 transition. For standard mixed models, valid options
include |
hazardBase_01 |
Character strings specifying the baseline hazard function for transition 0-1
one of |
hazardBase_02 |
Character strings specifying the baseline hazard function for transition 0-2
one of |
hazardBase_12 |
Character strings specifying the baseline hazard function for transition 1-2
one of |
delta1 |
One-sided formula defining the event indicator for the first event ( |
delta2 |
One-sided formula defining the indicator for the second event ( |
Time_T |
One-sided formula specifying the event time variable. |
Time_L |
For IDM models, one-sided formula giving the time of the last observation in state (0). |
Time_R |
For IDM models, one-sided formula giving the first observed time in state (1). |
Time_T0 |
One-sided formula specifying the time of entry (for delayed entry). |
formSlopeFixed |
One-sided formula for the time derivative of the fixed effects (if "slope"
is included in |
formSlopeRandom |
One-sided formula for the time derivative of the random effects
(if "slope" is included in |
index_beta_slope |
Vector indicating the indices of fixed-effect parameters used in the slope association. |
index_b_slope |
Vector indicating the indices of random-effect parameters used in the slope association. |
nb.knots.splines |
Integer giving the number of internal knots for spline-based baseline hazards. |
nb_pointsGK |
Integer specifying the number of Gauss–Kronrod quadrature points (between 7 and 15; default is 15). |
S1 |
Integer specifying the number of QMC draws for the first step. |
S2 |
Integer specifying the number of QMC draws for the second step. |
binit |
Optional vector of initial parameters values. |
nproc |
Integer specifying the number of processors for parallel computing. |
clustertype |
Character string indicating the cluster type supported by |
maxiter |
Optional integer specifying the maximum number of iterations for the Marquardt–Levenberg algorithm (default to 100). |
print.info |
Logical indicating whether iteration details should be printed (False by default). |
file |
Optional character string giving the name of the file where iteration outputs are
written (if |
epsa |
Optional numeric threshold for convergence based on parameter stability. |
epsb |
Optional numeric threshold for convergence based on objective function stability. |
epsd |
Optional numeric threshold for the relative distance to the maximum. This criterion has the nice interpretation of estimating the ratio of the approximation error over the statistical error, thus it can be used for stopping the iterative process whatever the problem. |
A joint model is composed of two submodels:
(1) a linear mixed model or location-scale mixed model(see ?LSJM::lsmm), and
(2) a survival model.
Three types of survival processes are supported and are described below.
A. A single event: proportional hazards model
In this case, we consider only a single event. Let denote the
observed time,
where is the true event time and the censoring time for subject .
Let be the event indicator.
The hazard function is given by:
where:
is the baseline hazard function,
is a vector of baseline covariates with associated coefficients
,
are regression coefficients for the function ,
representing the association between the event risk and the mean trajectory of ,
are regression coefficients for the function ,
representing the association between the event risk and the residual variance.
The association function can be defined as:
— current value,
— current
slope,
— both value and slope,
— random effects.
The association function is defined according to the longitudinal model
type:
If a standard linear mixed model with homogeneous residual variance is used:
.
If a location–scale mixed model with time- or covariate-dependent variance is used:
.
If both within- and between-visit variances are modeled:
,
where correspond to between-visit and
within-visit variabilities, respectively.
The baseline hazard function can follow different parametric forms:
Exponential: ,
Weibull: ,
Gompertz: ,
Cubic B-splines with knots:
,
where denotes the q-th B-spline basis function with knot vector .
B. Competing events: cause-specific model
When multiple types of events are possible, two competing causes can be modeled.
Let be the observed time, where is the
true event time for cause (with ),
and the censoring time.
The event indicator is , where if cause
occurred and otherwise.
The cause-specific hazard is defined as:
The definitions of , , , and
follow the same principles as in the single-event model.
C. Semi-competing events: illness–death model
In this setting, transition to state (1) may be interval-censored, whereas transition to state
(2) is observed exactly.
The observed event data for subject are given by:
,
where:
— entry time (in case of delayed entry),
— time of the last visit where the subject was in state (0),
— time of the first visit where the subject was observed in state (1),
— minimum between the transition time to state (2) and the censoring time,
— indicator of transition to state (1),
— indicator of transition to state (2).
Transition intensities from state to state follow a
proportional hazards model under the Markov assumption:
where the terms are defined analogously to the single-event model.
An object of class lsjm containing:
table.resTable of parameter estimates and standard errors.
result_step1A marqLevAlg object with first-step estimation results.
result_step2A marqLevAlg object with second-step estimation results.
info_conv_step1Information on first-step convergence (criteria and computation time).
info_conv_step2Information on second-step convergence (criteria and computation time).
controlList of control parameters used during estimation.
set.seed(123) data <- data.frame( ID = rep(1:100, each = 3), time = rep(1:3, 100), y = rnorm(300), event = rep(rbinom(100,1,0.5), each = 3), time_event = rep(runif(100), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) fit <- lsjm( Objectlsmm = m0, survival_type = "Single", formSurv_01 = ~ 1, sharedtype_01 = "value", hazardBase_01 = "Weibull", delta1 = ~ event, Time_T = ~ time_event, S1 = 100, S2 = 100, nproc = 1 ) ## Not run: library(dplyr) # First, run the examples from the lsmm function (see ?lsmm). # Example 1: Illness-death model with time-dependent subject-specific # variability data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","dem","death", "age.first65","age.last65","age.final65","age0_65")] m1 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l1 <- lsjm(m1, survival_type = 'IDM', formSurv_01=~1, formSurv_02=~sex, formSurv_12=~sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "slope", "variability"), sharedtype_12 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", hazardBase_12 = "Splines", delta1=~dem, delta2=~death, Time_T =~age.final65, Time_L =~age.last65, Time_R =~age.first65, Time_T0 =~age0_65, formSlopeFixed =~1, formSlopeRandom =~1, index_beta_slope = c(2), index_b_slope = c(2), nb.knots.splines = c(0,0,1), S1 = 1000, S2 = 2000, nproc = 5) summary(l1) # Example 2: Competing risks model with between- and within-visit # subject-specific variabilities threeC_ex2 <- threeC[,c("ID", "SBP", "age.visit65", "age0_65", "age.final65", "age.last65", "age.first65", "dem", "death", "sex","num.visit")] threeC_ex2$age65_CR <- NA threeC_ex2$age65_CR[which(threeC_ex2$dem == 1)] <- (threeC_ex2$age.last65[which(threeC_ex2$dem == 1)] + threeC_ex2$age.first65[which(threeC_ex2$dem == 1)])/2 threeC_ex2$age65_CR[which(threeC_ex2$dem == 0)] <- threeC_ex2$age.final65[which(threeC_ex2$dem == 0)] threeC_ex2$demCR <- threeC_ex2$dem threeC_ex2$deathCR <- NA threeC_ex2$deathCR[which(threeC_ex2$dem == 1)] <- 0 threeC_ex2$deathCR[which(threeC_ex2$dem == 0)] <- threeC_ex2$death[which(threeC_ex2$dem == 0)] threeC_ex2 <- threeC_ex2 %>% group_by(ID) %>% dplyr::filter(age.visit65 <= age65_CR) threeC_ex2 <- threeC_ex2[,c("ID","SBP","age.visit65","num.visit","age0_65", "demCR","deathCR","age65_CR","sex")] m2 <- lsmm(formFixed = SBP ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex2, formVar = "inter-intra", random_inter = TRUE, random_intra = TRUE, formGroupVisit = ~num.visit, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l2 <- lsjm(Objectlsmm = m2, survival_type = 'CR', formSurv_01 = ~ sex, formSurv_02 = ~ sex, sharedtype_01 = c("value", "variability inter"), sharedtype_02 = c("value", "variability inter", "variability intra"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", delta1 = ~ demCR, delta2 = ~ deathCR, Time_T0 = ~ age0_65, Time_T = ~ age65_CR, nproc = 5, S1 = 1000, S2 = 2000) summary(l2) ## End(Not run)set.seed(123) data <- data.frame( ID = rep(1:100, each = 3), time = rep(1:3, 100), y = rnorm(300), event = rep(rbinom(100,1,0.5), each = 3), time_event = rep(runif(100), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) fit <- lsjm( Objectlsmm = m0, survival_type = "Single", formSurv_01 = ~ 1, sharedtype_01 = "value", hazardBase_01 = "Weibull", delta1 = ~ event, Time_T = ~ time_event, S1 = 100, S2 = 100, nproc = 1 ) ## Not run: library(dplyr) # First, run the examples from the lsmm function (see ?lsmm). # Example 1: Illness-death model with time-dependent subject-specific # variability data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","dem","death", "age.first65","age.last65","age.final65","age0_65")] m1 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l1 <- lsjm(m1, survival_type = 'IDM', formSurv_01=~1, formSurv_02=~sex, formSurv_12=~sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "slope", "variability"), sharedtype_12 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", hazardBase_12 = "Splines", delta1=~dem, delta2=~death, Time_T =~age.final65, Time_L =~age.last65, Time_R =~age.first65, Time_T0 =~age0_65, formSlopeFixed =~1, formSlopeRandom =~1, index_beta_slope = c(2), index_b_slope = c(2), nb.knots.splines = c(0,0,1), S1 = 1000, S2 = 2000, nproc = 5) summary(l1) # Example 2: Competing risks model with between- and within-visit # subject-specific variabilities threeC_ex2 <- threeC[,c("ID", "SBP", "age.visit65", "age0_65", "age.final65", "age.last65", "age.first65", "dem", "death", "sex","num.visit")] threeC_ex2$age65_CR <- NA threeC_ex2$age65_CR[which(threeC_ex2$dem == 1)] <- (threeC_ex2$age.last65[which(threeC_ex2$dem == 1)] + threeC_ex2$age.first65[which(threeC_ex2$dem == 1)])/2 threeC_ex2$age65_CR[which(threeC_ex2$dem == 0)] <- threeC_ex2$age.final65[which(threeC_ex2$dem == 0)] threeC_ex2$demCR <- threeC_ex2$dem threeC_ex2$deathCR <- NA threeC_ex2$deathCR[which(threeC_ex2$dem == 1)] <- 0 threeC_ex2$deathCR[which(threeC_ex2$dem == 0)] <- threeC_ex2$death[which(threeC_ex2$dem == 0)] threeC_ex2 <- threeC_ex2 %>% group_by(ID) %>% dplyr::filter(age.visit65 <= age65_CR) threeC_ex2 <- threeC_ex2[,c("ID","SBP","age.visit65","num.visit","age0_65", "demCR","deathCR","age65_CR","sex")] m2 <- lsmm(formFixed = SBP ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex2, formVar = "inter-intra", random_inter = TRUE, random_intra = TRUE, formGroupVisit = ~num.visit, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l2 <- lsjm(Objectlsmm = m2, survival_type = 'CR', formSurv_01 = ~ sex, formSurv_02 = ~ sex, sharedtype_01 = c("value", "variability inter"), sharedtype_02 = c("value", "variability inter", "variability intra"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", delta1 = ~ demCR, delta2 = ~ deathCR, Time_T0 = ~ age0_65, Time_T = ~ age65_CR, nproc = 5, S1 = 1000, S2 = 2000) summary(l2) ## End(Not run)
This function fits linear mixed effects models for longitudinal data, allowing the residual variance to be subject-specific. Three different model types can be estimated (see Details).Parameters are estimated by maximum likelihood using a Marquardt-Levenberg algorithm.
lsmm( formFixed, formRandom, formGroup, timeVar, formVar = "standard", formFixedVar = NULL, formRandomVar = NULL, random_inter = FALSE, random_intra = FALSE, formGroupVisit = NULL, correlated_re = FALSE, data.long, S1 = 500, S2 = 5000, nproc = 1, clustertype = "PSOCK", maxiter = 100, print.info = FALSE, file = "", epsa = 1e-04, epsb = 1e-04, epsd = 1e-04, binit = NULL )lsmm( formFixed, formRandom, formGroup, timeVar, formVar = "standard", formFixedVar = NULL, formRandomVar = NULL, random_inter = FALSE, random_intra = FALSE, formGroupVisit = NULL, correlated_re = FALSE, data.long, S1 = 500, S2 = 5000, nproc = 1, clustertype = "PSOCK", maxiter = 100, print.info = FALSE, file = "", epsa = 1e-04, epsb = 1e-04, epsd = 1e-04, binit = NULL )
formFixed |
Formula specifying the fixed effects of the longitudinal model. |
formRandom |
Formula specifying the random effects of the longitudinal model. |
formGroup |
Formula specifying the grouping variable (typically the subject ID). |
timeVar |
Character string specifying the time variable. |
formVar |
Character string indicating the type of variability: "standard" for a standard LMM, "cov-dependent" for a covariate-dependent residual variance, or "inter-intra" to distinguish inter- and intra-visit variability. |
formFixedVar |
Formula specifying the fixed effects for the variance predictor
(if |
formRandomVar |
Formula specifying the random effects for the variance predictor
(if |
random_inter |
Logical indicating whether the between-visit variability is subject-specific
(used when |
random_intra |
Logical indicating whether the within-visit variability is subject-specific
(used when |
formGroupVisit |
Formula specifying the visit indicator variable
(used when |
correlated_re |
Logical indicating whether the random effects for the mean and variance
submodels are correlated (used when |
data.long |
Data frame containing the longitudinal data. |
S1 |
Integer specifying the number of QMC draws for the first step. |
S2 |
Integer specifying the number of QMC draws for the second step. |
nproc |
Integer specifying the number of processors for parallel computing. |
clustertype |
Character string indicating the cluster type supported by |
maxiter |
Optional integer specifying the maximum number of iterations for the Marquardt–Levenberg algorithm (default to 100). |
print.info |
Logical indicating whether iteration details should be printed (False by default). |
file |
Optional character string giving the name of the file where iteration outputs are
written (if |
epsa |
Optional numeric threshold for convergence based on parameter stability. |
epsb |
Optional numeric threshold for convergence based on objective function stability. |
epsd |
Optional numeric threshold for the relative distance to the maximum. This criterion has the nice interpretation of estimating the ratio of the approximation error over the statistical error, thus it can be used for stopping the iterative process whatever the problem. |
binit |
Optional vector of initial parameters values. |
The model is defined as:
,
where and are vectors of explanatory variables for subject
at time , associated with the fixed-effect vector and
the subject-specific random-effect vector , respectively.
A. Standard linear mixed model
In this case, , with an unstructured
covariance matrix, and the measurement errors are independent
Gaussian errors with variance .
B. Location-scale mixed model with time and/or covariate-dependent variability
In this model, the residual error variance can vary across subjects and over time: we assume the following specification for the residual error:
with
.#'
where and are vectors of explanatory variables for subject
at visit , associated with the fixed-effect vector and
the subject-specific random-effect vector , respectively.
The random effects are assumed jointly Gaussian:
By convention, random effects for the mean () can be assumed
independent from those for the variance () by setting .
C. Location-scale mixed model distinguishing within and between visits variabilities
In some studies, multiple measurements of the same marker are collected during each visit. For instance, in clinical research, two or three blood pressure readings are typically recorded per visit, and within-visit variability may carry information.
To account for this, we introduce an LSMM that distinguishes within- and between-visit variabilities.
We introduce an additional level in the data hierarchy, grouping repeated measures by visit.
For each subject , represents the
-th measurement at visit
and time . We then define
where and are fixed intercepts for the
between-visits and within-visit variances, respectively. The subject-specific
random-effect and
are assumed to be Gaussian as in model (B).
An object of class lsmm containing:
table.resTable of parameter estimates and standard errors.
result_step1A marqLevAlg object with first-step estimation results.
result_step2A marqLevAlg object with second-step estimation results.
info_conv_step1Information on first-step convergence (criteria and computation time).
info_conv_step2Information on second-step convergence (criteria and computation time).
controlList of control parameters used during estimation.
data <- data.frame( ID = rep(1:5, each = 3), time = rep(1:3, 5), y = rnorm(15), event = rep(rbinom(5,1,0.5), each = 3), time_event = rep(runif(5), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) summary(m0) data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex")] #First example : a standard linear mixed model (constant residual variance, # in time and between subjects, case A in details) m1 <- lsmm(formFixed = SBPvisit ~ age.visit65+I(age.visit65^2), formRandom = ~ age.visit65+I(age.visit65^2), formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "standard", S1 = 500, S2 = 1000, nproc = 1) summary(m1) #Second example : a linear mixed model with subject-specific time-dependent # and covariate-dependent variability (case B in details) #We adjust the individual residual variability on age and the sex. m2 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) summary(m2) #Third example : a linear mixed model with subject-specific inter-visits and # intra-visits variabilities threeC_ex2 <- threeC[, c("ID", "SBP", "age.visit65", "sex", "num.visit")] m3 <- lsmm(formFixed = SBP ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex2, formVar = "inter-intra", random_inter = TRUE, random_intra = TRUE, formGroupVisit = ~num.visit, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) summary(m3) #Fourth example : a linear mixed model with subject-specific inter-visits # variability and constant intra-visit variability m4 <- lsmm(formFixed = SBP ~ age.visit65+sex, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex2, formVar = "inter-intra", random_inter = TRUE, random_intra = FALSE, formGroupVisit = ~num.visit, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) summary(m4)data <- data.frame( ID = rep(1:5, each = 3), time = rep(1:3, 5), y = rnorm(15), event = rep(rbinom(5,1,0.5), each = 3), time_event = rep(runif(5), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) summary(m0) data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex")] #First example : a standard linear mixed model (constant residual variance, # in time and between subjects, case A in details) m1 <- lsmm(formFixed = SBPvisit ~ age.visit65+I(age.visit65^2), formRandom = ~ age.visit65+I(age.visit65^2), formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "standard", S1 = 500, S2 = 1000, nproc = 1) summary(m1) #Second example : a linear mixed model with subject-specific time-dependent # and covariate-dependent variability (case B in details) #We adjust the individual residual variability on age and the sex. m2 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) summary(m2) #Third example : a linear mixed model with subject-specific inter-visits and # intra-visits variabilities threeC_ex2 <- threeC[, c("ID", "SBP", "age.visit65", "sex", "num.visit")] m3 <- lsmm(formFixed = SBP ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex2, formVar = "inter-intra", random_inter = TRUE, random_intra = TRUE, formGroupVisit = ~num.visit, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) summary(m3) #Fourth example : a linear mixed model with subject-specific inter-visits # variability and constant intra-visit variability m4 <- lsmm(formFixed = SBP ~ age.visit65+sex, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex2, formVar = "inter-intra", random_inter = TRUE, random_intra = FALSE, formGroupVisit = ~num.visit, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) summary(m4)
lsjm or lsmm objectsThis function produces different plots (longitudinal and survival goodness-of-fit,
individual trajectory) of a fitted object of class lsmm or lsjm.
## S3 method for class 'lsjm_classicCR' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_classicIDM' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ObjectSmoothHazard = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_classicSingle' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_covDepCR' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_covDepIDM' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ObjectSmoothHazard = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_covDepSingle' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_interintraCR' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_interintraIDM' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ObjectSmoothHazard = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_interintraSingle' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsmm_classic' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ylim = NULL, xlim = NULL, ... ) ## S3 method for class 'lsmm_covDep' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ylim = NULL, xlim = NULL, ... ) ## S3 method for class 'lsmm_interintra' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ylim = NULL, xlim = NULL, ... )## S3 method for class 'lsjm_classicCR' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_classicIDM' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ObjectSmoothHazard = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_classicSingle' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_covDepCR' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_covDepIDM' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ObjectSmoothHazard = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_covDepSingle' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_interintraCR' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_interintraIDM' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ObjectSmoothHazard = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsjm_interintraSingle' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, xlim = NULL, ylim = NULL, ... ) ## S3 method for class 'lsmm_classic' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ylim = NULL, xlim = NULL, ... ) ## S3 method for class 'lsmm_covDep' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ylim = NULL, xlim = NULL, ... ) ## S3 method for class 'lsmm_interintra' plot( x, which = "long.fit", Objectpredict, break.times = NULL, ID.ind = NULL, ylim = NULL, xlim = NULL, ... )
x |
A |
which |
A character indicating which plot must be display, |
Objectpredict |
An object of the |
break.times |
A vector of breaking times to create windows if |
ID.ind |
A vector providing the id of subjects for whom we we wish to trace the individual trajectory. |
xlim |
the x limits (x1, x2) of the plot. The default value, NULL, indicates that the range of the finite values to be plotted should be used. |
ylim |
the y limits (y1, y2) of the plot. The default value, NULL, indicates that the range of the finite values to be plotted should be used. |
... |
Further arguments passed to |
ObjectSmoothHazard |
A SmoothHazard object (only for IDM survival model) |
With which="long.fit", this function allows to assess the fit of the longitudinal submodel
comparing the mean of marker predictions collected in some windows of times (defined by
break.times or using percentiles) to the mean of the observed measurements and its
95\
With which="traj.ind", represents the individual trajectory with its prediction interval.
For a lsjm object only, with which="survival.fit", the function
allows to assess the fit of the survival submodel. For each transition, the predicted cumulative
hazard function at each event time is computed given the predicted random effects. Then the mean
of the predicted cumulative hazard functions are compared with there Nelson-Aalen estimator in
the case of a single event or with competing risks. For an illness-death model, the predicted
cumulative hazard function for each transition is compared to an illness-death model estimated by
penalized likelihood accounting for interval censoring with the SmoothHazard package
A list containing one or more plots:
long.fitA plot comparing the mean marker predictions with the mean observed measurements and their 95 confidence intervals.
graph.traj.indOne or more plots representing individual trajectories together with their prediction intervals.
survBA plot comparing the predicted cumulative hazard function with either the Nelson–Aalen estimator or an Illness–Death model.
set.seed(123) data <- data.frame( ID = rep(1:5, each = 3), time = rep(1:3, 5), y = rnorm(15), event = rep(rbinom(5,1,0.5), each = 3), time_event = rep(runif(5), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) pred.m0 <- predict(m0, which = c("RE","Y"), data.long = data) plot(m0, which = "long.fit", Objectpredict = pred.m0, break.times = c(0,1,2,3)) plot(m0, which = "traj.ind", Objectpredict = pred.m0, ID.ind = c(1,2)) ## Not run: library(dplyr) data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC %>% group_by(ID, num.visit) %>% mutate(SBPvisit = mean(SBP)) threeC$age65_CR <- NA threeC$age65_CR[which(threeC$dem == 1)] <- (threeC$age.last65[which(threeC$dem == 1)] +threeC$age.first65[which(threeC$dem == 1)])/2 threeC$age65_CR[which(threeC$dem == 0)] <- threeC$age.final65[which(threeC$dem == 0)] threeC$demCR <- threeC$dem threeC$deathCR <- NA threeC$deathCR[which(threeC$dem == 1)] <- 0 threeC$deathCR[which(threeC$dem == 0)]<-threeC$death[which(threeC$dem == 0)] threeC <- threeC %>% group_by(ID) %>% filter(age.visit65 <= age65_CR) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","age0_65", "demCR","deathCR", "age65_CR")] # Estimation of a lsmm with time-dependent variability model: m2 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) # Predictions: pred.m2 <- predict(m2, which = c("RE", "Y")) #Plot: plot(m2, which = "long.fit", Objectpredict = pred.m2, break.times = (seq(65,95,by = 2.5)-65)/10) plot(m2, which = "traj.ind", Objectpredict = pred.m2, ID.ind = c(3,120)) # Estimation of a lsjm with time-dependent variability model and # competing events: l2 <- lsjm(Objectlsmm = m2, survival_type = 'CR', formSurv_01 = ~ sex, formSurv_02 = ~ sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", delta1 = ~ demCR, delta2 = ~ deathCR, Time_T0 = ~ age0_65, Time_T = ~ age65_CR, nproc = 5, S1 = 1000, S2 = 2000) # Predictions: pred.l2 <- predict(l2, which = c("RE", "Y", "Cum")) # Plot: plot(l2, which = "long.fit", Objectpredict = pred.l2, break.times = (seq(65,95,by = 2.5)-65)/10) plot(l2, which = "traj.ind", Objectpredict = pred.l2, ID.ind = c(3,120)) plot(l2, which = "survival.fit", Objectpredict = pred.l2) ## End(Not run)set.seed(123) data <- data.frame( ID = rep(1:5, each = 3), time = rep(1:3, 5), y = rnorm(15), event = rep(rbinom(5,1,0.5), each = 3), time_event = rep(runif(5), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) pred.m0 <- predict(m0, which = c("RE","Y"), data.long = data) plot(m0, which = "long.fit", Objectpredict = pred.m0, break.times = c(0,1,2,3)) plot(m0, which = "traj.ind", Objectpredict = pred.m0, ID.ind = c(1,2)) ## Not run: library(dplyr) data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC %>% group_by(ID, num.visit) %>% mutate(SBPvisit = mean(SBP)) threeC$age65_CR <- NA threeC$age65_CR[which(threeC$dem == 1)] <- (threeC$age.last65[which(threeC$dem == 1)] +threeC$age.first65[which(threeC$dem == 1)])/2 threeC$age65_CR[which(threeC$dem == 0)] <- threeC$age.final65[which(threeC$dem == 0)] threeC$demCR <- threeC$dem threeC$deathCR <- NA threeC$deathCR[which(threeC$dem == 1)] <- 0 threeC$deathCR[which(threeC$dem == 0)]<-threeC$death[which(threeC$dem == 0)] threeC <- threeC %>% group_by(ID) %>% filter(age.visit65 <= age65_CR) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","age0_65", "demCR","deathCR", "age65_CR")] # Estimation of a lsmm with time-dependent variability model: m2 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) # Predictions: pred.m2 <- predict(m2, which = c("RE", "Y")) #Plot: plot(m2, which = "long.fit", Objectpredict = pred.m2, break.times = (seq(65,95,by = 2.5)-65)/10) plot(m2, which = "traj.ind", Objectpredict = pred.m2, ID.ind = c(3,120)) # Estimation of a lsjm with time-dependent variability model and # competing events: l2 <- lsjm(Objectlsmm = m2, survival_type = 'CR', formSurv_01 = ~ sex, formSurv_02 = ~ sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", delta1 = ~ demCR, delta2 = ~ deathCR, Time_T0 = ~ age0_65, Time_T = ~ age65_CR, nproc = 5, S1 = 1000, S2 = 2000) # Predictions: pred.l2 <- predict(l2, which = c("RE", "Y", "Cum")) # Plot: plot(l2, which = "long.fit", Objectpredict = pred.l2, break.times = (seq(65,95,by = 2.5)-65)/10) plot(l2, which = "traj.ind", Objectpredict = pred.l2, ID.ind = c(3,120)) plot(l2, which = "survival.fit", Objectpredict = pred.l2) ## End(Not run)
This function computes different predicted quantities. For a lsmm object, it is possible
to compute, for each subject, their random effects, their value of the marker and the residual
variability (for each measurement time)).
For a lsjm object we could also compute cumulative hazard function for each risk
transition.
## S3 method for class 'lsjm_classicCR' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_classicIDM' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_classicSingle' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_covDepCR' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_covDepIDM' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_covDepSingle' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_interintraCR' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_interintraIDM' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_interintraSingle' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsmm_classic' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsmm_covDep' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsmm_interintra' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...)## S3 method for class 'lsjm_classicCR' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_classicIDM' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_classicSingle' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_covDepCR' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_covDepIDM' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_covDepSingle' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_interintraCR' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_interintraIDM' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsjm_interintraSingle' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsmm_classic' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsmm_covDep' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...) ## S3 method for class 'lsmm_interintra' predict(object, which = "RE", Objectranef = NULL, data.long = NULL, ...)
object |
Either a |
which |
A vector of characters to indicate which predictions are computed.
|
Objectranef |
Optional |
data.long |
A dataframe containing the longitudinal data for making predictions. |
... |
Further arguments |
A table for each type of prediction (RE/Y/Cum)
predictREA table with predicted random effects for each subjects.
predictYA table with predicted marker and residual variability for each subjects and at each measurement time.
predictCum_01A table for predicted cumulative hazard function for transition 0-1.
predictCum_02A table for predicted cumulative hazard function for transition 0-2.
predictCum_12A table for predicted cumulative hazard function for transition 1-2.
grid.time.CumA vector of times for which the cumulative hazard functions are computed.
data <- data.frame( ID = rep(1:5, each = 3), time = rep(1:3, 5), y = rnorm(15), event = rep(rbinom(5,1,0.5), each = 3), time_event = rep(runif(5), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) pred.m0 <- predict(m0, which = c("RE","Y"), data.long = data) ## Not run: library(dplyr) data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","dem","death", "age.first65","age.last65","age.final65","age0_65")] m1 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l1 <- lsjm(m1, survival_type = 'IDM', formSurv_01=~1, formSurv_02=~sex, formSurv_12=~sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "slope", "variability"), sharedtype_12 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", hazardBase_12 = "Splines", delta1=~dem, delta2=~death, Time_T =~age.final65, Time_L =~age.last65, Time_R =~age.first65, Time_T0 =~age0_65, formSlopeFixed =~1, formSlopeRandom =~1, index_beta_slope = c(2), index_b_slope = c(2), nb.knots.splines = c(0,0,1), S1 = 1000, S2 = 2000, nproc = 5) pred.m1 <- predict(m1, which = c("RE","Y"), data.long = threeC_ex1) pred.l1 <- predict(l1, which = c("RE","Y","Cum"), data.long = threeC_ex1) ## End(Not run)data <- data.frame( ID = rep(1:5, each = 3), time = rep(1:3, 5), y = rnorm(15), event = rep(rbinom(5,1,0.5), each = 3), time_event = rep(runif(5), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) pred.m0 <- predict(m0, which = c("RE","Y"), data.long = data) ## Not run: library(dplyr) data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","dem","death", "age.first65","age.last65","age.final65","age0_65")] m1 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l1 <- lsjm(m1, survival_type = 'IDM', formSurv_01=~1, formSurv_02=~sex, formSurv_12=~sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "slope", "variability"), sharedtype_12 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", hazardBase_12 = "Splines", delta1=~dem, delta2=~death, Time_T =~age.final65, Time_L =~age.last65, Time_R =~age.first65, Time_T0 =~age0_65, formSlopeFixed =~1, formSlopeRandom =~1, index_beta_slope = c(2), index_b_slope = c(2), nb.knots.splines = c(0,0,1), S1 = 1000, S2 = 2000, nproc = 5) pred.m1 <- predict(m1, which = c("RE","Y"), data.long = threeC_ex1) pred.l1 <- predict(l1, which = c("RE","Y","Cum"), data.long = threeC_ex1) ## End(Not run)
ranef: the predicted random effects for all subjects
## S3 method for class 'lsjm_classicCR' ranef(object, ...) ## S3 method for class 'lsjm_classicIDM' ranef(object, ...) ## S3 method for class 'lsjm_classicSingle' ranef(object, ...) ## S3 method for class 'lsjm_covDepCR' ranef(object, ...) ## S3 method for class 'lsjm_covDepIDM' ranef(object, ...) ## S3 method for class 'lsjm_covDepSingle' ranef(object, ...) ## S3 method for class 'lsjm_interintraCR' ranef(object, ...) ## S3 method for class 'lsjm_interintraIDM' ranef(object, ...) ## S3 method for class 'lsjm_interintraSingle' ranef(object, ...) ## S3 method for class 'lsmm_classic' ranef(object, ...) ## S3 method for class 'lsmm_covDep' ranef(object, ...) ## S3 method for class 'lsmm_interintra' ranef(object, ...)## S3 method for class 'lsjm_classicCR' ranef(object, ...) ## S3 method for class 'lsjm_classicIDM' ranef(object, ...) ## S3 method for class 'lsjm_classicSingle' ranef(object, ...) ## S3 method for class 'lsjm_covDepCR' ranef(object, ...) ## S3 method for class 'lsjm_covDepIDM' ranef(object, ...) ## S3 method for class 'lsjm_covDepSingle' ranef(object, ...) ## S3 method for class 'lsjm_interintraCR' ranef(object, ...) ## S3 method for class 'lsjm_interintraIDM' ranef(object, ...) ## S3 method for class 'lsjm_interintraSingle' ranef(object, ...) ## S3 method for class 'lsmm_classic' ranef(object, ...) ## S3 method for class 'lsmm_covDep' ranef(object, ...) ## S3 method for class 'lsmm_interintra' ranef(object, ...)
object |
Either a lsmm object or a lsjm object |
... |
Further arguments |
A table with predicted random effects for each subjects.
data <- data.frame( ID = rep(1:5, each = 3), time = rep(1:3, 5), y = rnorm(15), event = rep(rbinom(5,1,0.5), each = 3), time_event = rep(runif(5), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) ranef.m0 <- ranef(m0) ## Not run: library(dplyr) data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","dem","death", "age.first65", "age.last65","age.final65","age0_65")] m1 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l1 <- lsjm(m1, survival_type = 'IDM', formSurv_01=~1, formSurv_02=~sex, formSurv_12=~sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "slope", "variability"), sharedtype_12 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", hazardBase_12 = "Splines", delta1=~dem, delta2=~death, Time_T =~age.final65, Time_L =~age.last65, Time_R =~age.first65, Time_T0 =~age0_65, formSlopeFixed =~1, formSlopeRandom =~1, index_beta_slope = c(2), index_b_slope = c(2), nb.knots.splines = c(0,0,1), S1 = 1000, S2 = 2000, nproc = 5) r1 <- ranef(m1) r1.1 <- ranef(l1) ## End(Not run)data <- data.frame( ID = rep(1:5, each = 3), time = rep(1:3, 5), y = rnorm(15), event = rep(rbinom(5,1,0.5), each = 3), time_event = rep(runif(5), each = 3) ) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) ranef.m0 <- ranef(m0) ## Not run: library(dplyr) data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","dem","death", "age.first65", "age.last65","age.final65","age0_65")] m1 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l1 <- lsjm(m1, survival_type = 'IDM', formSurv_01=~1, formSurv_02=~sex, formSurv_12=~sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "slope", "variability"), sharedtype_12 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", hazardBase_12 = "Splines", delta1=~dem, delta2=~death, Time_T =~age.final65, Time_L =~age.last65, Time_R =~age.first65, Time_T0 =~age0_65, formSlopeFixed =~1, formSlopeRandom =~1, index_beta_slope = c(2), index_b_slope = c(2), nb.knots.splines = c(0,0,1), S1 = 1000, S2 = 2000, nproc = 5) r1 <- ranef(m1) r1.1 <- ranef(l1) ## End(Not run)
The population-average probability of being free of any events at a given time $t$ and covariates
## S3 method for class 'lsjm_classicCR' survmarg(object, individual, time) ## S3 method for class 'lsjm_classicIDM' survmarg(object, individual, time) ## S3 method for class 'lsjm_classicSingle' survmarg(object, individual, time) ## S3 method for class 'lsjm_covDepCR' survmarg(object, individual, time) ## S3 method for class 'lsjm_covDepIDM' survmarg(object, individual, time) ## S3 method for class 'lsjm_covDepSingle' survmarg(object, individual, time) ## S3 method for class 'lsjm_interintraCR' survmarg(object, individual, time) ## S3 method for class 'lsjm_interintraIDM' survmarg(object, individual, time) ## S3 method for class 'lsjm_interintraSingle' survmarg(object, individual, time)## S3 method for class 'lsjm_classicCR' survmarg(object, individual, time) ## S3 method for class 'lsjm_classicIDM' survmarg(object, individual, time) ## S3 method for class 'lsjm_classicSingle' survmarg(object, individual, time) ## S3 method for class 'lsjm_covDepCR' survmarg(object, individual, time) ## S3 method for class 'lsjm_covDepIDM' survmarg(object, individual, time) ## S3 method for class 'lsjm_covDepSingle' survmarg(object, individual, time) ## S3 method for class 'lsjm_interintraCR' survmarg(object, individual, time) ## S3 method for class 'lsjm_interintraIDM' survmarg(object, individual, time) ## S3 method for class 'lsjm_interintraSingle' survmarg(object, individual, time)
object |
A lsjm object |
individual |
Subject profile for which we want to compute the probability |
time |
a numeric, the time $t$ at which we want to compute the probability |
A numeric, the population-average probability of being free of any events at a given time $t$ and chosen covariates
set.seed(456) data <- data.frame( ID = rep(1:100, each = 3), time = rep(0:2, 100), y = rnorm(300), event = rep(rbinom(100, 1, 0.5), each = 3), time_event = rep(runif(100, min = 0, max = 5), each = 3), covariate = rep(rbinom(100, size = 1, prob = 0.5), each = 3) ) # Keep only the observed time before time_event data <- subset(data, time < time_event) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) fit <- lsjm( Objectlsmm = m0, survival_type = "Single", formSurv_01 = ~ covariate, sharedtype_01 = "value", hazardBase_01 = "Weibull", delta1 = ~ event, Time_T = ~ time_event, S1 = 100, S2 = 100, nproc = 1, binit = c(1.44498682, -4.10877891, 0.23741874, -10.11422733, 0.06706379, -0.05305361, 0.94307564, 0.34785575, -0.08949800, 0.00814575) ) individual <- data[1, ] survmarg(fit, individual, time = 2) ## Not run: # Begining by estimating the examples from \code{lsmm} and \code{lsjm}, we then compute # the average-probability of being alive and without dementia at age 85 for a Women data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","dem","death", "age.first65","age.last65","age.final65","age0_65")] m1 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l1 <- lsjm(m1, survival_type = 'IDM', formSurv_01=~1, formSurv_02=~sex, formSurv_12=~sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "slope", "variability"), sharedtype_12 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", hazardBase_12 = "Splines", delta1=~dem, delta2=~death, Time_T =~age.final65, Time_L =~age.last65, Time_R =~age.first65, Time_T0 =~age0_65, formSlopeFixed =~1, formSlopeRandom =~1, index_beta_slope = c(2), index_b_slope = c(2), nb.knots.splines = c(0,0,1), S1 = 1000, S2 = 2000, nproc = 5) individual <- threeC_ex1[1,] survmarg(l1, individual, time = 2) ## End(Not run)set.seed(456) data <- data.frame( ID = rep(1:100, each = 3), time = rep(0:2, 100), y = rnorm(300), event = rep(rbinom(100, 1, 0.5), each = 3), time_event = rep(runif(100, min = 0, max = 5), each = 3), covariate = rep(rbinom(100, size = 1, prob = 0.5), each = 3) ) # Keep only the observed time before time_event data <- subset(data, time < time_event) m0 <- lsmm( formFixed = y ~ time, formRandom = ~ time, formGroup = ~ ID, formVar = "standard", timeVar = "time", data.long = data, S1 = 5, S2 = 5, nproc = 1 ) fit <- lsjm( Objectlsmm = m0, survival_type = "Single", formSurv_01 = ~ covariate, sharedtype_01 = "value", hazardBase_01 = "Weibull", delta1 = ~ event, Time_T = ~ time_event, S1 = 100, S2 = 100, nproc = 1, binit = c(1.44498682, -4.10877891, 0.23741874, -10.11422733, 0.06706379, -0.05305361, 0.94307564, 0.34785575, -0.08949800, 0.00814575) ) individual <- data[1, ] survmarg(fit, individual, time = 2) ## Not run: # Begining by estimating the examples from \code{lsmm} and \code{lsjm}, we then compute # the average-probability of being alive and without dementia at age 85 for a Women data(threeC) threeC$age.visit65 <- (threeC$age.visit-65)/10 threeC$SBP <- threeC$SBP/10 threeC <- threeC threeC <- dplyr::group_by(threeC, ID, num.visit) threeC <- dplyr::mutate(threeC, SBPvisit = mean(SBP)) threeC_ex1 <- threeC[!duplicated(threeC[, c("ID", "num.visit")]), c("ID", "SBPvisit", "age.visit65", "sex","dem","death", "age.first65","age.last65","age.final65","age0_65")] m1 <- lsmm(formFixed = SBPvisit ~ age.visit65, formRandom = ~ age.visit65, formGroup = ~ ID, timeVar = 'age.visit65', data.long = threeC_ex1, formVar = "cov-dependent", formFixedVar = ~ age.visit65+sex, formRandomVar = ~ age.visit65, correlated_re = FALSE, S1 = 500, S2 = 1000, nproc = 1) l1 <- lsjm(m1, survival_type = 'IDM', formSurv_01=~1, formSurv_02=~sex, formSurv_12=~sex, sharedtype_01 = c("value", "variability"), sharedtype_02 = c("value", "slope", "variability"), sharedtype_12 = c("value", "variability"), hazardBase_01 = "Weibull", hazardBase_02 = "Weibull", hazardBase_12 = "Splines", delta1=~dem, delta2=~death, Time_T =~age.final65, Time_L =~age.last65, Time_R =~age.first65, Time_T0 =~age0_65, formSlopeFixed =~1, formSlopeRandom =~1, index_beta_slope = c(2), index_b_slope = c(2), nb.knots.splines = c(0,0,1), S1 = 1000, S2 = 2000, nproc = 5) individual <- threeC_ex1[1,] survmarg(l1, individual, time = 2) ## End(Not run)
A random subsample of 500 subjects from the French Three-Cities cohort, aimed at assessing the relation between vascular factors and dementia in the elderly, for the example of the LSJM package.
data(threeC)data(threeC)
A data frame with 5248 rows and 13 variables:
id of each subject
indicator of the apoe4 gene
Educational level (0 = less than 10 years, 1 = more than 10 years)
systolic blood pressure in mmHg
age at measurement of SBP
age at death or censoring (last news)
age at entry in the cohort
age of last visit without dementia
age at visit diagnosis for dementia
sex of the subject
indicator of dementia
indicator of death
visit identifier
(age.visit-65)/10
(age.final-65)/10
(age.last-65)/10
(age.first-65)/10
(age0-65)/10
The sample includes participants without dementia at baseline and aged 65 years old or older. Repeated measures of systolic blood pressure were collected over a maximum period of 20 years. At each visit, systolic blood pressure was measured two or three times.