Learn R Programming

riskRegression (version 1.3.7)

CoxVariableName: Extract variable names from a model

Description

Extract the name of the variables belonging to the linear predictor or used to form the strata

Usage

CoxVariableName(object)

Arguments

object

The fitted Cox regression model object either obtained with coxph (survival package) or cph (rms package).

Examples

Run this code

d <- sampleData(1e2, outcome = "survival")
d$entry <- 0
d$id <- 1:NROW(d)

##
library(survival)
d$X1=factor(d$X1)
mCox <- coxph(Surv(time, event) ~ X1+X2, data = d, x = TRUE, y = TRUE)
CoxVariableName(mCox)
mCoxS <- coxph(Surv(time, event) ~ strata(X1)+X2, data = d, x = TRUE, y = TRUE)
CoxVariableName(mCoxS)
mCoxS2 <- coxph(Surv(time, event) ~ strata(X1)+strata(X2), data = d, x = TRUE, y = TRUE)
CoxVariableName(mCoxS2)
mCoxI <- coxph(Surv(time, event) ~ X1*X2, data = d, x = TRUE, y = TRUE)
CoxVariableName(mCoxI)

##
library(rms)
mCox <- cph(Surv(time, event) ~ X1+X2, data = d, x = TRUE, y = TRUE)
CoxVariableName(mCox) 
mCoxS <- cph(Surv(time, event) ~ strat(X1)+X2, data = d, x = TRUE, y = TRUE)
CoxVariableName(mCoxS) 
mCoxS2 <- cph(Surv(time, event) ~ strat(X1)+strat(X2), data = d, x = TRUE, y = TRUE)
CoxVariableName(mCoxS2) 
mCoxI <- cph(Surv(time, event) ~ X1*X2, data = d, x = TRUE, y = TRUE)
CoxVariableName(mCoxI)

##
library(mets)
mCox <- phreg(Surv(entry, time, event) ~ X1+X2, data = d)
CoxVariableName(mCox) 
mCoxS <- phreg(Surv(entry, time, event) ~ strata(X1)+cluster(id)+X2, data = d)
CoxVariableName(mCoxS) 
mCoxI <- phreg(Surv(entry, time, event) ~ X1*X2, data = d)
CoxVariableName(mCoxI)

Run the code above in your browser using DataLab