I am trying to reproduce this study: http://stm.sciencemag.org/content/7/299/299ra122

I have time-dependent features like patient lab values and vital signs measurements, and also features like age, gender, etc that don't change in time. The paper says "we fit a Cox proportional hazards model using the time until the onset of septic shock as the supervisory signal". And "time-to-event models were learned as a Cox proportional hazards model with lasso regularization (glmnet R package, version 1.9-8"

I am new to survival analysis. I have done a lot of research but have not found one that has used glmnet cox regression with time dependent data. The only example I found is this: https://github.com/cran/glmnet/blob/master/inst/doc/Coxnet.R The data (patient.data) columns are not explained and do not seem to be time dependent.

To feed my data to glmnet package, I know I should have a matrix x (one row for each patient and one column for each feature) and a matrix y (one column for each patient,one row for time of event for each patient and one row for status of event)

My question is, imagine I have 50 patients, and my features are age, gender, type of disease and blood pressure (measured every four hours for a month) and a lab value (measured every day for a month), what should my matrix x look like?

  • 1
    $\begingroup$ After reading the paper I think they did the following: they fitted N multiple models to predict the onset of septic shock from N specific time points Although, Cox assumes that every patient eventually experiences an event; however in this setting, not every patient develops septic shock. Would that mean that they only included the positive and interval-censored patients in their matrix to train the model and neglected the negatives? I am curious whether and how you have fixed this problem. $\endgroup$ Mar 2, 2018 at 14:07

1 Answer 1


Is there a specific reason why you are using penalized?

It strikes me that with multiple ids per row it makes sense to use cluster() in the survival package and denote the patient the observation belongs to.

  • $\begingroup$ Thanks for your response. The main reason why I am using penalized is that glmnet() was used in the original study that I am trying to reproduce. Also because I have 50+ covariates. $\endgroup$
    – nasim
    Apr 28, 2017 at 15:57
  • $\begingroup$ This paper with data prep for time-dependent covariates should explain what X needs to look like: cran.r-project.org/web/packages/survival/vignettes/timedep.pdf $\endgroup$
    – cutty14
    Apr 30, 2017 at 0:38
  • $\begingroup$ I already read that. It does not have an example that uses glmnet but I will try a similar approach and see if it works. Matrixs Y in glmnet has 2 rows and n(number of patients) columns, one row for event/censoring times and one for status(0 for censored and 1 for event). If I use the approach outlined in timedep.pdf, I have to have two rows for time in matrix Y (time1 and time2 or timestart and timestop), and I don't know if glmnet() will let me. I will try and update this post. Thanks for taking the time to help. $\endgroup$
    – nasim
    May 1, 2017 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.