| crrstep | R Documentation |
Performs forward and backward stepwise variable selection for the Fine-Gray subdistribution hazard model in competing risks analysis. The procedure uses AIC, BIC, or BICcr as selection criteria. BICcr uses a penalty of k = \log(d), where d is the number of events of interest.
crrstep(formula, scope.min = ~1, etype, ..., subset, data,
direction = c("backward", "forward"),
criterion = c("AIC", "BICcr", "BIC"),
crr.object = FALSE, trace = TRUE, steps = 100)
## S3 method for class 'crrstep'
print(x, digits = max(3L, getOption("digits") - 3L), ...)
## S3 method for class 'crrstep'
summary(object, conf.level = 0.95, ...)
## S3 method for class 'summary.crrstep'
print(x, digits = max(3L, getOption("digits") - 3L),
signif.stars = getOption("show.signif.stars"), ...)
## S3 method for class 'crrstep'
coef(object, ...)
## S3 method for class 'crrstep'
vcov(object, ...)
## S3 method for class 'crrstep'
confint(object, parm, level = 0.95, ...)
## S3 method for class 'crrstep'
logLik(object, ...)
## S3 method for class 'crrstep'
AIC(object, ..., k = 2)
## S3 method for class 'crrstep'
BIC(object, ...)
formula |
A formula object where the left-hand side (LHS) is the failure time variable and the right-hand side (RHS) specifies the linear predictors (e.g., |
scope.min |
A one-sided formula specifying the minimum model (lower scope) for backward selection or the starting model for forward selection. Default is |
etype |
An integer variable denoting the event type for each observation. By default, 1 indicates the event of interest, 2 indicates competing events, and 0 indicates censoring. These can be modified using |
... |
Additional arguments passed to
For |
subset |
An optional vector specifying a subset of observations to use in the analysis. |
data |
A data frame containing all variables referenced in the formula and |
direction |
Character string specifying the direction of stepwise search. Either |
criterion |
Character string specifying the model selection criterion:
where |
crr.object |
Logical. If |
trace |
Logical. If |
steps |
Maximum number of steps allowed in the stepwise selection. Default is 100. |
x |
An object of class |
object |
An object of class |
digits |
Integer specifying the number of significant digits to display. |
conf.level |
Numeric value specifying the confidence level for confidence intervals. Default is 0.95. |
signif.stars |
Logical. If |
parm |
A specification of which parameters to compute confidence intervals for. Can be a vector of numbers (indices) or names. If missing, all parameters are included. |
level |
The confidence level for |
k |
Numeric penalty parameter for |
This function performs stepwise model selection for the Fine-Gray competing risks regression model implemented in crr. The implementation is based on the approach of stepAIC from the MASS package, adapted for the competing risks setting.
The function properly handles:
Factor variables (automatically expanded to dummy variables)
Interaction terms (e.g., x1:x2, x1*x2)
Polynomial terms (e.g., I(x^2))
Complex terms (e.g., I(x^2):factor)
The BICcr criterion, proposed by Volinsky and Raftery (2000) and adapted for competing risks by Kuk and Varadhan (2013), uses the number of events of interest rather than the total sample size in the penalty term. This is appropriate because the effective sample size in survival analysis is determined by the number of events, not the total number of observations.
Missing values are handled by complete case analysis. Observations with missing values in any predictor variable are removed before model fitting, and a message is displayed if trace = TRUE.
If crr.object = TRUE, returns the crr object from the final selected model.
Otherwise, returns an object of class "crrstep" with the following components:
call |
The matched function call. |
formula |
The formula for the final selected model. |
direction |
The direction of stepwise selection used. |
criterion |
The selection criterion used. |
criterion_value |
The value of the selection criterion for the final model. |
coefficients |
Named numeric vector of estimated coefficients. |
std.error |
Standard errors of the coefficients. |
zvalue |
Wald z-statistics ( |
pvalue |
Two-sided p-values based on the normal distribution. |
conf.int |
Matrix of confidence intervals for the coefficients. |
conf.level |
The confidence level used for |
loglik |
Log partial likelihood of the final model. |
loglik_null |
Log partial likelihood of the null model. |
n |
Number of observations used. |
nevent |
Number of events of interest. |
converged |
Logical indicating whether the |
is_null_model |
Logical indicating whether the final model is the null model. |
crr_fit |
The |
The summary method returns an object of class "summary.crrstep" containing:
call |
The matched function call. |
formula |
The formula for the final selected model. |
direction |
The direction of stepwise selection. |
criterion |
The selection criterion used. |
criterion_value |
The criterion value for the final model. |
coefficients |
Formatted coefficient table with estimates, hazard ratios, standard errors, z-values, and p-values. |
conf.int |
Confidence intervals for hazard ratios. |
conf.level |
The confidence level used. |
loglik |
Log partial likelihood of the final model. |
loglik_null |
Log partial likelihood of the null model. |
lr_test |
List containing the likelihood ratio test statistic, degrees of freedom, and p-value. |
n |
Number of observations. |
nevent |
Number of events of interest. |
converged |
Logical indicating convergence. |
is_null_model |
Logical indicating if the null model was selected. |
Ravi Varadhan and Deborah Kuk
Fine, J. P. and Gray, R. J. (1999). A proportional hazards model for the subdistribution of a competing risk. Journal of the American Statistical Association, 94(446), 496-509.
Volinsky, C. T. and Raftery, A. E. (2000). Bayesian information criterion for censored survival models. Biometrics, 56(1), 256-262.
Kuk, D. and Varadhan, R. (2013). Model selection in competing risks regression. Statistics in Medicine, 32(18), 3077-3088.
crr for the underlying Fine-Gray model,
stepAIC for stepwise selection in other model classes,
AIC, BIC for information criteria
# Load required package
library(cmprsk)
# Simulate example data
set.seed(123)
n <- 500
ftime <- rexp(n)
fstatus <- sample(0:2, n, replace = TRUE)
cov1 <- matrix(runif(5 * n), nrow = n)
x6 <- as.factor(sample(3, size = n, replace = TRUE))
x7 <- as.factor(sample(5, size = n, replace = TRUE))
cov1 <- cbind(cov1, x6, x7)
dimnames(cov1)[[2]] <- c('x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7')
mydata <- as.data.frame(cov1)
mydata$ftime <- ftime
mydata$fstatus <- fstatus
# Define formula with factors
formula1 <- ftime ~ x1 + x2 + x3 + x4 + x5 + as.factor(x6) + as.factor(x7)
# Backward selection with BIC
fit1 <- crrstep(formula1, etype = fstatus, data = mydata,
direction = "backward", criterion = "BIC")
print(fit1)
# Forward selection with AIC (event of interest = 2)
fit2 <- crrstep(formula1, etype = fstatus, data = mydata,
direction = "forward", criterion = "AIC",
failcode = 2, trace = FALSE)
print(fit2)
summary(fit2)
# Extract model components
coef(fit2)
confint(fit2)
confint(fit2, level = 0.90)
AIC(fit2)
BIC(fit2)
logLik(fit2)
vcov(fit2)
# Model with interactions
formula2 <- ftime ~ x1 + x2 + x3 + x4 + x4:as.factor(x6) + x5:as.factor(x7)
fit3 <- crrstep(formula2, etype = fstatus, data = mydata,
direction = "backward", criterion = "AIC",
trace = FALSE)
print(fit3)
summary(fit3)
# Return crr object for further analysis
fit_crr <- crrstep(formula1, etype = fstatus, data = mydata,
direction = "backward", criterion = "BICcr",
crr.object = TRUE, trace = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.