View source: R/pa_predict_survreg.R
| pa_predict_survreg | R Documentation |
This function computes Calculates a set of measures, $R^2$ and $L^2$, $Pseudo-R^2$ for evaluating the predictive accuracy of parametric survival regression models. R-squared quantifies the proportion of variability in the response that is explained by a corrected prediction function derived from the original model. L-squared measures the proportion of the prediction error from the original model that is explained by the corrected prediction function, effectively capturing the improvement in prediction accuracy. Together, these metrics provide a comprehensive assessment of the predictive performance of a survival regression model.
pa_predict_survreg(model, covs, tau = 1e+11, new_data = NULL, predict = TRUE)
model |
An object of class survreg representing a fitted parametric survival regression model. The survreg call must include x = TRUE and y = TRUE to ensure the design matrix and response vector are stored in the model object. |
covs |
A vector of covariate names to be used for prediction when new_data is provided. |
tau |
(Optional) A restriction time for computing restricted survival time. If provided, the function evaluates predictions up to this time point. Default is 10e10. |
new_data |
(Optional) A new dataset for evaluating the model. If NULL, the function uses the training data stored in model. |
predict |
(Optional) A logical value indicating whether to return individual predictions. Default is TRUE. |
With 'predict = FALSE', R-squared metrics return missing values with a warning if censoring weights cannot be normalized, for example when the training censoring survival is zero at an observed evaluation event. Individual predictions remain available with 'predict = TRUE'.
A **named list** of model-specific prediction objects. Each element of the returned list corresponds to one fitted model and contains:
model – the fitted survival model object.
times – numeric vector of observed follow-up times for the evaluation dataset.
status – event indicators (1 = event, 0 = censored).
surv_prob – an n \times K matrix of predicted
subject-specific survival probabilities on a common time grid.
pred – predicted mean survival time
(restricted or unrestricted, depending on the function).
covs – character vector of covariate names used for prediction.
new_data – dataset on which the predictions were computed.
data(pbc, package = "survival")
pbc <- pbc[!is.na(pbc$trt), ]
pbc$log_albumin <- log(pbc$albumin)
pbc$log_bili <- log(pbc$bili)
pbc$log_protime <- log(pbc$protime)
pbc$status <- ifelse(pbc$status == 2, 1, 0)
covs <- c("age", "log_albumin", "log_bili", "log_protime", "edema")
df <- pbc[, c("time", "status", covs)]
df <- df[stats::complete.cases(df), ]
set.seed(2025)
idx <- sample(seq_len(nrow(df)), round(2 / 3 * nrow(df)))
train_data <- df[idx, ]
test_data <- df[-idx, ]
m.wei <- survival::survreg(survival::Surv(time, status) ~ .,
data = train_data, dist = "weibull",
x = TRUE, y = TRUE)
wei_pred <- pa_predict_survreg(model = m.wei, covs = covs,
new_data = test_data)
str(wei_pred$pred)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.