Title: | Analysis using Landmark Models |
---|---|
Description: | The landmark approach allows survival predictions to be updated dynamically as new measurements from an individual are recorded. The idea is to set predefined time points, known as "landmark times", and form a model at each landmark time using only the individuals in the risk set. This package allows the longitudinal data to be modelled either using the last observation carried forward or linear mixed effects modelling. There is also the option to model competing risks, either through cause-specific Cox regression or Fine-Gray regression. To find out more about the methods in this package, please see <https://isobelbarrott.github.io/Landmarking/articles/Landmarking>. |
Authors: | Isobel Barrott [aut, cre], Jessica Barrett [aut], Ruth Keogh [ctb], Michael Sweeting [ctb], David Stevens [ctb] |
Maintainer: | Isobel Barrott <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.2 |
Built: | 2024-11-02 04:01:22 UTC |
Source: | https://github.com/isobelbarrott/landmarking |
Randomly assigns a k-fold cross-validation number to each individual in a dataset.
add_cv_number(data_long, individual_id, k, seed = 1)
add_cv_number(data_long, individual_id, k, seed = 1)
data_long |
Data frame in long format i.e. there may be more than one row per individual |
individual_id |
Character string specifying the column name in |
k |
Integer specifying the number of folds for cross-validation. |
seed |
The value of the seed (default is 1) |
This function randomly divides the n
individual IDs
into k
groups, each with n/k
members (or as close to this number as possible).
Data frame data_long
updated to contain a new column cross_validation_number
indicating the fold to which the individual has been assigned.
Isobel Barrott [email protected]
data(data_repeat_outcomes) data_repeat_outcomes <- add_cv_number(data_long = data_repeat_outcomes, individual_id = "id", k = 10)
data(data_repeat_outcomes) data_repeat_outcomes <- add_cv_number(data_long = data_repeat_outcomes, individual_id = "id", k = 10)
A simulated dataset which is a combination of longitudinal (repeat measurement) data and time-to-event data. This dataset contains simulated data from 3000 patients.
The longitudinal (repeat measurement) data is formed using an LME model, whose parameters were based on CVD risk assessments recorded at primary care practices in New Zealand.
A LME model was fitted to this dataset and values of sbp_stnd
and tchdl_stnd
were estimated at landmark age 60. These values (along with the other baseline covariates)
were used to simulate time-to-event data from a
cause specific model with parameters based on CVD events of patients
at primary care practices in New Zealand.
data_repeat_outcomes
data_repeat_outcomes
A dataset with 9031 rows and 12 columns:
Patient ID
Smoking status, 0 indicates the patient has never smoked, 1 indicates the patient has quit smoking, and 2 indicates the patient is a current smoker
Diabetes status, 0 indicates the patient is not diagnosed with diabetes, and 1 indicates the patient is diagnosed with diabetes
Ethnicity, one of five ethnicities
Date of birth
An index indicating assessment number for a patient
Standardised systolic blood pressure
Standardised total cholesterol to HDL ratio
Age that total cholesterol to HDL ratio was recorded
Age that systolic blood pressure was recorded, this is the same as the date that the fixed measures were recorded
Event status, 0 indicates censoring, 1 indicates CVD event, and 2 indicates death from other causes
Event time
This function is a helper function for fit_LME_landmark
.
find_LME_risk_set( data_long, x_L, x_hor, predictors_LME, predictors_LME_time, responses_LME, responses_LME_time, individual_id, event_time, event_status )
find_LME_risk_set( data_long, x_L, x_hor, predictors_LME, predictors_LME_time, responses_LME, responses_LME_time, individual_id, event_time, event_status )
data_long |
Data frame in long format i.e. there may be more than one row per individual |
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 |
predictors_LME_time |
Vector of character strings specifying the column names in |
responses_LME |
Vector of character strings specifying the column names in |
responses_LME_time |
Vector of character strings specifying the column names in |
individual_id |
Character string specifying the column name in |
event_time |
Character string specifying the column name in |
event_status |
Character string specifying the column name in |
This function finds the risk set for each of landmark times in x_L. This means that each of the individuals has a LME value for all predictors_LME at the landmark time and has not experienced an event up to (and including) the landmark time.
List with elements corresponding to each landmark time in x_L. Each element is a data frame, containing only those individuals in the risk set at each of the landmark times x_L.
Isobel Barrott [email protected]
This function is a helper function for fit_LOCF_landmark
.
find_LOCF_risk_set( data_long, x_L, x_hor, covariates, covariates_time, individual_id, event_time, event_status )
find_LOCF_risk_set( data_long, x_L, x_hor, covariates, covariates_time, individual_id, event_time, event_status )
data_long |
Data frame in long format i.e. there may be more than one row per individual |
x_L |
Numeric specifying the landmark time(s) |
x_hor |
Numeric specifying the horizon time(s) |
covariates |
Vector of character strings specifying the column names in |
covariates_time |
Vector of character strings specifying the column names in |
individual_id |
Character string specifying the column name in |
event_time |
Character string specifying the column name in |
event_status |
Character string specifying the column name in |
This function finds the risk set for each of landmark times in x_L. This means that each of the individuals has a LOCF value for all covariates at the landmark time and has not experienced an event up to (and including) the landmark time.
List with elements corresponding to each landmark time in x_L. Each element is a data frame, containing only those individuals in the risk set at each of the landmark times x_L.
Isobel Barrott [email protected]
This function performs the two-stage landmarking analysis.
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 )
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 )
data_long |
Data frame or list of data frames each corresponding to a landmark age |
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 |
responses_LME |
Vector of character strings specifying the column names in |
predictors_LME_time |
Vector of character strings specifying the column names in |
responses_LME_time |
Vector of character strings specifying the column names in |
random_slope_longitudinal |
Boolean indicating whether to include a random slope in the LME model. See Details section of |
random_slope_survival |
Boolean indicating whether to include the random slope estimate from the LME model.
See Details section of |
include_data_after_x_L |
Boolean indicating whether to include all longitudinal data, including data after the landmark age |
individual_id |
Character string specifying the column name in |
k |
Integer specifying the number of folds for cross-validation.
An alternative to setting parameter |
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 |
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 |
lme_control |
Object created using |
event_time |
Character string specifying the column name in |
event_status |
Character string specifying the column name in |
survival_submodel |
Character string specifying which survival submodel to
use. Three options: the standard Cox model i.e. no competing risks ( |
b |
Integer specifying the number of bootstrap samples to take when calculating standard error of c-index and Brier score |
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
).
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 and is performed using fit_LME_longitudinal
. See ?fit_LME_longitudinal
more for information about this function.
Using the survival data is the second stage and is performed using fit_survival_model
. This function censors the
individuals at the time horizon x_L
and fits the survival model. See ?fit_survival_model
more for information about this function.
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 Brier score and C-index.
This is performed using get_model_assessment
. See ?get_model_assessment
more for information about this function.
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
, and prediction_error
.
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 use to normalise times when fitting the LME model.
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 indicating the c-index and Brier score at time x_hor
and their standard errors if parameter b
is used.
Isobel Barrott [email protected]
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" )
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" )
This function is a helper function for fit_LME_landmark
.
fit_LME_longitudinal( data_long, x_L, predictors_LME, responses_LME, predictors_LME_time, responses_LME_time, standardise_time = FALSE, random_slope_longitudinal = TRUE, random_slope_survival = TRUE, include_data_after_x_L = TRUE, cv_name = NA, individual_id, lme_control = nlme::lmeControl() )
fit_LME_longitudinal( data_long, x_L, predictors_LME, responses_LME, predictors_LME_time, responses_LME_time, standardise_time = FALSE, random_slope_longitudinal = TRUE, random_slope_survival = TRUE, include_data_after_x_L = TRUE, cv_name = NA, individual_id, lme_control = nlme::lmeControl() )
data_long |
Data frame containing repeat measurement data and time-to-event data in long format. |
x_L |
Numeric specifying the landmark time(s) |
predictors_LME |
Vector of character strings specifying the column names in |
responses_LME |
Vector of character strings specifying the column names in |
predictors_LME_time |
Vector of character strings specifying the column names in |
responses_LME_time |
Vector of character strings specifying the column names in |
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 |
random_slope_longitudinal |
Boolean indicating whether to include a random slope in the LME model. See Details section of |
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 |
include_data_after_x_L |
Boolean indicating whether to include all longitudinal data, including data after the landmark age |
cv_name |
Character string specifying the column name in |
individual_id |
Character string specifying the column name in |
lme_control |
Object created using |
For an individual , the LME model can be written as
where
is the vector of responses at different time points for the individual
is the matrix of predictors for the fixed effects at these time points
is the vector of coefficients for the fixed effects
is the matrix of predictors for the random effects
is the matrix of coefficients for the random effects
is the error term, typically from N(0,
)
By using an LME model to fit repeat measures data, rather than a linear model, we can allow measurements from the same individuals to be more similar than measurements from different individuals. This is done through the random intercept and/or random slope.
Extending this model to the case where there are multiple random effects, denoted , we have
Typically the random effects are assumed to be from the multivariate normal (MVN) distribution
and we choose a certain covariance structure for
. The function
fit_LME_landmark
uses this distribution with
unstructured covariance for the random effects when fitting the LME model (i.e. no constraints are imposed on the values).
To fit the LME model the function lme
from the package nlme
is used.
The random intercept is always included in the LME model.
Additionally, the random slope can be included in the LME model using the parameter random_slope_longitudinal=TRUE
.
It is important to distinguish between the validation set and the development set for fitting the LME model in this function.
The development dataset either includes all the repeat measurements (including those after the landmark age x_L
), or only the repeat measurements
recorded up to and including the landmark age x_L
. This is controlled using the parameter include_data_after_x_L
.
The validation set only includes the repeat measurements recorded up until and including the landmark age x_L
,
i.e. it does not include future data in its predictions.
Using the fitted model, the values of the best linear unbiased predictions (BLUPs)
at the landmark age x_L
are calculated. These BLUPs are the predictions of the values of the responses_LME
the landmark age x_L
. The values of the predictors in this prediction are the LOCF values of the predictors_LME
at the landmark age x_L
. In the function fit_LME_landmark
, these predictions are used as covariates in the survival
model along with the LOCF values of predictors_LME
. Additionally, the estimated value of the random slope can
be included as predictors in the survival model using the parameter random_slope_survival=TRUE
.
There is an important consideration about fitting the linear mixed effects model. As the variable responses_LME_time
gets further from 0, the random effects coefficients get closer to 0. This causes computational issues
as the elements in the covariance matrix of the random effects, , are constrained to
be greater than 0. Using parameter
standard_time=TRUE
can prevent this issue by standardising the
time variables to ensure that the responses_LME_time
values are not too close to 0.
List containing elements:
data_longitudinal
, model_longitudinal
, model_LME
, and model_LME_standardise_time
.
data_longitudinal
has one row for each individual in the risk set at x_L
and
contains the value of the covariates at the landmark time x_L
of the predictors_LME
using the LOCF model and
responses_LME
using the LME model.
model_longitudinal
indicates that the LME approach is used.
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.
This function performs the two-stage landmarking analysis.
fit_LOCF_landmark( data_long, x_L, x_hor, covariates, covariates_time, k, cross_validation_df, individual_id, event_time, event_status, survival_submodel = c("standard_cox", "cause_specific", "fine_gray"), b )
fit_LOCF_landmark( data_long, x_L, x_hor, covariates, covariates_time, k, cross_validation_df, individual_id, event_time, event_status, survival_submodel = c("standard_cox", "cause_specific", "fine_gray"), b )
data_long |
Data frame or list of data frames each corresponding to a landmark age |
x_L |
Numeric specifying the landmark time(s) |
x_hor |
Numeric specifying the horizon time(s) |
covariates |
Vector of character strings specifying the column names in |
covariates_time |
Vector of character strings specifying the column names in |
k |
Integer specifying the number of folds for cross-validation. An alternative to setting parameter |
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 |
individual_id |
Character string specifying the column name in |
event_time |
Character string specifying the column name in |
event_status |
Character string specifying the column name in |
survival_submodel |
Character string specifying which survival submodel to
use. Three options: the standard Cox model i.e. no competing risks ( |
b |
Integer specifying the number of bootstrap samples to take when calculating standard error of c-index and Brier score |
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 random_effects
on or before x_L
) and
exited the study after the landmark age (event_time
is greater than x_L
).
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 and is performed using fit_LOCF_longitudinal
. See ?fit_LOCF_longitudinal
more for information about this function.
This function censors the
individuals at the time horizon x_L
and fits the survival model. Using the survival data is the second stage and is performed using fit_survival_model
. See ?fit_survival_model
more for information about this function.
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 Brier score and C-index.
This is performed using get_model_assessment
. See ?get_model_assessment
more for information about this function.
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_survival
, and prediction_error
.
data
has one row for each individual in the risk set at x_L
and
contains the value of the covariates
at the landmark time x_L
using the LOCF approach. 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 LOCF.
model_survival
contains the outputs from the function used to fit the survival submodel, including the estimated parameters of the model.
For a model using cross-validation, model_survival
contains a list of outputs with each
element in the list corresponding to a different cross-validation fold. For more information on how the survival model is fitted
please see ?fit_survival_model
which is a function used within fit_LOCF_landmark
.
prediction_error
contains a list indicating the c-index and Brier score at time x_hor
and their standard errors if parameter b
is used.
For more information on how the prediction error is calculated
please see ?get_model_assessment
which is the function used to do this within fit_LOCF_landmark
.
Isobel Barrott [email protected]
library(Landmarking) data(data_repeat_outcomes) data_model_landmark_LOCF <- fit_LOCF_landmark( data_long = data_repeat_outcomes, x_L = c(60, 61), x_hor = c(65, 66), covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), k = 10, individual_id = "id", event_time = "event_time", event_status = "event_status", survival_submodel = "cause_specific" )
library(Landmarking) data(data_repeat_outcomes) data_model_landmark_LOCF <- fit_LOCF_landmark( data_long = data_repeat_outcomes, x_L = c(60, 61), x_hor = c(65, 66), covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), k = 10, individual_id = "id", event_time = "event_time", event_status = "event_status", survival_submodel = "cause_specific" )
This function is a helper function for fit_LOCF_landmark
.
fit_LOCF_longitudinal( data_long, x_L, covariates, covariates_time, cv_name = NA, individual_id )
fit_LOCF_longitudinal( data_long, x_L, covariates, covariates_time, cv_name = NA, individual_id )
data_long |
Data frame in long format i.e. there may be more than one row per individual |
x_L |
Numeric specifying the landmark time(s) |
covariates |
Vector of character strings specifying the column names in |
covariates_time |
Vector of character strings specifying the column names in |
cv_name |
Character string specifying the column name in |
individual_id |
Character string specifying the column name in |
This function extracts the LOCF value for each of the covariates
in data_long
up to (and including) time x_L
.
List containing data_longitudinal
, model_longitudinal
, and call
.
data_longitudinal
has one row for each individual in data_long
and
contains the LOCF value of covariates
at the landmark time x_L
.
model_longitudinal
indicates that the LOCF approach is used.
call
contains the call of the function.
Isobel Barrott [email protected]
This function is a helper function for fit_LOCF_landmark_model
and fit_LME_landmark_model
.
fit_survival_model( data, individual_id, cv_name = NA, covariates, event_time, event_status, survival_submodel = c("standard_cox", "cause_specific", "fine_gray"), x_hor )
fit_survival_model( data, individual_id, cv_name = NA, covariates, event_time, event_status, survival_submodel = c("standard_cox", "cause_specific", "fine_gray"), x_hor )
data |
Data frame containing covariates and time-to-event data, one row for each individual. |
individual_id |
Character string specifying the column name in |
cv_name |
Character string specifying the column name in |
covariates |
Vector of character strings specifying the column names in |
event_time |
Character string specifying the column name in |
event_status |
Character string specifying the column name in |
survival_submodel |
Character string specifying which survival submodel to
use. Three options: the standard Cox model i.e. no competing risks ( |
x_hor |
Numeric specifying the horizon time(s) |
This function fits the survival model from the landmark model framework. The individuals are censored at the time horizon x_hor
and the survival model is fitted with
covariates specified in parameter covariates
.
For the survival model, there are three choices of model:
the standard Cox model, this is a wrapper function for coxph
from the package survival
the cause-specific model, this is a wrapper function for CSC
from package riskRegression
the Fine Gray model, this is a wrapper function for FGR
from package riskRegression
The latter two models estimate the probability of the event of interest in the presence of competing events.
List containing data_survival
and model_survival
data_survival
contains the predicted risk of event by the horizon time x_hor
.
model_survival
contains the outputs from the function used to fit the survival submodel, including the estimated parameters of the model.
For a model using cross-validation, model_survival
contains a list of outputs with each
element in the list corresponding to a different cross-validation fold.
Isobel Barrott [email protected]
Performs model assessment by computing the C-index and Brier score at time x_hor
. There is the option
to calculate their standard errors using bootstraping.
get_model_assessment( data, individual_id, event_prediction, event_status, event_time, x_hor, b )
get_model_assessment( data, individual_id, event_prediction, event_status, event_time, x_hor, b )
data |
Data frame containing survival outcomes and the event predictions from the model, there should be one row for each individual |
individual_id |
Character string specifying the column name in |
event_prediction |
Character string specifying the column name in |
event_status |
Character string specifying the column name in |
event_time |
Character string specifying the column name in |
x_hor |
Numeric specifying the horizon time(s) |
b |
Integer specifying the number of bootstrap samples to take when calculating standard error of c-index and Brier score |
There are two factors in assessing the performance of a prediction model; its
discrimination and its calibration. The c-index is a commonly used metric which assesses
discrimination, this refers to the ability of the model to separate individuals into
those that will have an event and those that will not. The c-index at a horizon time x_hor
looks at the pairs of individuals where one individual has the event at a time T and the other has not had the event at time T.
It is calculated as the proportion of these pairs where their relative risk prediction agrees with the
actual outcomes for the two individuals. This is extended to the competing risks case
by comparing individuals where one had the event of interest at time T and the other individual either
did not experience the event before this time T or experienced a competing event.
The Brier score gives an indication of the calibration of a model (and its discrimination to an extent), this refers to the agreement between the risk prediction and the outcome. The Brier score is calculated as the average mean squared error of the predicted risk and the event outcome (where an event is 1 and not experiencing the event is 0). This is extended to the competing risks case by including the competing risk events as not experiencing the event.
For both the c-index and Brier score calculations, inverse probability censoring weighting (IPCW) is used to create weights which account for the occurrence of censoring. The censoring model assumes for this function is the Kaplan Meier model, i.e. censoring occurs independently of covariates.
The c-index is calculated using the cindex
function in package pec
. The Brier score is calculated using
pec
function in package pec
.
List containing C-index, Brier score and their standard errors
Isobel Barrott [email protected]
## Not run: library(Landmarking) data(data_repeat_outcomes) data_model_landmark_LOCF <- fit_LOCF_landmark( data_long = data_repeat_outcomes, x_L = c(60, 61), x_hor = c(65, 66), covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), k = 10, individual_id = "id", event_time = "event_time", event_status = "event_status", survival_submodel = "cause_specific" ) get_model_assessment(data = data_model_landmark_LOCF[["60"]]$data, individual_id = "id", event_prediction = "event_prediction", event_status = "event_status", event_time = "event_time", x_hor = 65, b = 100) ## End(Not run)
## Not run: library(Landmarking) data(data_repeat_outcomes) data_model_landmark_LOCF <- fit_LOCF_landmark( data_long = data_repeat_outcomes, x_L = c(60, 61), x_hor = c(65, 66), covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), k = 10, individual_id = "id", event_time = "event_time", event_status = "event_status", survival_submodel = "cause_specific" ) get_model_assessment(data = data_model_landmark_LOCF[["60"]]$data, individual_id = "id", event_prediction = "event_prediction", event_status = "event_status", event_time = "event_time", x_hor = 65, b = 100) ## End(Not run)
This function allows the user to make out-of-sample predictions from an LME model.
mixoutsamp(model, newdata)
mixoutsamp(model, newdata)
model |
Object of class |
newdata |
Data frame containing data for which to make predictions. The response variable should be set to NA for the rows of the data the user wishes to make predictions for. The columns in the data should have the same names as those used to fit the model. The variables should also be of the same type as in the data used to fit the mixed model (numeric, factor etc). |
List containing preddata
and random
. Data frame preddata
is a version of newdata
updated to contain columns corresponding to the fixed effects values (fixed
),
random effects values (random
), and fitted values (fitted
).
Data frame random
contains the values of random effects components for each individual.
This code was originally written by Ruth Keogh (London School of Hygiene and Tropical Medicine) which can be viewed at github.com/ruthkeogh/landmark_CF. There have been further contributions from Jessica Barrett (MRC Biostatistics Unit, University of Cambridge), David Stevens (University of Liverpool), and Mike Sweeting (University of Leicester).
Creates a calibration plot for the landmark model fitted by fit_LME_landmark_model
or fit_LOCF_landmark_model
.
This function plots the observed frequencies of the event of interest against the predicted probabilities of the event of interest.
## S3 method for class 'landmark' plot(x, x_L, n, x_lims, y_lims, ...)
## S3 method for class 'landmark' plot(x, x_L, n, x_lims, y_lims, ...)
x |
Object inheriting the class |
x_L |
Numeric specifying the landmark time. This indicates which landmark model in |
n |
Numeric specifying the number of bins to use. |
x_lims |
Vector of length 2 specifying the limits of the x axes |
y_lims |
Vector of length 2 specifying the limits of the y axes |
... |
Arguments passed to |
This function bins the predicted probabilities of the event of interest into n
bins. The event of interest is the event with
event_status=1
when fitting the landmark model. For each of the n
sets of individuals, the Aalen-Johansen estimator is fit to that set
and used to calculate the risk of an event at the horizon time. The predictions (from the landmark model) and the observed frequencies
(from the Aalen-Johansen estimator) are plotted against each other. For a perfect prediction model, the points will be plotted along the y=x line.
Calibration plot showing the value of predicted probabilities against observed frequencies, with a y=x
line.
library(Landmarking) data(data_repeat_outcomes) data_model_landmark_LOCF <- fit_LOCF_landmark( data_long = data_repeat_outcomes, x_L = c(60, 61), x_hor = c(65, 66), covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), k = 10, individual_id = "id", event_time = "event_time", event_status = "event_status", survival_submodel = "cause_specific" ) plot(x=data_model_landmark_LOCF,x_L=60,n=5) plot(x=data_model_landmark_LOCF,x_L=61,n=5)
library(Landmarking) data(data_repeat_outcomes) data_model_landmark_LOCF <- fit_LOCF_landmark( data_long = data_repeat_outcomes, x_L = c(60, 61), x_hor = c(65, 66), covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), k = 10, individual_id = "id", event_time = "event_time", event_status = "event_status", survival_submodel = "cause_specific" ) plot(x=data_model_landmark_LOCF,x_L=60,n=5) plot(x=data_model_landmark_LOCF,x_L=61,n=5)
This function predicts the risk of an event for new data using the landmark model fitted by fit_LME_landmark
or fit_LOCF_landmark
.
The 'event' is defined as event for which event_status
is 1.
## S3 method for class 'landmark' predict(object, x_L, x_hor, newdata, cv_fold = NA, ...)
## S3 method for class 'landmark' predict(object, x_L, x_hor, newdata, cv_fold = NA, ...)
object |
Object inheriting the class |
x_L |
Numeric specifying the landmark time. This indicates which landmark model in |
x_hor |
Numeric specifying the horizon time. The function assesses the risk of event before this time. |
newdata |
Data frame containing new data to return the risk prediction of the event of interest. The data should be in in long format
and the columns must contain the covariates and time variables that are used to fit the model.
For the LME model this the variables |
cv_fold |
If cross validation is used to fit |
... |
Arguments passed on to |
Data frame newdata
updated to contained a new column event_prediction
library(Landmarking) data(data_repeat_outcomes) data_model_landmark_LOCF <- fit_LOCF_landmark( data_long = data_repeat_outcomes, x_L = c(60, 61), x_hor = c(65, 66), covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), k = 10, individual_id = "id", event_time = "event_time", event_status = "event_status", survival_submodel = "cause_specific" ) newdata <- rbind( data.frame( id = c(3001, 3001, 3001), response_time_sbp_stnd = c(57, 58, 59), smoking = c(0, 0, 0), diabetes = c(0, 0, 0), ethnicity = c("Indian", "Indian", "Indian"), sbp_stnd = c(0.45, 0.87, 0.85), tchdl_stnd = c(-0.7, 0.24, 0.3), response_time_tchdl_stnd = c(57, 58, 59) ) ) predict(object=data_model_landmark_LOCF,x_L=60,x_hor=62,newdata=newdata,cv_fold=1)
library(Landmarking) data(data_repeat_outcomes) data_model_landmark_LOCF <- fit_LOCF_landmark( data_long = data_repeat_outcomes, x_L = c(60, 61), x_hor = c(65, 66), covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), k = 10, individual_id = "id", event_time = "event_time", event_status = "event_status", survival_submodel = "cause_specific" ) newdata <- rbind( data.frame( id = c(3001, 3001, 3001), response_time_sbp_stnd = c(57, 58, 59), smoking = c(0, 0, 0), diabetes = c(0, 0, 0), ethnicity = c("Indian", "Indian", "Indian"), sbp_stnd = c(0.45, 0.87, 0.85), tchdl_stnd = c(-0.7, 0.24, 0.3), response_time_tchdl_stnd = c(57, 58, 59) ) ) predict(object=data_model_landmark_LOCF,x_L=60,x_hor=62,newdata=newdata,cv_fold=1)
To fit the LOCF model, all individuals must have at least one
non-NA
entry by landmark time x_L
for all covariates.
This function selects these individuals and removes the other rows.
return_ids_with_LOCF( data_long, individual_id, x_L, covariates, covariates_time )
return_ids_with_LOCF( data_long, individual_id, x_L, covariates, covariates_time )
data_long |
Data frame with repeated measurements data in long format |
individual_id |
Character string specifying the column name in |
x_L |
Numeric specifying the landmark time(s) |
covariates |
Vector of character strings specifying the column names in |
covariates_time |
Vector of character strings specifying the column names in |
Individuals have a LOCF if there is a non-NA
entry for each of the covariates in
covariates
up until (not including) time x_L
.
List of data frames which correspond to each landmark time x_L
.
Each data frame is an updated version of data_long
which contains only rows
of individuals with a LOCF at age x_L
, other rows are removed.
Isobel Barrott [email protected]
library(Landmarking) data(data_repeat_outcomes) data_repeat_outcomes <- return_ids_with_LOCF( data_long = data_repeat_outcomes, individual_id = "id", covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), x_L = c(60,61) )
library(Landmarking) data(data_repeat_outcomes) data_repeat_outcomes <- return_ids_with_LOCF( data_long = data_repeat_outcomes, individual_id = "id", covariates = c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"), covariates_time = c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"), x_L = c(60,61) )