Penalized regression with cph() function of rms package in R

38 views Asked by At

I am little bit crazy trying to run a penalized cox ph regression model with functions of rms package. I’ve done it with glmnet package but I would like to analize the outputs with rms and Hmisc functions later. Is it possible to do so with cph() function? as well, how can be performed with cross-validation to found the optimum lambda which leads e.g. to a minimum mean cross-validated error.

Any help or do you have an example to follow? Thank you

I need to run cph() function to develop a cox ph model with penalization, but I do not know how to proceed. I expect to know if it's possible to do that and how, and much better if it's possible including an example.

1

There are 1 answers

1
rw2 On BEST ANSWER

I don't think you can do penalized regression directly in the rms package, but you could fit a penalized cox model separately, and then use the coefficients from that as the starting point in the cph function:

library(survival)
library(rms)
library(penalized)
data(lung)

penalized.model <- penalized(Surv(time, status) ~ age + sex, 
                             data = lung, 
                             model = "cox", 
                             lambda1 = 1, 
                             lambda2 = 1) 

coefficients <- coef(penalized.model)

rms.model <- cph(Surv(time, status) ~ age + sex, 
                 data = lung, 
                 x = TRUE, y = TRUE, 
                 surv = TRUE, 
                 init = coefficients)

EDIT: Adding splines and interactions:

lung$age_spline <- rcs(lung$age, 4)
lung$age_sex_interaction <- lung$age * lung$sex

penalized.model <- penalized(Surv(time, status) ~ age_spline + age_sex_interaction, 
                             data = lung, 
                             model = "cox", 
                             lambda1 = 1, 
                             lambda2 = 1)