Search code examples
rsurvival-analysis

Kaplan meier survival curve is flipped in R?


I am fitting a K.M survival model on a data and the summary for model seems fine but whenever I plot it's reversed as it 0 at day 0 and 1 at day 2500 which should be the other way around?

kaplan <- survfit(Surv(time_diff, death)~1, data = new_data)
summary(kaplan)
time n.risk n.event P((s0)) P(1)
6 84 1 0.9881 0.0119
7 83 1 0.9762 0.0238
11 79 1 0.9638 0.0362
13 78 1 0.9515 0.0485
18 74 1 0.9386 0.0614
19 73 1 0.9258 0.0742
20 72 1 0.9129 0.0871
21 71 1 0.9000 0.1000
24 68 1 0.8868 0.1132
26 67 2 0.8603 0.1397
29 64 1 0.8469 0.1531
33 62 1 0.8332 0.1668
47 57 1 0.8186 0.1814
56 54 1 0.8035 0.1965
63 53 1 0.7883 0.2117
64 52 1 0.7731 0.2269
75 50 1 0.7577 0.2423
85 47 1 0.7416 0.2584
96 46 1 0.7254 0.2746
117 45 1 0.7093 0.2907
133 44 1 0.6932 0.3068
138 42 1 0.6767 0.3233
139 41 1 0.6602 0.3398
144 40 1 0.6437 0.3563
170 37 1 0.6263 0.3737
180 36 1 0.6089 0.3911
189 35 1 0.5915 0.4085
192 34 1 0.5741 0.4259
210 33 1 0.5567 0.4433
225 32 1 0.5393 0.4607
253 30 1 0.5213 0.4787
258 29 1 0.5033 0.4967
269 28 1 0.4854 0.5146
548 19 1 0.4598 0.5402
603 17 1 0.4328 0.5672
1078 11 1 0.3934 0.6066
1263 10 1 0.3541 0.6459
1388 8 1 0.3098 0.6902
1466 7 1 0.2656 0.7344
2060 5 1 0.2125 0.7875
2097 4 1 0.1593 0.8407
2281 3 1 0.1062 0.8938
2460 2 1 0.0531 0.9469
2828 1 1 0.0000 1.0000
plot(kaplan)

Resulting plot

Sorry if the question is simple as I am new R!

Thanks a lot!


Solution

  • Probably your status variable death is a factor. It shouldn't be. It should be numeric.

    Run a toy example below. Here, status is a factor, so plot will look like yours:

    time<-1:10
    status<-factor(rep(1:0, 5))       # factor!
    fit<-survfit(Surv(time, status)~1)
    plot(fit)
    

    Now, status is numeric and plot looks like you wish it to look like.

    time<-1:10
    status<-rep(1:0, 5)              # numeric!
    fit<-survfit(Surv(time, status)~1)
    plot(fit)