crr2: Competing risks regression

View source: R/crr2.R

crr2R Documentation

Competing risks regression

Description

Regression modeling of subdistribution functions in competing risks.

Usage

crr2(
  formula,
  data,
  which = NULL,
  cox = FALSE,
  variance = TRUE,
  cengroup = NULL,
  failcode = NULL,
  cencode = NULL,
  cov2 = NULL,
  tf = NULL,
  gtol = 1e-06,
  maxiter = 10,
  init = NULL
)

Arguments

formula

a survival object formula, Surv(time, status(censor) == failure) ~ response, where censor and failure are unique values of the status variable indicating the censoring and failure codes of interest; note all other unique values of status will be treated as competing risks

data

a data frame in which to interpret the variables named in formula

which

optional character string giving the desired outcome of interest (i.e., one of the unique values of the status variable); if given, no other crr models are returned

cox

logical; if TRUE, a coxph model is fit using the event of interest with all other events treated as censored;

alternatively, a formula to be passed to coxph, typically with the same RHS as formula, since this may be more desirable than setting cox = TRUE; note that this model may be fit to a different set of data depending on the missingness in variables of both models

variance

logical; if FALSE, suppresses computation of the variance estimate and residuals

cengroup, failcode, cencode, cov2

additional arguments passed to crr; these will be guessed from formula but may be overridden

tf

a function which takes a vector of times and returns a matrix to be multiplied by cov2; see [cmprsk]crr

gtol, maxiter, init

(optional) additional arguments passed to crr

Value

A list of crr objects with some additional components:

coxph

a coxph model if cox = TRUE

nuftime

a vector with the number of times each unique failure time, $uftime, was seen

n.missing

the number of observations removed due to missingness

attr(, "model.matrix")

the model.matrix, i.e., cov1, used in the call to crr

attr(, "model.frame")

the model.frame for cov1

See Also

crr; summary.crr2; print.crr2; finegray2; finegray; coxph

Examples

## 'formula' as one would pass to survival::coxph with additional
## indications for the censoring and failure codes

tp <- within(transplant, {
  event_ind <- as.integer(event) - 1L
  year <- NULL
})

## these are equivalent ways to call 'crr2'
crr2(Surv(futime, event_ind(0) == 1) ~ age + sex + abo, tp)
crr2(Surv(futime, event_ind(0) %in% 1) ~ age + sex + abo, tp)
crr2(Surv(futime, event(censored) == death) ~ age + sex + abo, tp)


## variables can be created or altered as usual
crr2(Surv(futime, event(censored) %in% death) ~ cut(age, 3), tp)
crr2(Surv(futime, event(censored) %in% death) ~ age + I(age ^ 2), tp)
crr2(Surv(futime, event(censored) %in% death) ~ relevel(abo, 'O'), tp)

form <- Surv(futime, event(censored) == death) ~ age + sex + abo
crr2(form, tp[tp$age > 55, ], cox = TRUE, variance = FALSE, which = 'death')


## use the summary method to compare models easily
crrs <- crr2(form, data = transplant,
             cox = Surv(futime, event == 'death') ~ age + sex + abo)
summary(crrs)

library('htmlTable')
summary(crrs, html = TRUE, n = TRUE)


## use the call from a crr2 object to run cmprsk::crr
cl <- crr2(Surv(futime, event(censored) == death) ~ age + sex + abo,
           na.omit(transplant))
cl[[1]]

cl[[1]]$call$cov2 <- NULL
eval(cl[[1]]$call)


## covariates that are functions of time are identified by tf()
crr2(Surv(futime, event(censored) == death) ~ factor(sex) + age + tf(age),
     data = transplant, tf = function(uft) cbind(uft, uft ^ 2))

## same as above but using the cov2 option
crr2(Surv(futime, event(censored) == death) ~ factor(sex) + age,
     cov2 = na.omit(cbind(transplant$age, transplant$age)),
     data = transplant, tf = function(uft) cbind(uft, uft ^ 2))


## example from cmprsk::crr

# simulated data to test
set.seed(10)
ftime   <- rexp(200)
fstatus <- sample(0:2, 200, replace = TRUE)
cov <- matrix(runif(600), 200, dimnames = list(NULL, c('x1', 'x2', 'x3')))
dat <- data.frame(ftime = ftime, fstatus = fstatus, cov)

## cmprsk::crr
(z1 <- crr(ftime, fstatus, cov, failcode = 1, cencode = 0))

## cmprsk2::crr2
(z2 <- crr2(Surv(ftime, fstatus(0) == 1) ~ ., dat))

summary(z1)
summary(z2)
summary(z2[[1]])

z1$call <- z2[[1]]$call <- NULL
all.equal(z1[names(z1)], z2[[1]][names(z1)])
# [1] TRUE


raredd/cmprsk2 documentation built on March 29, 2024, 5:34 a.m.