Learn R Programming

riskRegression (version 1.3.7)

CoxStrata: Define the strata for a new dataset

Description

Define the strata in a dataset to match those of a stratified Cox model

Usage

CoxStrata(object, data, sterms, stratavars, levels, stratalevels)

# S3 method for coxph CoxStrata(object, data = NULL, sterms, stratavars, levels, stratalevels)

# S3 method for coxph CoxStrata(object, data = NULL, sterms, stratavars, levels, stratalevels)

# S3 method for phreg CoxStrata(object, data = NULL, sterms, stratavars, levels, stratalevels)

Arguments

object

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

data

a data.frame or a data.table

sterms

terms in the formula corresponding to the strata variables

stratavars

the name of the variables used to define the strata

levels

the strata levels that have been used to fit the Cox model

stratalevels

a named list containing for each variable used to form the strata all its possible levels

Details

if no strata variables returns a vector of "1" (factor).

Examples

Run this code

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

##
library(survival)
mCoxS <- coxph(Surv(time, event) ~ strata(X1)+strata(X2), data = d, x = TRUE, y = TRUE)
resInfo <- CoxVariableName(mCoxS)
Ostrata <- CoxStrata(mCoxS, stratavars = resInfo$stratavars)
CoxStrata(mCoxS, data = d, sterms = resInfo$sterms, stratavars = resInfo$stratavars, 
          levels = levels(Ostrata), stratalevels = resInfo$stratalevels)

##
library(rms)
mCoxS <- cph(Surv(time, event) ~ strat(X1)+strat(X2), data = d, y = TRUE)
resInfo <- CoxVariableName(mCoxS)
Ostrata <- CoxStrata(mCoxS, stratavars = resInfo$stratavars)
CoxStrata(mCoxS, data = d, sterms = resInfo$sterms, stratavars = resInfo$stratavars, 
          levels = levels(Ostrata), stratalevels = resInfo$stratalevels)
          
##
library(mets)
mCoxS <- phreg(Surv(entry, time, event) ~ strata(X1)+X2+cluster(id), data = d)
resInfo <- CoxVariableName(mCoxS)
Ostrata <- CoxStrata(mCoxS, stratavars = resInfo$stratavars)
CoxStrata(mCoxS, data = d, sterms = resInfo$sterms, stratavars = resInfo$stratavars, 
          levels = levels(Ostrata), stratalevels = resInfo$stratalevels)

Run the code above in your browser using DataLab