pa_predict_cif: Predict Subject-Specific Cumulative Incidence Function (CIF)

View source: R/pa_predict_cif.R

pa_predict_cifR Documentation

Predict Subject-Specific Cumulative Incidence Function (CIF)

Description

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.

Usage

pa_predict_cif(
  model1 = NULL,
  model2 = NULL,
  fg_model = NULL,
  cr_model = NULL,
  tau = NULL,
  newdata,
  event.type = 1,
  covs
)

Arguments

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.

Details

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.

Value

A list with the following components:

times

Numeric vector of observed times from newdata$time.

status

Integer vector of event indicators from newdata$status.

cif_pred

A matrix where the first column is time, and subsequent columns are predicted CIFs for each subject.

pred

Numeric vector of the integral of one minus the CIF from 0 to tau.

linear.pred

Numeric vector of subject-specific linear predictors.

Examples

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)
}


PAmeasures documentation built on Oct. 29, 2026, 1:08 a.m.