Understanding the plot from a parametric survival analysis in R

27 views Asked by At

I'm new to plotting in Rstudio.

I want to fit a parametric survival distribution/model to some hypothetical data for the time-to-progression (TTP) for a standard of care.

Using the 'flexsurv' package, I fit several commonly used parametric survival distributions to data that includes a column for the time (in years) and a status indicator whether the time corresponds to an event, i.e. disease progression (status = 1), or to the last time of follow up, i.e. censoring (status = 0).

head(df_TTP)
        time status
1 6.13998781      1
2 2.68245570      1
3 5.20061733      1
4 1.93995197      1
5 0.02420781      0
6 9.66624332      1

I use the following code to fit parametric survival distributions:

l_TTP_SoC_exp      <- flexsurvreg(formula = Surv(time, status) ~ 1, data = df_TTP, dist = "exp")
l_TTP_SoC_gamma    <- flexsurvreg(formula = Surv(time, status) ~ 1, data = df_TTP, dist = "gamma")
l_TTP_SoC_gompertz <- flexsurvreg(formula = Surv(time, status) ~ 1, data = df_TTP, dist = "gompertz")
l_TTP_SoC_llogis   <- flexsurvreg(formula = Surv(time, status) ~ 1, data = df_TTP, dist = "llogis")
l_TTP_SoC_lnorm    <- flexsurvreg(formula = Surv(time, status) ~ 1, data = df_TTP, dist = "lnorm")
l_TTP_SoC_weibull  <- flexsurvreg(formula = Surv(time, status) ~ 1, data = df_TTP, dist = "weibull")

Then I want to inspect fit based on visual fit:

colors <- rainbow(6)
plot(l_TTP_SoC_exp,       col = colors[1], ci = FALSE, ylab = "Event-free proportion", xlab = "Time in years", las = 1)
lines(l_TTP_SoC_gamma,    col = colors[2], ci = FALSE)
lines(l_TTP_SoC_gompertz, col = colors[3], ci = FALSE)
lines(l_TTP_SoC_llogis,   col = colors[4], ci = FALSE)
lines(l_TTP_SoC_lnorm,    col = colors[5], ci = FALSE)
lines(l_TTP_SoC_weibull,  col = colors[6], ci = FALSE)
legend("right",
       legend = c("exp", "gamma", "gompertz", "llogis", "lnorm", "weibull"),
       col    = colors,
       lty    = 1,
       bty    = "n")

I get the following graph when I do this:

enter image description here

I can understand that the colored lines match the distributions on the right. But what are the black dotted lines? What are they, and why are there so many of them? Also, is there a way to plot a line to represent the survival original data among the colored lines to better see which colored line matches up with the original survival data?

I include the example data I use below:

            time status
1    6.139987810      1
2    2.682455703      1
3    5.200617334      1
4    1.939951970      1
5    0.024207815      0
6    9.666243316      1
7    4.394700402      1
8    1.855542818      1
9    4.243317837      1
10   4.869644446      1
11   1.155341021      1
12   4.891988824      1
13   3.431407080      1
14   4.106660932      1
15   8.293441583      1
16   1.786907695      1
17   6.512490436      1
18   9.790415889      1
19   5.807602615      1
20   1.186825739      1
21   1.881704034      1
22   3.331969749      1
23   3.670999791      1
24   0.117667753      0
25   0.752084289      0
26   3.228468223      1
27   4.291003529      1
28   3.968534505      1
29   6.126456936      1
30   1.824315009      0
31   1.067576833      1
32   0.207942678      0
33   3.345709542      1
34   2.630963333      1
35   9.583448954      0
36   4.726709972      1
37   2.891900978      1
38   6.804436004      1
39   5.885603560      1
40   2.256993024      0
41   7.673061950      1
42   5.161129560      1
43   5.166943102      1
44   5.492783542      1
45   7.543131314      1
46   7.728777122      1
47   6.310096008      0
48   4.806289563      1
49   6.329450639      1
50   1.179123729      0
51   9.656833097      1
52   4.968277719      1
53   2.605911365      1
54   7.978906534      1
55   4.181906829      1
56   6.907489546      1
57   7.892817552      1
58   2.524973740      0
59   1.831432953      1
60   5.451004683      1
61   3.512235699      1
62   8.441303260      1
63   5.380989861      1
64   6.254610034      1
65   1.212849987      0
66   0.793727186      0
67   2.524263850      1
68   2.507031055      1
69   2.639087620      1
70   4.318995059      0
71   2.919318585      1
72   3.743526925      1
73   1.152062483      0
74  14.939483927      1
75   4.743329033      1
76   6.766536900      1
77   5.411471601      1
78   0.910766582      0
79   5.621576851      1
80   8.152265017      1
81   6.535860404      1
82   0.435747574      0
83   5.139246701      1
84   2.683237441      1
85   8.294505650      1
86   2.935649641      0
87   0.677132739      1
88   1.849762603      1
89   1.909292774      1
90   7.260559336      1
91   7.845714091      1
92   2.950981222      0
93   5.685308829      1
94   3.566271737      1
95   5.867931880      1
96   7.113857527      1
97   2.725272282      1
98   1.838957663      0
99   4.800776307      1
100  4.503277677      1
101  3.931034439      1
102  5.768823178      1
103  4.654522474      1
104  1.187223843      1
105  0.599267793      0
106  1.874365670      1
107  1.644908363      1
108  3.874953071      1
109  5.188448113      1
110  3.501001799      0
111  1.422450954      1
112  5.982149127      0
113  9.205680321      1
114  0.874650503      0
115  3.148365707      1
116  7.680052104      1
117  4.257221958      1
118  1.192320519      1
119  1.470623365      0
120  2.804878402      0
121  3.623448170      1
122  5.872380191      1
123  5.970895259      1
124  6.770105723      1
125  4.720251077      0
126  0.693668386      1
127  7.520110995      1
128  3.871928081      0
129  7.685419082      1
130  2.730749887      0
131  3.807477008      1
132  1.864886242      1
133  3.461118570      1
134  1.576016548      0
135  4.440189075      1
136  3.546371029      1
137  2.409905038      0
138  2.696909409      1
139  0.785257496      1
140  4.987360910      1
141  5.938235225      1
142  5.197076696      1
143  8.679309490      0
144  7.157690914      1
145  2.275095893      1
146  6.656221384      1
147  6.579052067      1
148  8.813685668      1
149  5.421954233      0
150  3.071099114      1
151  2.237626206      1
152  4.595397012      1
153  4.572749676      0
154  6.509082644      1
155  8.152915561      1
156  5.337048806      1
157  4.111151151      1
158  6.799459898      1
159  4.950618640      1
160  6.788218941      1
161  4.563868708      1
162  5.605490272      1
163  3.609968685      1
164  5.449143774      1
165  0.266878015      0
166  4.358360411      1
167  3.015752648      1
168  6.756558950      1
169  5.173867862      1
170  6.332020640      1
171  3.738698509      1
172  7.157932674      1
173  2.105821388      1
174  2.973402799      1
175  3.491703379      1
176  3.815422192      1
177  5.467513685      1
178  4.383428738      1
179  2.012537821      1
180  4.048068396      1
181  2.298380810      1
182  3.361948075      0
183  3.230055974      1
184  6.338038927      1
185  3.967244050      1
186  4.703338416      1
187  6.337904532      1
188  4.158431775      1
189  0.467085405      0
190  1.767546548      1
191  6.256523180      1
192  5.859013909      1
193  0.661446870      1
194  3.685012770      0
195  0.123654632      0
196  4.802439128      1
197  5.215883749      1
198  3.550301335      1
199  7.544422354      1
200  0.973865424      0
201  6.582649250      1
202  1.077323275      1
203  3.922205759      1
204  3.590529969      0
205  4.316233642      0
206  1.964302884      1
207  5.528386680      1
208  6.134323135      1
209  0.160850760      0
210  7.295046192      1
211  4.698309692      1
212  6.448159332      1
213  6.806009407      1
214  3.452172977      1
215  9.595233070      1
216  2.962352465      0
217  5.620883007      1
218  5.200851465      1
219  2.442962682      1
220  0.583044966      0
221  6.183468898      1
222  1.095478361      1
223  3.096224404      1
224  3.374020417      1
225  9.431196562      1
226  5.299193248      1
227  4.726379077      1
228  4.186386486      1
229  0.725098539      0
230  1.632346408      1
231  3.813283923      1
232  5.063728268      1
233  4.303872156      1
234  9.267289968      1
235  6.375692099      1
236  5.285257667      1
237  7.002038506      1
238  1.476317382      0
239  7.537317543      1
240  0.773277083      0
241  4.273129564      1
242  3.530340351      1
243  7.300750804      1
244  3.718900574      1
245  5.936866355      1
246  3.121939279      1
247  5.272388153      1
248  0.970292931      1
249  0.503570026      0
250  3.107563505      1
251  6.408942533      1
252  6.749630841      1
253  2.833333594      0
254  6.315560685      1
255  4.093816601      0
256  1.749620491      0
257  0.147443207      0
258  5.233251639      1
259  1.349483594      0
260  2.068471853      1
261  1.528133965      1
262  1.949117019      1
263  3.453404373      1
264  1.243505388      1
265  4.470883277      1
266  4.081677976      1
267  5.741269973      1
268  5.655902742      1
269 10.876670614      1
270  4.560481325      1
271  2.043629042      1
272 12.380597999      1
273  4.275103835      0
274  7.392543683      1
275  1.783457613      0
276  3.050562270      1
277  0.263555069      0
278  4.802846379      1
279  0.853799653      0
280  3.617490284      1
281  2.890979424      1
282  7.752854974      1
283  5.289347190      1
284  5.793151335      0
285  9.281854161      1
286  5.294338092      1
287  9.094930939      1
288  6.708473611      1
289  4.022503442      0
290  3.478751959      1
291  6.053820467      1
292  8.332808901      1
293  8.923607255      1
294  1.962605087      1
295  2.920882413      1
296  0.009120685      0
297  0.738333449      1
298  3.467213801      0
299  8.363279454      1
300  2.606588656      1
301  2.709065572      1
302 11.877796290      1
303  2.748127510      1
304  3.089540574      1
305  3.737678730      1
306  4.705870873      1
307  3.122080753      0
308 12.052067876      1
309  4.897963747      1
310  4.630074129      1
311  1.686443269      0
312  4.815049867      1
313  3.197021981      1
314  9.357999946      1
315  5.554961390      0
316  0.127240628      0
317  2.330046991      1
318  6.592061660      1
319  5.604868700      1
320  2.161514471      1
321  1.519945497      0
322  6.069341778      1
323  7.615055399      1
324  3.258434138      1
325  0.592943949      0
326 10.125728028      1
327  0.134232615      1
328 10.075649724      1
329  5.725160292      1
330  0.333856252      0
331  3.820441954      1
332  6.151071358      1
333  3.032919701      1
334  2.342875794      1
335  5.917295351      1
336  0.674378226      0
337  3.301987477      1
338  3.664852606      1
339  3.649017920      1
340  0.823082176      1
341  5.159793600      1
342  8.018004139      1
343  4.408234319      1
344  1.684378811      0
345  4.669172070      1
346  5.482570121      1
347  0.712668970      1
348  5.349235125      1
349  6.675116584      1
350  3.781550075      1
351  5.078751640      0
352  1.000204677      1
353  4.479880679      1
354  7.406794484      1
355  1.073215282      0
356  0.654139652      1
357  3.488547315      1
358  5.130309382      1
359  5.844084353      1
360  2.333567936      1
361  7.659060181      1
362  7.056350363      1
0

There are 0 answers