0

I don't know how, but the survival curve that should be descending is coming out upwards. Actually I'm getting the cumulative incidence curve. Any ideas on how to find and fix the problem? Thank you!

the "upwards" survival curve

A piece of the df:

id<-c(11001, 11731, 12220, 16530, 99290, 100500)
time<-c(51,60,24,60,60,55)
event<-c(1,0,1,0,0,1)
df<-data.frame(id,time,event)

The code I tried:

df$id<-factor(df$id)
df$event<-factor(df$event)
# time is interger

a<-Surv(df$time, df$event)
km<-survfit(a~1,df)
plot(km)

I have used this code countless times before, I really don't know what is happening.

lemosl
  • 5
  • 4

1 Answers1

0

The survival packege instruction states that for the Surv funcion: "When the survival type is "mstate" then the status variable will be treated as a factor. The first level of the factor is taken to represent censoring and remaining ones a transition to the given state. (If the status variable is a factor then mstate is assumed.)"

My "event" variable was numeric with 0 for cencosing and 1 for deaths. I don't know why, but when I skiped transforming the variable to factor, as suggested, the code worked as expected (I believe that the function transforms the variable internally).

lemosl
  • 5
  • 4