Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

stratifySurv

Add strata to a Surv object


Description

Helper function to add strata as an attribute to a Surv object. The output of this function can be used as the response in glmnet() for fitting stratified Cox models.

Usage

stratifySurv(y, strata = rep(1, length(y)))

Arguments

y

A Surv object.

strata

A vector of length equal to the number of observations in y, indicating strata membership. Default is all belong to same strata.

Details

When fitting a stratified Cox model with glmnet(), strata should be added to a Surv response with this helper function. Note that it is not sufficient to add strata as an attribute to the Surv response manually: if the result does not have class stratifySurv, subsetting of the response will not work properly.

Value

An object of class stratifySurv (in addition to all the classes y belonged to).

Examples

y <- survival::Surv(1:10, rep(0:1, length.out = 10))
strata <- rep(1:3, length.out = 10)
y2 <- stratifySurv(y, strata)  # returns stratifySurv object

glmnet

Lasso and Elastic-Net Regularized Generalized Linear Models

v4.1-1
GPL-2
Authors
Jerome Friedman [aut], Trevor Hastie [aut, cre], Rob Tibshirani [aut], Balasubramanian Narasimhan [aut], Kenneth Tay [aut], Noah Simon [aut], Junyang Qian [ctb]
Initial release
2021-02-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.