Learn R Programming

riskRegression (version 1.4.3)

CoxDesign: Extract the design matrix used to train a Cox model

Description

Extract the design matrix used to train a Cox model. Should contain the time of event, the type of event, the variable for the linear predictor, the strata variables and the date of entry (in case of delayed entry).

Usage

CoxDesign(object, center)

# S3 method for coxph CoxDesign(object, center = FALSE)

# S3 method for phreg CoxDesign(object, center = FALSE)

Arguments

object

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

center

logical. Should the variable of the linear predictor be centered ?

Examples

Run this code
# NOT RUN {
set.seed(10)
d <- sampleData(2e1, outcome = "survival")
d$entry <- 0

##
library(survival)
mCox <- coxph(Surv(entry, time, event) ~ X1+X2, data = d, x = TRUE, y = TRUE)
CoxDesign(mCox)
mCox <- coxph(Surv(time, event) ~ X1*X2+strata(X3), data = d, x = TRUE, y = TRUE)
CoxDesign(mCox)
mCox <- coxph(Surv(time, event) ~ X1+X2+strata(X3)+strata(X4), data = d, x = TRUE, y = TRUE)
CoxDesign(mCox, center = TRUE)

##
library(rms)
mCox <- cph(Surv(time, event) ~ X1+X2, data = d, x = TRUE, y = TRUE)
CoxDesign(mCox)
mCox <- cph(Surv(time, event) ~ X1*X2+strat(X3), data = d, x = TRUE, y = TRUE)
CoxDesign(mCox, center = TRUE)
mCox <- cph(Surv(time, event) ~ X1*X2+strat(X3)+strat(X4), data = d, x = TRUE, y = TRUE)
CoxDesign(mCox)

##
library(mets) 
d$id <- 1:NROW(d)

mCox <- phreg(Surv(entry, time, event) ~ X1*X2, data = d)
CoxDesign(mCox)
mCox <- phreg(Surv(entry, time, event) ~ X1+X2+strata(X3)+cluster(id), data = d)
CoxDesign(mCox)
# mCox <- phreg(Surv(entry, time, event) ~ X1+X2+strata(X3)+strata(X4)+cluster(id), data = d)
# }

Run the code above in your browser using DataLab