laia_gt
laia_gt

Reputation: 1

Test Cox Proportional Assumption (cox.zph) for multiple columns using apply?

I have a dataset with many columns. I want to do a Cox regression for each one of the columns, so I used "apply". miRNA names are the predictor variables, the columns I want to do Cox regression in separated models. This is the code:

mirna_names <-colnames(DB)[33:54]
cox_cont = sapply(mirna_names, function(x){
  formula = as.formula(paste('Surv(years, AD)~', x))
  coxFit = coxph(formula, data = DB)
  summary(coxFit)$coefficients[,c(2,3,5)] %>% round(3)
}) 

Now, I would like to test Cox Proportional Assumption using "cox.zph". I want to do it for all the miRNAs again, so I used "apply". However, this doesn't work. Any help?

cox_assump = sapply(mirna_names, function(x){
  formula = as.formula(paste('coxph(Surv(years, AD)~', x))
  coxFit_assump = cox.zph(formula, data = DB)
  print(coxFit_assump)
})

Upvotes: 0

Views: 287

Answers (1)

SMzgr356
SMzgr356

Reputation: 93

A MWE would have helped, but the code below works. I've made as few changes to your original code as possible.

library(survival)
data(capacitor)

mirna_names <- c("voltage", "temperature")
cox_cont = lapply(mirna_names, function(x){
  formula = as.formula(paste('Surv(time, status)~', x))
  coxFit = coxph(formula, data = capacitor)
}) 

cox_assump = sapply(cox_cont, function(x){
  coxFit_assump = cox.zph(x)
  print(coxFit_assump)
})

The issue had to do with the input for cox.zph. It wants a coxph object, which you recognized, evident in how you were reestimating the models again. However, your reestimated coxph had no data argument. (The data argument present in your cox.zph line won't get passed to coxph.) I sidestepped the issue entirely by looping over the coxph objects from the first lapply.

Upvotes: 0

Related Questions