cox regression with R atomic vectors error

570 Views Asked by At

I have a dataset imported into R. I sucessfully ran survfit on the data set. I have one column with the periods survived by the patient and one column with (0/1) outcome whether the patient survived. I am know trying to do coxph() on the data and am using the following.

coxph <- coxph(Surv(mydata$V11, mydata$event), method ="breslow")

However, I keep getting the following error. I have tried using as.numeric on the variables but this still does not fix the problem. I have also tried removing mydata$ from each variable in the line of code above. Thank you.

Error: $ operator is invalid for atomic vectors
1

There are 1 best solutions below

0
On
  1. To prevent this error, you have to explicitly include "formula =" in coxph(), as shown below.

  2. Also, if you're trying to model the null model, you need to include " ~ 1" after Surv().

coxph <- coxph(formula = Surv(mydata$V11, mydata$event) ~ 1, 
               method ="breslow")