1

Whenever I get to the "coxph" function in my code it gives me the error "Error in Surv(time, status) : object 'status' not found". But I don't get that same error elsewhere. What can I do?

This is my current code:

install.packages("survminer")
library(survminer)
library(survival)

data(lung)

require("survival")
km_fit <- survfit(Surv(time, status) ~ sex, data=lung)
ggsurvplot(km_fit, linetype = "strata", conf.int = TRUE, pval = TRUE, palette = "Dark2")


cox <- coxph(Surv(time, status), age+sex+ph.ecog+ph.karno+pat.karno+meal.cal+wt.loss, data=lung)
summary(cox) 
Logica
  • 977
  • 4
  • 16
Nonya
  • 115
  • 1
  • 5

1 Answers1

1

The error in your code is in the comma instead of using ~. If you replace it like in the following sample it works:

coxph(Surv(time, status) ~ age+sex+ph.ecog+ph.karno+pat.karno+meal.cal+wt.loss, data=lung)
Diegolog
  • 308
  • 1
  • 7