View source: R/pa_predict_cif.R
| pa_predict_cif | R Documentation |
This function calculates cumulative incidence function (CIF) predictions for individual subjects across multiple types of competing risks models. It supports cause-specific Cox models, accelerated failure time (AFT) models (Weibull, Log-normal, Log-logistic), Fine-Gray models, and competing risks random survival forests.
pa_predict_cif(
model1 = NULL,
model2 = NULL,
fg_model = NULL,
cr_model = NULL,
tau = NULL,
newdata,
event.type = 1,
covs
)
model1 |
The fitted model for the target cause (either a 'coxph' or 'survreg' object). |
model2 |
The fitted model for competing causes (either a 'coxph' or 'survreg' object). |
fg_model |
Optional Fine-Gray model object ('crr' from 'cmprsk' package). |
cr_model |
Optional competing risks random forest model object. |
tau |
The maximum time horizon for prediction. |
newdata |
A data frame containing observed event times ('time'), event indicators ('status'). |
event.type |
The event type of interest for which CIF is to be predicted. |
covs |
A character vector specifying the names of the covariates used in the model. |
For cause-specific AFT models, CIFs are evaluated by adaptive quadrature on the target cause's probability scale. This handles Weibull densities that are unbounded at time zero, including fixed scales above 1. The time summary integrates one minus the CIF on the returned time grid.
A list with the following components:
Numeric vector of observed times from newdata$time.
Integer vector of event indicators from newdata$status.
A matrix where the first column is time, and subsequent columns are predicted CIFs for each subject.
Numeric vector of the integral of one minus the CIF from 0 to tau.
Numeric vector of subject-specific linear predictors.
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)
covariates <- c("age", "log_albumin", "log_bili", "log_protime", "edema")
dat <- pbc[, c("time", "status", covariates)]
dat <- dat[stats::complete.cases(dat), ]
# Cause-specific Cox models: event of interest (1) and competing event (2)
m1 <- survival::coxph(survival::Surv(time, status == 1) ~ age + log_albumin +
log_bili + log_protime + edema,
data = dat, x = TRUE, y = TRUE)
m2 <- survival::coxph(survival::Surv(time, status == 2) ~ age + log_albumin +
log_bili + log_protime + edema,
data = dat, x = TRUE, y = TRUE)
pred <- pa_predict_cif(model1 = m1, model2 = m2, newdata = dat,
covs = covariates, event.type = 1,
tau = max(dat$time))
str(pred$pred)
# Fine-Gray backend, available when cmprsk is installed
if (requireNamespace("cmprsk", quietly = TRUE)) {
fg <- cmprsk::crr(ftime = dat$time, fstatus = dat$status,
cov1 = as.matrix(dat[, covariates]),
failcode = 1, cencode = 0)
pred_fg <- pa_predict_cif(fg_model = fg, newdata = dat,
covs = covariates, event.type = 1,
tau = max(dat$time))
str(pred_fg$pred)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.