| Title: | Landmark Prediction of a Survival Outcome |
|---|---|
| Description: | Nonparametric methods for landmark prediction of long-term survival outcomes, incorporating covariate and short-term event information. The package supports the construction of flexible varying-coefficient models that use discrete covariates, as well as multiple continuous covariates. The goal is to improve prediction accuracy when censored short-term events are available as predictors, using robust nonparametric procedures that do not require correct model specification and avoid restrictive parametric assumptions found in alternative methods. More information on these methods can be found in Parast et al. 2012 <doi:10.1080/01621459.2012.721281>, Parast et al. 2011 <doi:10.1002/bimj.201000150>, and Parast and Cai 2013 <doi:10.1002/sim.5776>. A tutorial for this package is available here: <https://www.laylaparast.com/landpred>. |
| Authors: | Dylan Huynh [aut], Layla Parast [aut, cre] |
| Maintainer: | Layla Parast <[email protected]> |
| License: | GPL |
| Version: | 2.0 |
| Built: | 2026-05-14 09:34:51 UTC |
| Source: | https://github.com/laylaparast/landpred |
This function calculates the AUC given the data (truth) and corresponding estimated probabilities; uses a continuity correction.
AUC.landmark(t0, tau, data, weight=NULL)AUC.landmark(t0, tau, data, weight=NULL)
t0 |
The landmark time. |
tau |
The prediction window. |
data |
A data matrix where the first column is XL = min(TL, C) where TL is the time of the long term event, C is the censoring time; the second column is DL =1*(TL<C); the third column is the estimated probability P(TL<t0+tau | TL>t0). |
weight |
an optional weight to be incorporated in all estimation. |
AUC.est |
Estimated AUC |
Parast, Layla, Su-Chun Cheng, and Tianxi Cai. Incorporating short-term outcome information to predict long-term survival with discrete markers. Biometrical Journal 53.2 (2011): 294-307.
data(data_example_landpred) t0=2 tau = 8 out = Prob.Null(t0=t0,tau=tau,data=data_example_landpred) #get data with predictions data_pred = out$data #calculate training AUC AUC.landmark(t0=t0,tau=tau, data = data_pred[,c("XL","DL","prob_est")])data(data_example_landpred) t0=2 tau = 8 out = Prob.Null(t0=t0,tau=tau,data=data_example_landpred) #get data with predictions data_pred = out$data #calculate training AUC AUC.landmark(t0=t0,tau=tau, data = data_pred[,c("XL","DL","prob_est")])
This function calculates the Brier score given the data (truth) and corresponding estimated probabilities.
BS.landmark(t0, tau, data, weight=NULL)BS.landmark(t0, tau, data, weight=NULL)
t0 |
The landmark time. |
tau |
The prediction window. |
data |
A data matrix where the first column is XL = min(TL, C) where TL is the time of the long term event, C is the censoring time; the second column is DL =1*(TL<C); the third column is the estimated probability P(TL<t0+tau | TL>t0). |
weight |
an optional weight to be incorporated in all estimation. |
Brier.score |
Estimated Brier score |
Parast, Layla, Su-Chun Cheng, and Tianxi Cai. Incorporating short-term outcome information to predict long-term survival with discrete markers. Biometrical Journal 53.2 (2011): 294-307.
data(data_example_landpred) t0=2 tau = 8 out = Prob.Null(t0=t0,tau=tau,data=data_example_landpred) #get data with predictions data_pred = out$data #calculate training BS BS.landmark(t0=t0,tau=tau, data = data_pred[,c("XL","DL","prob_est")])data(data_example_landpred) t0=2 tau = 8 out = Prob.Null(t0=t0,tau=tau,data=data_example_landpred) #get data with predictions data_pred = out$data #calculate training BS BS.landmark(t0=t0,tau=tau, data = data_pred[,c("XL","DL","prob_est")])
Extracts coefficients. If t_s is provided, it fits the short-term GLM
and returns its coefficients.
## S3 method for class 'landpred_model_continuous' coef(object, t_s = NULL, ...)## S3 method for class 'landpred_model_continuous' coef(object, t_s = NULL, ...)
object |
A landpred_model_continuous object. |
t_s |
Optional short-term event time. |
... |
Additional arguments. |
A named vector of coefficients.
Helper function; should not be called directly by user.
cumsum2(mydat)cumsum2(mydat)
mydat |
mydat |
out |
matrix |
Layla Parast
Hypothetical data to be used in examples.
data(data_example_landpred)data(data_example_landpred)
A data frame with 4868 observations on the following 5 variables.
XLa numeric vector. XL = min(TL, C) where TL is the time of the long term event, C is the censoring time.
DLa 0/1 vector. DL =1*(TL<C) where TL is the time of the long term event, C is the censoring time.
XSa numeric vector. XS = min(TS, C) where TS is the time of the long term event, C is the censoring time.
DSa 0/1 vector. DS =1*(TS<C) where TS is the time of the long term event, C is the censoring time.
Za 0/1 vector of discrete covariate values.
data(data_example_landpred)data(data_example_landpred)
Creates a landpred model object for a specific landmark time and prediction window. Dispatches to continuous or discrete model creation based on the landpred object type.
get_model(landpred_obj, t0, tau, bw = NULL, transform = identity)get_model(landpred_obj, t0, tau, bw = NULL, transform = identity)
landpred_obj |
A landpred object. |
t0 |
The landmark time. |
tau |
The prediction window. |
bw |
The bandwidth. |
transform |
Transformation function. |
A landpred_model object (continuous or discrete).
Estimate Survival Function
Ghat.FUN(tt, data, type = "fl", weight.given)Ghat.FUN(tt, data, type = "fl", weight.given)
tt |
Time points. |
data |
Data frame. |
type |
Type of estimator. |
weight.given |
Optional weights. |
Helper function for AUC.landmark; should not be called directly by user.
helper.si(yy,FUN,Yi,Vi=NULL)helper.si(yy,FUN,Yi,Vi=NULL)
yy |
yy |
FUN |
FUN |
Yi |
Yi |
Vi |
Vi |
out |
matrix |
Layla Parast
Calculates the kernel matrix
Kern.FUN(zz, zi, bw)Kern.FUN(zz, zi, bw)
zz |
zz |
zi |
zi |
bw |
bandwidth |
the kernel matrix
Layla Parast
Parses the formula and data to create a landpred object used for landmark prediction. Call '?landpred.pacakge' for more information on the legacy API.
landpred(formula, data, discrete = FALSE, no.covariates = FALSE)landpred(formula, data, discrete = FALSE, no.covariates = FALSE)
formula |
A formula object with a Surv object on the LHS and covariates on the RHS. |
data |
The data frame. |
discrete |
Logical, whether to use the discrete method (legacy). |
no.covariates |
Logical, whether there are covariates or not. |
A landpred_object.
library(landpred) library(survival) # Load example data data(data_example_landpred) # Define landmark time and prediction window t0 <- 2 tau <- 8 # Create a landpred object using the formula interface # The formula specifies: Long-term survival ~ Short-term survival + Covariates # Note: The short-term event must be a Surv object obj <- landpred( Surv(XL, DL) ~ Surv(XS, DS) + Z, data = data_example_landpred, discrete = FALSE ) # 1. Optimize bandwidth (Optional but recommended) # This uses cross-validation to find the optimal bandwidth for the short-term event # We use log transformation for the time variable as it's often more appropriate bw <- optimize_bandwidth( landpred_obj = obj, t0 = t0, tau = tau, lower = 0.5, upper = 5, transform = log ) print(paste("Optimal bandwidth:", bw)) # 2. Fit the model # We pass the optimized bandwidth and the transformation used model <- get_model( landpred_obj = obj, t0 = t0, tau = tau, bw = bw, transform = log ) print(model) summary(model,t_s = 1) # 3. Predict on new data # For demonstration, we use the first 10 rows of the original data as "new data" new_data <- data_example_landpred[1:10, ] # The predict function expects a data frame with the same column names as used in the formula probs <- predict(model, newdata = new_data) print("Predicted probabilities:") print(probs)library(landpred) library(survival) # Load example data data(data_example_landpred) # Define landmark time and prediction window t0 <- 2 tau <- 8 # Create a landpred object using the formula interface # The formula specifies: Long-term survival ~ Short-term survival + Covariates # Note: The short-term event must be a Surv object obj <- landpred( Surv(XL, DL) ~ Surv(XS, DS) + Z, data = data_example_landpred, discrete = FALSE ) # 1. Optimize bandwidth (Optional but recommended) # This uses cross-validation to find the optimal bandwidth for the short-term event # We use log transformation for the time variable as it's often more appropriate bw <- optimize_bandwidth( landpred_obj = obj, t0 = t0, tau = tau, lower = 0.5, upper = 5, transform = log ) print(paste("Optimal bandwidth:", bw)) # 2. Fit the model # We pass the optimized bandwidth and the transformation used model <- get_model( landpred_obj = obj, t0 = t0, tau = tau, bw = bw, transform = log ) print(model) summary(model,t_s = 1) # 3. Predict on new data # For demonstration, we use the first 10 rows of the original data as "new data" new_data <- data_example_landpred[1:10, ] # The predict function expects a data frame with the same column names as used in the formula probs <- predict(model, newdata = new_data) print("Predicted probabilities:") print(probs)
Selects the optimal bandwidth by minimizing the Mean Squared Error (MSE) using cross-validation.
optimize_bandwidth( landpred_obj, t0, tau, lower = 0.05, upper = 5, transform = identity, reps = 50, train_prop = 0.66 )optimize_bandwidth( landpred_obj, t0, tau, lower = 0.05, upper = 5, transform = identity, reps = 50, train_prop = 0.66 )
landpred_obj |
A landpred object. |
t0 |
The landmark time. |
tau |
The prediction window. |
lower |
Lower bound for bandwidth search. |
upper |
Upper bound for bandwidth search. |
transform |
Transformation function for the short-term event (e.g., log). Default is identity. |
reps |
Number of cross-validation repetitions. Default is 50. |
train_prop |
Proportion of data used for training in each fold. Default is 0.66. |
The optimal bandwidth.
Predicts the probability of the event occurring given new data.
## S3 method for class 'landpred_model_continuous' predict(object, newdata = NULL, type = "response", ...)## S3 method for class 'landpred_model_continuous' predict(object, newdata = NULL, type = "response", ...)
object |
A landpred_model_continuous object. |
newdata |
New data frame containing covariates and short-term event info. |
type |
Type of prediction (default "response"). |
... |
Additional arguments |
A vector of predicted probabilities.
Predicts probabilities using the discrete landpred model.
## S3 method for class 'landpred_model_discrete' predict(object, newdata = NULL, ...)## S3 method for class 'landpred_model_discrete' predict(object, newdata = NULL, ...)
object |
A landpred_model_discrete object. |
newdata |
Optional new data. |
... |
Additional arguments. |
Predicted probabilities.
Prints the continuous landpred model results.
## S3 method for class 'landpred_model_continuous' print(x, ...)## S3 method for class 'landpred_model_continuous' print(x, ...)
x |
A landpred_model_continuous object. |
... |
Additional arguments. |
Prints the discrete landpred model results.
## S3 method for class 'landpred_model_discrete' print(x, ...)## S3 method for class 'landpred_model_discrete' print(x, ...)
x |
A landpred_model_discrete object. |
... |
Additional arguments. |
Prints a summary of the landpred object.
## S3 method for class 'landpred_object' print(x, ...)## S3 method for class 'landpred_object' print(x, ...)
x |
A landpred_object. |
... |
Additional arguments. |
Calculates the probability of the event occurring before t0 + tau,
given survival up to t0, using a single covariate.
Prob.Covariate(t0, tau, data, weight = NULL, short = TRUE, newdata = NULL)Prob.Covariate(t0, tau, data, weight = NULL, short = TRUE, newdata = NULL)
t0 |
The landmark time. |
tau |
The prediction window. |
data |
The data frame for training. |
weight |
Optional weights. |
short |
Logical, whether the covariate is short-term. |
newdata |
Dataframe of new data for prediction. |
A landpred_result object.
Calculates the probability of the event occurring before t0 + tau,
given survival up to t0, using information on a short-term event.
Prob.Covariate.ShortEvent( t0, tau, data, weight = NULL, bandwidth = NULL, newdata = NULL )Prob.Covariate.ShortEvent( t0, tau, data, weight = NULL, bandwidth = NULL, newdata = NULL )
t0 |
The landmark time. |
tau |
The prediction window. |
data |
The data frame. |
weight |
Optional weights. |
bandwidth |
Bandwidth for kernel smoothing. |
newdata |
Optional new data for prediction. |
A landpred_result object.
Calculates the probability of the event occurring before t0 + tau,
given survival up to t0, without using any covariate information.
Prob.Null(t0, tau, data, weight = NULL, newdata = NULL)Prob.Null(t0, tau, data, weight = NULL, newdata = NULL)
t0 |
The landmark time. |
tau |
The prediction window. |
data |
The data frame. |
weight |
Optional weights. |
newdata |
Optional new data for prediction. |
A landpred_result object.
Calculate Probability Component (No Kernel)
Prob2(t0, tau, data, covariate.value, weight = NULL)Prob2(t0, tau, data, covariate.value, weight = NULL)
t0 |
Landmark time. |
tau |
Prediction window. |
data |
Data frame. |
covariate.value |
Covariate value. |
weight |
Optional weights. |
Calculate Probability Component with Kernel Smoothing
Prob2.k.t(t, t0, tau, data.use, bandwidth, covariate.value, weight = NULL)Prob2.k.t(t, t0, tau, data.use, bandwidth, covariate.value, weight = NULL)
t |
Time points. |
t0 |
Landmark time. |
tau |
Prediction window. |
data.use |
Data frame. |
bandwidth |
Bandwidth. |
covariate.value |
Covariate value. |
weight |
Optional weights. |
Calculate Single Probability Component
prob2.single(K, W2i, Xi.long, tau, Di.short, Xi.short, Zi, t0, covariate.value)prob2.single(K, W2i, Xi.long, tau, Di.short, Xi.short, Zi, t0, covariate.value)
K |
Kernel weights. |
W2i |
IPCW weights. |
Xi.long |
Long term event times. |
tau |
Prediction window. |
Di.short |
Short term event indicators. |
Xi.short |
Short term event times. |
Zi |
Covariates. |
t0 |
Landmark time. |
covariate.value |
Covariate value. |
Prints a summary of the model, including coefficients and standard errors.
## S3 method for class 'landpred_model_continuous' summary(object, t_s = NULL, ...)## S3 method for class 'landpred_model_continuous' summary(object, t_s = NULL, ...)
object |
A landpred_model_continuous object. |
t_s |
Optional short-term event time. |
... |
Additional arguments. |
Prints a detailed summary of the landpred object.
## S3 method for class 'landpred_object' summary(object, ...)## S3 method for class 'landpred_object' summary(object, ...)
object |
A landpred_object. |
... |
Additional arguments. |
This function creates a matrix that repeats vc, dm times where each row is equal to the vc vector.
VTM(vc, dm)VTM(vc, dm)
vc |
the vector to repeat. |
dm |
number of rows. |
a matrix that repeats vc, dm times where each row is equal to the vc vector
Computes the inverse probability of censoring weights for a specific t0 and tau i.e. this computes I(t0 < XL < t0+tau)*DL/G(XL) + I(XL>t0+tau)/G(t0+tau) where XL = min(TL, C), TL is the time of the long term event, C is the censoring time, DL =1*(TL<C) and G() is the estimate survival probability for censoring estimated using the Kaplan Meier estimator
Wi.FUN(data, t0, tau, weight.given = NULL)Wi.FUN(data, t0, tau, weight.given = NULL)
data |
n by k matrix, where k>= 2. A data matrix where the first column is XL = min(TL, C) where TL is the time of the long term event, C is the censoring time, and the second column is DL =1*(TL<C) |
t0 |
the landmark time.. |
tau |
the residual survival time for which probabilities are calculated. |
weight.given |
an optional weight to be incorporated in estimation of this weight |
Inverse probability of censoring weight.
Layla Parast
data(data_example_landpred) t0=2 tau = 8 W2i <- Wi.FUN(data_example_landpred[,1],data = data_example_landpred[,c(1:2)],t0=t0,tau=tau)data(data_example_landpred) t0=2 tau = 8 W2i <- Wi.FUN(data_example_landpred[,1],data = data_example_landpred[,c(1:2)],t0=t0,tau=tau)