Reputation: 41
I'm using the survfit function from the survival package, and get results I don't understand. I have simple data - an object with survival times, and another with an indicator variable (0 = alive, 1 = dead).
Survival_Time_Months[1:50]
# [1] 165 3 119 92 88 3 25 3 56 18 100 114 17 97 141 145 103 156 37 91 101 43 41 143 108 93 136 4 116
# [30] 85 166 0 92 26 9 8 55 136 10 99 1 20 6 95 85 79 119 109 41 23
Vital_Status_RECODE[1:50]
# [1] 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
# Levels: 0 1
I can then run this through survfit as:
my.surv.fit <- survfit(Surv(Survival_Time_Months,Vital_Status_RECODE) ~ 1, data=mydata)
Then run the plot command:
plot(my.surv.fit)
I get something that is not a Kaplan-Meier curve, but something that starts at zero and goes upward - it looks like 1.0 - KM. The KM data is in the fit object as $pstate, but I have to mess around extensively to extract it and generate the KM-plot I want.
In trying to resolve this, I've looked through every forum regarding the survfit package, and multiple tutorials, and every single one seems to indicate that sequence of commands should produce a KM curve.
Upvotes: 1
Views: 1416
Reputation: 9705
Status should be a numeric vector, not a factor. Try this and you will see the difference:
time <- c(165,3,119,92,88,3,25,3,56,18,100,114,17,97,141,145,103,156,37,91,101,43,41,143,108,93,136,4,116,85,166,0,92,26,9,8,55,136,10,99,1,20,6,95,85,79,119,109,41,23)
status <- c(0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0)
plot(survfit(Surv(time, status)~1))
Upvotes: 3