Skip to contents

This function performs the two-stage landmarking analysis.

Usage

fit_LME_landmark(
  data_long,
  x_L,
  x_hor,
  predictors_LME,
  responses_LME,
  predictors_LME_time,
  responses_LME_time,
  random_slope_longitudinal = TRUE,
  random_slope_survival = TRUE,
  include_data_after_x_L = TRUE,
  individual_id,
  k,
  cross_validation_df,
  standardise_time = FALSE,
  lme_control = nlme::lmeControl(),
  event_time,
  event_status,
  survival_submodel = c("standard_cox", "cause_specific", "fine_gray"),
  b
)

Arguments

data_long

Data frame or list of data frames each corresponding to a landmark age x_L (each element of the list must be named the value of x_L it corresponds to). Each data frame contains repeat measurements data and time-to-event data in long format.

x_L

Numeric specifying the landmark time(s)

x_hor

Numeric specifying the horizon time(s)

predictors_LME

Vector of character strings specifying the column names in data_long which correspond to the predictor variables in the LME model

responses_LME

Vector of character strings specifying the column names in data_long which correspond to the response variables in the LME model. Values may be missing (NA), for example when the responses are measured at different times; missing values are ignored.

predictors_LME_time

Vector of character strings specifying the column names in data_long which contains the time at which the predictor variables were recorded. This should either be length 1 or the same length as predictors_LME. In the latter case the order of elements must correspond to the order of elements in predictors_LME.

responses_LME_time

Vector of character strings specifying the column names in data_long which contain the times at which response variables were recorded. This should either be length 1 or the same length as responses_LME. In the latter case the order of elements must correspond to the order of elements in responses_LME. A time may be missing when the corresponding response is missing.

random_slope_longitudinal

Boolean indicating whether to include a random slope in the LME model. See Details section of fit_LME_longitudinal for more information.

random_slope_survival

Boolean indicating whether to include the random slope estimate from the LME model as a covariate in the survival submodel. See Details section of fit_LME_longitudinal for more information. If standardise_time = TRUE, the slopes are on the standardised time scale, i.e. per standard deviation of the response times.

include_data_after_x_L

Boolean indicating whether to include all longitudinal data, including data after the landmark age x_L, in the model development dataset (default TRUE). Using measurements after the landmark age can improve the estimates of the LME model, but it conditions on individuals remaining under observation after the landmark age, and how often individuals are measured may itself be related to their outcome. With cross-validation, only the measurements of individuals in the training folds are used to fit the LME model, so the measurements after the landmark age of the individuals being predicted are never used; comparing the cross-validated performance with include_data_after_x_L = FALSE shows whether using these data improves the predictions. See Details section of fit_LME_longitudinal for more information.

individual_id

Character string specifying the column name in data_long which contains the individual identifiers

k

Integer specifying the number of folds for cross-validation. An alternative to setting parameter cross_validation_df for performing cross-validation; if both are missing no cross-validation is used.

cross_validation_df

List of data frames containing the cross-validation fold each individual is assigned to. Each data frame in the list should be named according to the landmark time x_L that they correspond. Each data frame should contain the columns individual_id and a column cross_validation_number which contains the cross-validation fold of the individual. An alternative to setting parameter k for performing cross-validation; if both are missing no cross-validation is used.

standardise_time

Boolean indicating whether to standardise the time variable in the LME model by subtracting the mean and dividing by the standard deviation. See Details section of fit_LME_longitudinal for more information.

lme_control

Object created using nlme::lmeControl(), which will be passed to the control argument of the lme function

event_time

Character string specifying the column name in data_long which contains the event time

event_status

Character string specifying the column name in data_long which contains the event status (where 0=censoring, 1=event of interest, if there are competing events these are labelled 2 or above).

survival_submodel

Character string specifying which survival submodel to use. Three options: the standard Cox model i.e. no competing risks ("standard_cox"), the cause-specific regression model ("cause_specific"), or the Fine Gray regression model ("fine_gray")

b

No longer used (deprecated in Landmarking 1.1.0). Standard errors of the AUC and Brier score are now calculated from the influence function with riskRegression::Score() rather than by bootstrapping; a warning is given if b is supplied.

Value

List containing containing information about the landmark model at each of the landmark times. Each element of this list is named the corresponding landmark time, and is itself a list containing elements: data, model_longitudinal, model_LME, model_LME_standardise_time, model_survival, prediction_error, and x_hor.

data has one row for each individual in the risk set at x_L and contains the value of the predictors_LME using the LOCF approach and predicted values of the responses_LME using the LME model at the landmark time x_L. It also includes the predicted probability that the event of interest has occurred by time x_hor, labelled as "event_prediction". There is one row for each individual.

model_longitudinal indicates that the longitudinal approach is LME.

model_LME contains the output from the lme function from package nlme. For a model using cross-validation, model_LME contains a list of outputs with each element in the list corresponds to a different cross-validation fold.

model_LME_standardise_time contains a list of two objects mean_response_time and sd_response_time if the parameter standardise_time=TRUE is used. This is the mean and standard deviation used to normalise times when fitting the LME model. For a model using cross-validation, it contains a list of these for each cross-validation fold.

model_survival contains the outputs from the survival submodel functions, including the estimated parameters of the model. For a model using cross-validation, model_survival will contain a list of outputs with each element in the list corresponding to a different cross-validation fold.

prediction_error contains a list with the time-dependent AUC and the Brier score, and their standard errors, at time x_hor. See ?get_model_assessment for details.

x_hor is the horizon time used to fit the model. predict does not predict beyond this time.

Details

Firstly, this function selects the individuals in the risk set at the landmark time x_L. Specifically, the individuals in the risk set are those that have entered the study before the landmark time x_L (there is at least one observation for each of the predictors_LME and responses_LME on or before x_L) and exited the study after the landmark age (event_time is greater than x_L). Individuals without an observation of each of the responses_LME on or before x_L are excluded from the survival submodel with a warning, but their measurements are still used to fit the LME model.

Secondly, if the option to use cross validation is selected (using either parameter k or cross_validation_df), then an extra column cross_validation_number is added with the cross-validation folds. If parameter k is used, then the function add_cv_number randomly assigns these folds. For more details on this function see ?add_cv_number. If the parameter cross_validation_df is used, then the folds specified in this data frame are added. If cross-validation is not selected then the landmark model is fit to the entire group of individuals in the risk set (this is both the training and test dataset).

Thirdly, the landmark model is then fit to each of the training datasets. There are two parts to fitting the landmark model: using the longitudinal data and using the survival data. Using the longitudinal data is the first stage, in which an LME model is fitted and used to predict the values of the responses_LME at the landmark age. See ?fit_LME_longitudinal more for information about this stage. Using the survival data is the second stage, in which the individuals are censored at the time horizon x_hor and the survival model is fitted. See ?fit_survival_model more for information about this stage.

With cross-validation, both stages are nested within each fold: for each fold, the LME model is fitted to the other folds (with time standardised using their measurements) and used to predict the values of the responses_LME at the landmark age for every individual, from their measurements up to the landmark age. The survival model is then fitted to the individuals in the other folds and used to predict the risk for the individuals in the fold. So no data from a fold are used to fit the models that predict it. In versions of Landmarking before 1.1.0, the survival model for a fold was trained on predictions from LME models that had been fitted using data from that fold, which could make the cross-validated performance optimistic.

Fourthly, the performance of the model is then assessed on the set of predictions from the entire set of individuals in the risk set by calculating the time-dependent AUC and Brier score. This is performed using get_model_assessment. See ?get_model_assessment more for information about this function.

Author

Isobel Barrott isobel.barrott@gmail.com

Examples

# \donttest{
library(Landmarking)
data(data_repeat_outcomes)
data_model_landmark_LME <-
  fit_LME_landmark(
    data_long = data_repeat_outcomes,
    x_L = c(60, 61),
    x_hor = c(65, 66),
    k = 10,
    predictors_LME = c("ethnicity", "smoking", "diabetes"),
    predictors_LME_time = "response_time_sbp_stnd",
    responses_LME = c("sbp_stnd", "tchdl_stnd"),
    responses_LME_time = c("response_time_sbp_stnd", "response_time_tchdl_stnd"),
    individual_id = "id",
    standardise_time = TRUE,
    lme_control = nlme::lmeControl(maxIter = 100, msMaxIter = 100),
    event_time = "event_time",
    event_status = "event_status",
    survival_submodel = "cause_specific"
  )
#> Warning: 864 individuals have been removed from the model building as they are not in the risk set at landmark age 60
#> Warning: 737 individuals have been removed from the model building as they are not in the risk set at landmark age 61
#> Warning: 23 individuals have been removed from the survival submodel at landmark age 60 as they do not have an observation of each of responses_LME on or before the landmark age (their measurements are still used to fit the LME model)
#> Fitting longitudinal and survival submodels in each cross-validation fold, landmark age 60
#> Warning: Loglik converged before variable  2 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  2 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  2 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3,4 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  2 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  2,4 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  2 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  2 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  2 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  2 ; coefficient may be infinite. 
#> Complete, landmark age 60
#> Warning: 8 individuals have been removed from the survival submodel at landmark age 61 as they do not have an observation of each of responses_LME on or before the landmark age (their measurements are still used to fit the LME model)
#> Fitting longitudinal and survival submodels in each cross-validation fold, landmark age 61
#> Warning: Loglik converged before variable  1,3,4,6 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3,4 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3,4 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3,4 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3,4 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3,4 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3,4 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3,4 ; coefficient may be infinite. 
#> Warning: Loglik converged before variable  1,3,4 ; coefficient may be infinite. 
#> Complete, landmark age 61
# }